Automatically Deploy From GitHub To Server On Push

Solution 1:

You probably want to use GitHub's post-receive hooks.

In summary, GitHub will POST to a supplied URL when someone pushes to the repo. Just write a short PHP script to run on your linode VPS and pull from GitHub when it receives said POST.

Solution 2:

I wrote a small Github-Auto-Deploy server in python, that does exactly what you want.

  • Enter your domain to a new post-receive service hook on Github
  • Match local repository paths with repository urls in the config file
  • The server will receive requests from github and run git pull in local repository path
  • It also runs a shell script for deployment afterwards if you provide one

Solution 3:

I ended up creating my own rudimentary deployment tool (much like Karl but in PHP) which would automatically pull down new updates from the repo - https://github.com/jesalg/SlimJim - Basically it listens to the github post-receive-hook and uses a proxy to trigger an update script.

Solution 4:

Maybe i'm out of context but i prefer to manually choose where to push from my command line eg: git push linode

To do this i create a repository container in my linode server and created a post-receive hook that checkouts my folder to the last pushed commit

Create a git repo container mkdir /var/repo && cd /var/repo git --bare init

Create the post-receive hook in /var/repo/hooks/ touch post-receive nano post-receive chmod +x post-receive

post-receive content #!/bin/sh git --work-tree=/var/www/ --git-dir=/var/repo checkout -f

On your local repository git remote add linode root@<linode ip|domain>:/var/repo git push linode

your code is now deployed