Zero downtime on Heroku

前端 未结 4 1654
一整个雨季
一整个雨季 2021-02-13 22:12

Is it possible to do something like the Github zero downtime deploy on Heroku using Unicorn on the Cedar stack?

I\'m not entirely sure how the restart works on Heroku

4条回答
  •  青春惊慌失措
    2021-02-13 22:49

    It is possible, but requires a fair amount of forward planning. As of Rails 3.1 there's three tasks that need carrying out

    • Upload the new code
    • Run any database migrations
    • Sync the assets

    Uploading code and restarting is fairly straightforward, the main problem lies with the other two, but the way round them is the pretty much the same.

    Essentially you need to:

    • Make the code compatible with the migration you need to run
    • Run the migration, and remove any code written specifically for it

    For instance, if you want to remove a column, you’ll need to deploy a patch telling ActiveRecord to ignore it first. Only then you can deploy the migration, and clean up that patch.

    In short, you need to consider your database and the code compatability an work around them so that the two can overlap in terms of versioning.

    An alternative to this method might be to have two versions of the application running on Heroku at the same time. When you deploy, switch the domain to the other version, do the deploy, and switch it back again. This will help in most instances, but again, database compat is an issue.

    Personally, I would say that if your deployments are significant to require this sort of consideration, taking parts of the application offline are probably the safest answer. By breaking up an application into several smaller applications can help mitigate this and is a mechanism that I use regularly.

提交回复
热议问题