Run migrations on Dokku/Heroku deployment

Jeroen van Baarsen
February 15, 2016

We at Firmhouse are currently moving our projects over to a new version of Intercity, which is using Dokku as its backend. Dokku is a "Docker powered mini-Heroku", this means you can deploy your code by doing a Git push.

One thing that we miss in Dokku is a way to have "After-deploy" hooks to run migrations on deployment. This means that after you deployed, you need to manually run the migrations on your server; this is annoying and error prone!

When inspecting the way Dokku deploys its code, we see that it is using the Heroku buildpacks on the background. Heroku runs the asset precompilation task in the Deploy cycle, and since this is a Rake task, we can hook into this!

By creating the following file, we can run all migrations after the asset compilation task.


At first, this felt like a hack, but after using this method for over a month, I start to really like this!

If you have questions about this, ping me on Twitter (@jvanbaarsen), or send me an email