/ Tech

Simplest static-site workflow known to man

This weekend I managed to tick quite a hefty task off of my to-do list: go through 3 months of drafts on this blog, or around 15 posts. Whilst doing so, I decided that I no longer wanted my politics/current affairs musings to be mixed in with my technical pieces. (This was really for no reason other than to reduce the signal-to-noise ratio, and make things seem a bit more... "tidy".)

So, from here on out, if you want my comedically misinformed hot-takes on current affairs or politics, I present to you my musings!

Obviously though - and with the nature of this post in mind - no blog post would be complete without touching on the tech side of things, would it?

Throwing the blog online in under 15 minutes.

I love writing in Markdown, and there was no real reason to have anything more complex than a static site - therefore I opted to go with the NodeJS based Hexo.

One of the advantages of using a static site generator is that you can host your content anywhere; i.e via an AWS S3 bucket. Alas, I went for the simplest route - and one that only required me to issue one command from my terminal:

$ dokku apps:create musings

That's all that needed to be done to (a) initialise a dokku application on my server, and (b) allow dokku to configure it's nginx proxy to listen for the sub-domain musings.fer...

I've previously written about deploying this site via dokku, as well as how great the dokku-cli tool is for provisioning and managing simple sites; so this was a bit of a no-brainer really.

Dokku has the ability to run a Docker container, so I wrote a very simple Dockerfile that simply installed nginx in a container, and used an nginx.conf which would serve from my repositories public/ folder.

Deployment is then as simple as running:

$ hexo generate
$ git commit -am "New Blog Post: xyz"
$ git push dokku master

With (a) the site itself set up, (b) the server configured, and (c) a rocking deployment method, the next step was to configure somewhere to store drafts and keep a back-up.

After creating a new repository on Github, I configured my local repository to treat both dokku and github as the same "remote" (origin), with dokku being specified as push only. This is relatively trivial to do by editing the .git/config file:

[remote "origin"]
    url = git@github.com:FergusInLondon/musings.fergus.london.git
    pushurl = dokku@fergus.london:musings
    fetch = +refs/heads/*:refs/remotes/origin/*

This means that doing a git pull will only ever pull from Github, whilst doing a git push will always push to both Github and Dokku. This prevents the two remote servers from diverging and getting in to a state where they can't be synchronised easily.

So within 15 minutes you can configure your server for a simple site, deploy it, and do so with the security of a consistent back-up policy too... and the only time I had to leave my terminal session was to create the repository on Github. Pretty easy, huh?

Although serving a static site is arguably one of the simplest things you can do, managing to simplify it even more (i.e git deployment, no need to leave the terminal - even during initialisation/configuration) is bizarrely satisfying.


Contract Software Developer and DevOps Consultant, based out of London in England. Interests include information security, current affairs, and photography.