This was originally a blog post, but cross posting here in case useful for others.
Am wrapping up a project for a client that needed a static site. They requested that it be built with Hugo and deployed to GitLab pages. The theme they wanted to base it off uses Hugo Modules, which in turn requires a Golang installation.
I know there are existing docker images that have Hugo and Golang installed, but this particular project’s build is a bit complex (I’ve dumbed down the build script for this post), so I needed more flexibility.
I set things up so that when a commit is pushed to the master
branch, a CI job is triggered. This job does the following:
- Pulls a CentOS docker image
- Installs
curl
,git
,go
,hugo
- Builds the site
- Deploys the site to GitLab Pages
Set GO_VERSION
and HUGO_VERSION
to your desired versions in .gitlab-ci.yml
, then it’s ready to go.
Sample files are below.
.gitlab-ci.yml
image: centos:8
variables:
GIT_SUBMODULE_STRATEGY: recursive
GO_VERSION: "1.15.6"
HUGO_VERSION: "0.78.2"
before_script:
- yum install -y curl git
- chmod +x task_ci_config.sh
- chmod +x task_ci_install_go.sh
- chmod +x task_ci_install_hugo.sh
- chmod +x task_ci_build.sh
- ./task_ci_install_go.sh $GO_VERSION
- ./task_ci_install_hugo.sh $HUGO_VERSION
pages:
stage: deploy
script:
- ./task_ci_build.sh
artifacts:
paths:
- public
only:
- master
task_ci_config.sh
#!/usr/bin/env bash
export PATH=${PATH}:/usr/local/go/bin
export PATH=${PATH}:/usr/local
task_ci_install_go.sh
#!/usr/bin/env bash
USAGE="Usage:\n\n${0} VERSION\n"
if [[ -z ${1} ]]; then
echo -e "${USAGE}"; exit 1
fi
source task_ci_config.sh
VERSION=${1}
TAR=go${VERSION}.linux-amd64.tar.gz
URL=https://golang.org/dl/${TAR}
curl -L -O ${URL}
tar -C /usr/local -xzf ${TAR}
go version
task_ci_install_hugo.sh
#!/usr/bin/env bash
USAGE="Usage:\n\n${0} VERSION\n"
if [[ -z ${1} ]]; then
echo -e "${USAGE}"; exit 1
fi
source task_ci_config.sh
VERSION=${1}
TAR=hugo_extended_${VERSION}_Linux-64bit.tar.gz
URL=https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${TAR}
curl -L -O ${URL}
tar -C /usr/local -xzf ${TAR}
hugo version
task_ci_build.sh
#!/usr/bin/env bash
source task_ci_config.sh
hugo