Here comes the post-receive git hook I used along with Octopress, to finish deploying the static blog server-side.
What do we want to achieve ?
Well, each time a new version of the static site, built by Octopress,
is pushed to the git repository, we’d like git to copy it to the
document root served by Apache (
/srv/www/blog-test in this example).
In order to do that, we need to write a git hook, and to fiddle a little bit with permissions.
We’re talking about a post-receive git hook. Here it is:
There’s a few things to notice in this script:
-ein the first line, to exit if an error happens
WWWDIRthat you may change to suit your config
rm -frhere and there, so you’d better read and understand before running that wildly
echocommands are there for a good reason. Indeed, stdout is forwarded by git, and ends up in the console of the user that did the
git push. Or more precisely,
octopress deployin our case.
Settling write permissions
After that, we just have a few ownership details to solve.
As you can see in the script above, git will write inside the directory
We must manually create this directory, and allow git to write there.
A solution is to add git to the group
www-data (which is the user Apache is running),
so that they can both access it.
First, let’s create the document root directory:
$ cd /srv/www $ mkdir blog-test $ chgrp www-data blog-test $ chmod g+w blog-test $ ls -l total 4 drwxrwxr-x 2 root www-data 4096 Sep 29 19:08 blog-test
And now, just add git to the right group:
$ addgroup git www-data