Skip to content

Instantly share code, notes, and snippets.

@jkunkee
Created December 18, 2013 05:50
Show Gist options
  • Save jkunkee/8017839 to your computer and use it in GitHub Desktop.
Save jkunkee/8017839 to your computer and use it in GitHub Desktop.
Simple Git hook for deploying on every commit. Readily refined and fairly easy to modify. I used the firewall to restrict who could trigger it, though I'm sure that's easily spoofed. Downsides: * security by obscurity, not proper authentication * always pulls, even when deployed branch isn't changed * doesn't call deploy script, like "npm instal…
description "Gutenberg's Box githook listener"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
umask 022
console none
exec 2>/dev/shm/githook.log
exec >/dev/shm/githook.log
exec /usr/bin/nodejs /home/ubuntu/githook/index.js
function(){
"use strict";
var http = require('http')
, server
, exec = require('child_process').exec
;
http.createServer(function (req, res) {
if (req.url === '/githook/asdfasdfasdfasdfasdf') {
exec('cd /home/ubuntu/gutenbergs-box/ && git pull ; chown -R ubuntu:ubuntu /home/ubuntu/gutenbergs-box', function(error, stdout, stderr) {
res.writeHead(200);
res.end(stdout + stderr);
});
} else {
res.writeHead(404);
res.end("not found\n");
}
}).listen(9999);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment