I am wanting to move all of my sites to GitHub for all of the obvious benefits. I am not a big fan of the command line, so I like GitHub because it allows me to avoid touching all of that. Setting up a repository on GitHub and then syncing it with my computer is easy enough. I need to be able to push from GitHub to the webserver automatically though so when I update something locally to the main branch, sync it with GitHub, it goes live on the site. From Googling the subject it seems like most of the techniques either require the command line or seem fairly complex. I want to do this with about 15-20 sites (many of which are hosted on different servers from different clients). I want to find an option that is within my skill set and doesn't take 2-3 hours per site. Anyone know of the best, easiest way to set this up?
You can run your deployment workflow on GitHub-hosted runners or on self-hosted runners.
The part which is complex is the webhook on GitHub
Every GitHub repository has the option to communicate with a web server whenever the repository is pushed to.
That means your web site must have a process listening to those JSON messages sent by GitHub upon reception of a commit.
You can see multiple examples of those listeners, like this webhook-deployer, with an auto.php (for a php server):
<?php // Prevent accidental XSS header("Content-type: text/plain"); // Run the script if ( $_POST['payload'] ) { shell_exec("./pull.sh"); }
That GitHub project recommends an SSH key with no passphrase, which I agree at first (to test it out).
However, especially for private projects, it is best to run an ssh-agent and manage an ssh key passphrase protected.
As janos comments:
- If the GitHub repository is public, then he doesn't even need one.
- If the repo is private, then he needs it, but this should not be taken so lightly. If possible he should use a key agent.
If that's too complicated then he could use a dedicated SSH key without passphrase just for this deployment, and that key should never leave the deployment PC.
I know this ticket is old, but for those who find this somehow, checkout dploy.io. It's a hosted service made specifically for the purpose of deploying your repo from GitHub/Bitbucket to your server. It supports SFTP/FTP/S3/Heroku/SSH commands and more.
Disclaimer: I work on dploy.io
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With