热门部署在Heroku,没有停机时间 [英] Hot deploy on Heroku with no downtime

查看:153
本文介绍了热门部署在Heroku,没有停机时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这显然可以引起一些问题,因为推送到Heroku的一个不好的一面是我必须在运行数据库迁移之前推送代码(并且服务器自动重新启动)用户浏览网站上有500个错误的新代码没有新的表/属性:Heroku提出的解决方案是使用维护模式,但我想要一个没有缺点的方式,让我的webapp每次都运行!



有没有办法?例如对于Capistrano:




  • 我准备在新的目录中部署的代码

  • 我运行(向后)迁移,旧代码继续正常工作

  • 我将mongrel实例切换到新目录并重新启动服务器



...我没有停机时间!

解决方案

您可以设置第二个Heroku应用程序指向与您的主要生产应用程序相同的数据库,并使用辅助应用程序运行数据库迁移,而不会中断生产(假设迁移不会破坏应用程序的先前版本)。



我们来打电话给Heroku应用程序 PRODUCTION STAGING



您的部署顺序将成为:


  1. 将新代码部署到 STAGING 可以
    git push

  2. STAGING 上运行数据库迁移(以更新PROD db)

    heroku run -a staging-app rake db:migrate

  3. 将新的代码部署到 PRODUCTION

    git push heroku production

分段应用程序不会花费任何费用,因为您不需要超过Heroku的免费级别,而且自动设置耙机部署脚本可以很方便地执行此操作。



祝你好运!


A bad side of pushing to Heroku is that I must push the code (and the server restarts automatically) before running my db migrations.

This can obviously cause some 500 errors on users navigating the website having the new code without the new tables/attributes: the solution proposed by Heroku is to use the maintenance mode, but I want a way with no downside letting my webapp running everytime!

Is there a way? For example with Capistrano:

  • I prepare the code to deploy in a new dir
  • I run (backward) migrations and the old code continue to work perfectly
  • I swith mongrel instance to the new dir and restart the server

...and I have no downtime!

解决方案

You could setup a second Heroku app which points to the same DB as your primary production app and use the secondary app to run your DB migrations without interrupting production (assuming the migrations don't break the previous version of your app).

Let's call the Heroku apps PRODUCTION and STAGING.

Your deploy sequence would become something like:

  1. Deploy new code to STAGING
    git push heroku staging
  2. Run database migrations on STAGING (to update PROD db)
    heroku run -a staging-app rake db:migrate
  3. Deploy new code to PRODUCTION
    git push heroku production

The staging app won't cost you anything since you won't need to exceed Heroku's free tier and it would be pretty trivial to setup a rake deploy script to do this for you automatically.

Good luck!

这篇关于热门部署在Heroku,没有停机时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆