Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hot deploy on Heroku with no downtime

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!

like image 447
zetarun Avatar asked Apr 01 '10 13:04

zetarun


People also ask

Does Heroku have downtime?

Heroku Preboot – A zero downtime deployment In a very simplistic way, on new deploys or changes of ENV vars, Heroku will boot your app onto new “hidden” dynos, and wait a few minutes before routing traffic to it.

Is Heroku free for lifetime?

Free Services on HerokuHeroku offers a free plan to help you learn and get started on the platform. Heroku Buttons and Buildpacks are free, and many Heroku Add-ons also offer a free plan.

How many project I can deploy in Heroku as free?

A 'Free' tier Heroku account allows up to 5 apps.

Can I deploy front end on Heroku?

Each process has its own port in dev, but deploying on Heroku uses just one total. Put the working frontend in a subdirectory of root (such as /frontend ). Put the working backend in a subdirectory of root (such as /api -- the blogpost assumes the backend remains in the root directory -- either way is fine).


2 Answers

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!

like image 141
jshkol Avatar answered Oct 17 '22 06:10

jshkol


If you're able to live with two versions of the same app live at the same time, Heroku now has a preboot feature.

https://devcenter.heroku.com/articles/preboot

like image 39
dB. Avatar answered Oct 17 '22 08:10

dB.