Reputation: 45410
We have a VPS on Linode, and code hosted on GitHub. How do we setup so when we push to GitHub, it also pushes automatically to our Linode server. We are using PHP on the Linode server.
Upvotes: 42
Views: 42372
Reputation: 1330102
Using any kind of webhook involves deploying a listener for that hook, and then triggering, from your listener server host, the action.
You can take a shortcut now (oct. 2018) with GitHub Actions (Oct. 2018).
GitHub Actions allows you to connect and share containers to run your software development workflow. Easily build, package, release, update, and deploy your project in any language—on GitHub or any external system—without having to run code yourself.
See Actions: pushing is only one of the possibilities behind Actions!
Workflows can be triggered by GitHub platform events (i.e. push, issue, release) and can run a sequence of serial or parallel actions in response. Combine and configure actions for the services you know and love built and maintained by the community.
Upvotes: 4
Reputation: 10711
You may refer to this tutorial:
Automatically Updating Your Website Using GitHub's Service Hooks:
In short it explains the following steps:
Create a php file in .git
folder on your server with the following contents.
<?php `git pull`;?>
Setup your server for the SSH keys to exist. Something like:
key. cat ~/.ssh/id_rsa.pub
Setup the service hook on GitHub . Enter WebHook URL:
http://your.domain.com/path/to/yourfile.php
When all is set. The file is going deploy all the work on your server each time you push to GitHub.
Upvotes: 1
Reputation: 465
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
Upvotes: 3
Reputation: 7958
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.
Upvotes: 3
Reputation: 171
I wrote a small Github-Auto-Deploy server in python, that does exactly what you want.
Upvotes: 17
Reputation: 38540
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.
Upvotes: 30