Who Needs CI?
Reared in the age of GitHub, I am ashamed to admit that it took me too long to realize that you do not need a "forge" like GitHub or GitLab in order to be able to git push
to a repository and in fact you don't need to do any extra configuration at all, if you already have an SSH server running.
Ever since realizing this I've just started putting repos in my home directory on my home server. Now, when I start a new project I simply
cd ~/repos mkdir new-project git init . --bare
and then on the client machine I'm ready to add my new repo and start using it:
git remote add origin [email protected]:~/repos/new-project git push -u origin master
This works with absolutely no extra configuration, since I already have SSH installed and set up for other things.
A bonus of this, is that when I start a project like this one, git hooks make it absolutely trivial to automate deployment.
This blog lives in a directory called ~/repos/silly.business
. Inside, there is a directory that git
creates called hooks
, and there, I have renamed post-update.sample
to post-update
which tells git
to actually run the hook. Then I updated the contents of the file with an extremely tiny script:
#!/bin/bash
set -exo pipefail
cd "$(mktemp -d)"
git clone /home/ian/repos/silly.business
cd silly.business
hugo
rsync --delete -avh public/ my-user@webhost:/final/path/
Now, whenever I git push
to my server, it will go ahead and rebuild the site and update it. I may need to optimize or modify this script at some point, but in this state it works and has no extra dependencies.
Sure, I could have set up Gitlab and created a repository through their web UI and then set up their CI thingy and read some documentation and yada yada
….or I could write six lines of Bash for my little website.