My work log for deploying Hugo on my instantiation, using https://euantorano.co.uk/hugo-git-deployment-nearly-free-speech/ (this mostly worked for me but required some minor changes).
Installing (a correct version of) Hugo on NearlyFreeSpeech
#!/usr/bin/env sh
set -ex
VERSION=0.145
FILENAME="hugo_${VERSION}_FreeBSD-64bit.tar.gz"
BIN_DIR=$HOME/bin
mkdir -p "${BIN_DIR}"
fetch -q -o hugo.tar.gz "https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${FILENAME}"
tar -C "${BIN_DIR}" -xvzf hugo.tar.gz hugo
rm hugo.tar.gz
If you want to change the version above, make sure it exists in the correct combo of version x operating system at https://github.com/gohugoio/hugo/releases/download/*. You may then need to modify FILENAME.
You only need to rerun this (either via ./updatehugo.sh or bash updatehugo.sh) when you want to change the version. Make sure the server version of hugo matches your local development version.
Git setup on server
Bare repo
A bare repo has no working tree and you can push your local version to this.
cd $HOME
mkdir errorbesque.com.git
cd errorbesque.com.git
git init --bare
git branch -m main
Note I had to change master to main since my local repo uses main as the branch.
Checkout directory
cd $HOME
mkdir errorbesque.com.checkout
cd errorbesque.com.checkout
git clone $HOME/errorbesque.com.git .
Note the .
post-receive hook
I didn’t know about post-receive hooks before this project.
cd $HOME/errorbesque.com.git
touch hooks/post-receive
chmod ug+x hooks/post-receive
Then after opening this file (perhaps via vi hooks/post-receive):
#!/bin/bash
set -ex
SITE_CHECKOUT=$HOME/errorbesque.com.checkout
GIT_DIR=$SITE_CHECKOUT/.git
PUBLIC_WWW=/home/public
cd $SITE_CHECKOUT
git --git-dir=$GIT_DIR pull -f
$HOME/bin/hugo --cleanDestinationDir --minify -d $PUBLIC_WWW
exit
Other
A few things that messed me up, being quite new to hugo:
- I made the error of editing my
hugo.yamlfile withtomlsyntax since many of the tutorials used this, and this caused the deployment to fail while not throwing any errors. - Two versions of
hugoon the server (a preinstalled one + a the one I defined) - Default
masterin bare repo needed to be changed tomain - Submodules need to be forcibly updated in git on the server, so
themesweren’t installed on the server without this. Oddly, the only thing in the build log is aWARN: found no layout file for "html" for kind "home": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
