Since I’ve started a blog using the excellent hugo static content generator, I have noticed that a large proportion of such blogs are devoted to documenting the workflow used to create them. So here is my shot at documenting what I’m doing.
Gitlab
I’ve been a Github user for some time, both the public service and the enterprise edition at work. Recently I had a need to have some private repositories, and since I had no budget for these hobby projects, I decided to check out Gitlab. Gitlab offers free private repositories, integrated CI (continuous integration) and all sorts of other goodies, so it seemed like a good choice for controlling the generation of this blog.
I created a group for the blog and within that three project repositories:
- src
- themes
- public
I cloned the empty src repository to my machine, generated a new hugo site within it, removed the themes directory. Then added git submodules referencing the themes and public repositories. Next, I cloned the theme that I’m using (Hugo Octopress) into the themes directory. It may well be overkill having the themes directory as a separate submodule - but what the hell, I am experimenting.
CI
In Gitlab the CI pipeline is controlled by a YAML file added to the repository. I had a fair bit of trial and error getting something up and working with this, but eventually settled on a two stage process which uses hugo to build the site and then git pushes the generated ‘public’ directory back to the public repository.
Unfortunately, whilst Gitlab CI can handle pulling in submodules based on a token for the CI process, it can’t handle write access to repositories currently - hence the use of the SSH private key variable - this is set to the private key corresponding to a public key added as a deploy key with write access to the repository. I edited the .gitmodules file to make sure that I was using references relative to the Gitlab group, as well as referencing the theme.
Deployment
I’ve simply added a deploy key to the public repo and run a cron job on my web hosting account (at Dreamhost[1]) to pull from the public branch.
Summary
So now I can edit away on post content and when I push up to Gitlab, docker containers will be created which build the site, push into another repository and then eventually this will be automatically pulled onto my webhost. Nice.
Note 1
This is an affiliate link - if you sign up to shared hosting at Dreamhost](https://www.dreamhost.com/r.cgi?309785/promo/dreamsavings50) you’ll get a $50 saving and I’ll get $47 credited to me.