heroku-like workflow on personal server

sethvargo picture sethvargo · Jan 25, 2011 · Viewed 7.6k times · Source

I'm trying to set up a server with pure-git workflow similar to heroku. I don't need help setting up git, but for informative purposes, I'm using gitolite. I'd like to (somehow) write custom hooks in the operating system (Ubuntu) of this system so that, when it receives a push on a particular branch, it performs all the operators heroku does (starting Rack, Mongrel, Apache (for static serving pages in my case), etc.

Can someone point me towards a resource to do this or at least get started? A google search didn't really seem to help...

Answer

semperos picture semperos · Jan 29, 2011

It sounds like you want to execute arbitrary functionality at a certain point in your Git workflow. Git hooks are the way to go.

If you look in any Git repo (inside the .git folder), you'll see a hooks folder. Inside it there are a number of example hook files with different names. Based on your explanation above, you want to edit the post-receive hook file, since that will be called immediately after a new ref has been updated in your remote repo (resulting from a push from a local one). For more info, read the official documentation on hooks or read this perhaps more approachable explanation.

You can put any shell commands you want in a hook file. Change the filename from post-receive.sample to simply post-receive, add the commands you need to start Rack, Mongrel, Apache, etc., then make the file executable with a quick chmod +x post-receive and you're all set.