Heroku like deployment for your cloud host / VPS


For Be My Eyes I have set up a heroku like deployment environment

Basically I followed this approach:
https://www.digitalocean.com/community/articles/how-to-set-up-automatic-deployment-with-git-with-a-vps

But there is one problem with the above approach, and that is that I want to be able to push other branches than master to the server. Thats how I push to QA and staging.
A gooogle search found this for me:
https://coderwall.com/p/oj5smw

Now all I needed was to add a restart

In the post-receive hook, for each repo, I have added the following code

#!/bin/bash

while read oldrev newrev ref
do
    branch=`echo $ref | cut -d/ -f3`
    GIT_WORK_TREE=/var/www/pathToAPI git checkout -f $branch
done

touch /var/www/pathToAPI/tmp/restart.txt

With this deployment is as easy as

git push api master

And of course, since I have a git repo behind me, I can rollback pretty easily as well.

Btw if you are instested in helping testing bemyeyes, and you have an iPhone, please do install the beta at http://beta.bemyeyes.org