Last Updated: February 25, 2016
·
772
· dparnell

Automatic site update on push to github

I've been meaning to give this a try for a while and finally had a reason to do it. On every github repository there is a list of service hooks. The first one is called WebHook URLs. This can be used to post a message to your web server whenever content is pushed to your github repository. Probably the simplest (although not particularly secure) way to use this is something like the following in a file hosted on your web server:

<?php system("git pull"); ?>

So far I am quite happy with the results :)

4 Responses
Add your response

+1, but... How is that not secure?

over 1 year ago ·

If somebody can guess the url for the PHP script they can trigger a git pull. It probably shouldn't hurt anything, but would create unnecessary load on your server.

over 1 year ago ·

Srsly?

over 1 year ago ·

You can add a key, and verify if the key is being passed correctly. It is another "security layer" that you can add, and is not hard to manipulate it through PHP.

Another possibility is to verify the "sender".

Also, keep on mind that git pull will only update your codebase, if you have changes in database, new gems, or need to clean cache it will not happen with this command. I'd create a .sh to update the whole database, and run it.

Now, forget everything I said above, and use a continuous deploy system like CodeShip (I don't work there) plus a good deploy recipe, and it will make your life a dream. I'm using it since sometime ago and it is great.

Cheers!

over 1 year ago ·