Auto Update Your Lithium Apps From GitHub

Just a simple route!

Posted 2 years ago by Tom Maiaroto.


So I wanted to quickly share this tip. It's too long for a Twitter status update, but it's short. I'm sure most of you are well aware of GitHub's service hooks, yes? Well, the most basic one is the WebHook. This basically makes an HTTP request to the URL(s) you provide. In Lithium, you can create a simple route to run a git pull and update command. You'll want to obfuscate the route so no one can, easily, access it. I don't deem it a security threat (I also typically only do this for dev sites just to avoid oopsies when pushing to the master branch) so I think obfuscation is fine. You can also optionally choose to redirect somewhere, etc. So your route will look something like:


Router::connect('/deploy-someRandomValue', array(), function($request) {
	system('(cd ' . LITHIUM_APP_PATH. ' && git pull)');
	system('(cd ' . LITHIUM_APP_PATH. ' && git submodule update --init --recursive)');
        return;
});

Note that you need to wrap your command in parenthesis so that git is called from the proper directory. Also note that LITHIUM_APP_PATH will be changing in the future so may want to use the Libraries class to get the path. Of course, you will also want to ensure the user running PHP has an SSH deploy key so that it can actually run the Git command. For Ubuntu this user is typically "www-data" and you can simply run ssh-keygen -t rsa while under the www-data user like any other user (though leave the passphrase blank). The home directory for www-data is "/var/www" just so you know where to find those keys. For other operating systems and Linux distributions this will vary.

Then on Github, enter in the servcie hook like so:


Filed under
comments powered by Disqus

Search for Posts

Popular Labels

social media virality score general internet web development reviews and opinions php web tools hosting lithium web design

Recent Posts