Automatic deployment from GitHub

I configured the server in such a way that after each commit to the master branch, the site is automatically generated.

On the GitHub side, I used a regular “WebHook”, and on the server side, I used Gith.

Gith is a handy web server for Node.JS that can accept and filter data from GitHub webhooks. My server that runs the build of the site looks like this:

var childProc = require (‘child_process’);

var path = require (‘path’);

gith ({

// Listen to hooks only for the “master” branch

branch: ‘master’

}). on (‘all’, function (payload) {

console.log (‘Run deply script on’, new Date ());

// Run the site build script

var deploy = childProc.spawn (‘sh’, [‘/web/’]);

deploy.stdout.on (‘data’, function (data) {

var message = data.toString (‘utf8’);

if (~ message.indexOf (‘subscribe’)) {

// Docpad may ask about subscribing to the newsletter, we will refuse

deploy.stdin.write (‘n’);

} else if (~ message.toLowerCase (). indexOf (‘privacy’)) {

// Docpad may ask about security policy, let’s agree

deploy.stdin.write (‘y’);



deploy.stderr.on (‘data’, function (data) {

console.log (‘Error:’, data.toString (‘utf8’));


deploy.on (‘exit’, function (code) {

console.log (‘Deploy complete with exit code’ + code);



The project build script itself looks like this:

#! /usr/bin/env bash
git pull
git submodule foreach 'git checkout master && git pull origin master'
npm install
docpad generate
find ./out -type f ( -name '*.html' -o -name '*.css' -o -name '*.js' )  -exec sh -c "gzip -7 -f < {} > {}.gz" ;