From Nikola to Hugo

Today I have migrated the static generator for this site from Nikola to Hugo. Part of the motivation has been trying a new technology, part of it, having less movable parts. Nikola is great but carries quite a lot of dependencies (specially with the themes). My previous workaround involved building a Docker image with the tools, and using that image inside a GitlabCI pipeline that built the statics and deployed them to my server.

My articles were written in Markdown, so I didn’t have to change the contents. I made a quick-and-dirty Python script to reformat the headers of each article (specially title and date). Appart from that, I chose a theme and wrote a small config.toml.

Hugo is a Golang-compiled single binary, so it is operationally much simpler to deploy, on my laptop and on the CI pipeline. For this new version of the blog, I have moved the repo to Github and the CI to Travis. This is my new .travis.yml:

language: go
  - 1.8
  - openssl aes-256-cbc -K $encrypted_84f17b3aef8a_key -iv $encrypted_84f17b3aef8a_iv -in deploy/server.pem.enc -out deploy/server.pem -d
      - rsync
      - openssh-client
  - eval $(ssh-agent -s)
  - chmod 600 deploy/server.pem && ssh-add deploy/server.pem
  - mkdir -p ~/.ssh
  - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
  - GOPATH=$HOME/go go get
  - "$HOME/go/bin/hugo"
  - rsync -avz --delete public/ $BLOG_DEPLOYMENT_URL

The only tricky part is allowing ssh access to my server. After reading the documentation, I have opted for commiting an encrypted version of a .pem file that I have generated for this purpose. The encryption is performed once using the travis command line interface:

travis login
travis encrypt-file deploy/server.pem --add

This command executes an AES-256 simmetric encryption and add the line to your .travis.yml to perform the decoding at the beginning of the execution.

The only issue that I currently face is the fact that the old URLs of the posts do not work, because Hugo expects the posts inside a post folder. I definitely need to read the documentation :-)