Seamless deployment in Rails

浪尽此生 提交于 2019-12-06 04:34:15

问题


I would like to seamlessly upgrade my Rails app:

Meaning:

  1. If no migrations need to run I would like to transparently upgrade the code and have no requests go 404 during the deployment.
  2. This is hard I would like to have some process that can upgrade the database seamlessly and during that time just hold back on the web requests (queue them in the pipe) when the db update is done, allow stuff through. (I only need this to work for short migrations - like 5-10 second migrations).

How would you go about achieving this?


回答1:


Upgrading just code

If you're just upgrading the application code passenger should allow you to do that without skipping a beat. However it's not going to protect you if an upgrade goes wrong, for that you should consider having two or more load balanced web servers which you can upgrade individually round robin.

Upgrading the database

As a user I'd rather see a "down for maintenance" page than my browser spinning for 10 seconds. If you explain that the downtime will be an order of a few seconds and set the page to auto-refresh.

If you're adamant about having no downtime while doing db upgrades you have a few options:

  1. You can refactor your database in such a way that you keep the old schema valid. This means you can keep two version of your app running against the same database and over time migrate to the new schema. There's a lot of 'database refactoring' articles, with most of them advocating using triggers/etc... to achieve the desired result. I personally think it's a lot of effort for not a lot of reward.

  2. Depending on your application you might be heavily biased towards reads over writes, which means you can show a 'maintenance' page for uncached data while you upgrade the database (this is how facebook does their database upgrades). This is even more effective if lots of your data is stored in memcached or redis. Alternatively you can switch to a readonly database slave and disable any write actions.

I hope this helps!




回答2:


You should have a look at Capistrano.



来源:https://stackoverflow.com/questions/2107615/seamless-deployment-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!