Sunday, June 17, 2012

Heroku-Style Deployment On EC2

Everybody loves the way you can just git push origin master in a Heroku project and see your changes live on the web right away. If you're on EC2, Slicehost, or any other non-Heroku environment, it's exceptionally easy to hack that functionality into your own project.

This is literally all the necessary code:

You set this running, make sure port 54321 (or whatever) is open, and configure your GitHub post-receive web hook. GitHub will POST a big JSON update to the hook every time you push to any GitHub branch, but all your Sinatra app needs to do is check that JSON for "/refs/heads/master", as in the gist, to differentiate master from any other branch.

This assumes a very simple app with no need to restart any app servers or what have you, but any additional config or setup you might need to do can quite happily live in the backticks as a shell script.