Deploying a cobalt site from a git hook
Since I've not have written a blog article in ages, and also not
upgrades the static site generator I use,
cobalt, I thought I'd hit kill birds
with a one-and-a-half stones by documenting my rather minimalist setup
and deploying a new version of cobalt
. The following parts are
involved:
- A bare git repository on my VPS that I can push to via SSH.
- A git
post-update
git hook in the repository, which is responsible for rendering the repository contents viacobalt
.
The post-update
hook just calls out to a script that does the actual
work, providing it with the "stage directory" and the symlink that is
set to the rendered output. The idea here switch the symlink between a
"left" and "right" directory, and only switch when the rendering
succeeded. This means a push to the git repository will only go live
when rendering was successful, adding a bit of a safety net.
Here is the hook itself, where the "left" and "right" directory will
be created under /srv/www/example.org/deploy/stage
and the symlink
pointing to one of those written to
/srv/www/example.org/deploy/htdocs
. You'll want to point your
webserver to that symlink.
#!/bin/sh
PATH="$HOME/bin:/usr/local/bin:/usr/bin:/bin"
export PATH
exec cobalt-git-deploy /srv/www/example.org/deploy/stage /srv/www/example.org/deploy/htdocs
The cobalt-git-deploy
script
(download) is specific to cobalt,
but should be adaptable, with minimal changes, to any other static
site generator.