Profile

Cover photo
4 followers|1,091 views
AboutPostsPhotosVideos

Stream

Toke

Shared publicly  - 
 
Or how this site is updated

This site is build via jekyll and the sources are coming from a git repository on github. I do not write something special about git or jekyll here. Just how the “deployment” works.

Github webhook

Github has a nice feature called “Service hooks” - especially a “Post-Receive URLs” hook. I use this hook to notify my server to do a “git pull” on a local repository, then rebuild the site with jekyll and rsync changed data to the document root.

The webhook endpoint (Dancer.pm code):

package ReceiveHook;
use Dancer ':syntax';

our $VERSION = '0.3';

# Configuration for different projects
my $config = {
"PROJECTNAME" => {
run => "/home/user/bin/updateblog.sh",
},
};

prefix '/notify';

get '/*' => sub {
header 'Allow' => 'POST';
status '405';
"Not for you\n";
};

post '/:project' => sub {
if (not defined $config->{params->{project}}) {
status 'not_found';
return "No such project: ".params->{project}."\n";
}

my $payload = params->{'payload'};
if (not defined $payload) {
status '415';
return "I need a payload\n";
}

# Read the configuration for that repo
my $repo_config = $config->{$repo->{name}};
if (defined $repo_config && defined $repo_config->{run}) {
eval {
system $repo_config->{run};
};
}

return "OK";
};

true;

The update itself is done by this little shellscript:

#!/bin/sh

REPPATH="/home/user/git/localgitrepository"
DEPLOYTARGET="/var/www/sites/mydomain"
LIVEURL="http://mydeploydomain.tld"

if [ -d ${REPPATH} ] ; then
cd "${REPPATH}"
git pull
jekyll --url "${LIVEURL}"
rsync -rXogpEAt _site/ "${DEPLOYTARGET}"
fi

More

That is just the surface what really is possible. I also use this method in different other setups. Just to mention differnet usecases:

Keep repositories synchronized
Automatic Builds
Automatic deployments
Test framework
Configuration management
Even a small distributed site or WiKi is possible
With a simple git post-commit-hook such a http Post with curl it is github independent.

To be continued…
1
Add a comment...
Have them in circles
4 people

Toke

Shared publicly  - 
 
#perl #programming
Perl tip of the week: use perlcritic (http://search.cpan.org/dist/Perl-Critic/), most of the time you will get useful tips how to follow best-practices.
You can even try it out online at http://perlcritic.com/
1
Add a comment...
People
Have them in circles
4 people
Links
Website
Story
Tagline
… read code … see patterns … evolve