Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing from GitHub to a Web Server

Tags:

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?

like image 395
Andrew Avatar asked Jun 28 '13 14:06

Andrew


People also ask

Can you deploy from GitHub?

You can run your deployment workflow on GitHub-hosted runners or on self-hosted runners.


2 Answers

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.
like image 137
VonC Avatar answered Nov 07 '22 20:11

VonC


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

like image 43
Dima Sabanin Avatar answered Nov 07 '22 19:11

Dima Sabanin