configure hugo with CD ( continuous deployment ) on AWS Amplify
By JIMz
background
by default, to update the hugo generated site, it expects :
- local new build ;
- push that whole newly built
/build
dir to repo ; - AWS amplify git clone for deployment ;
this also implies to make small changes / updates in github via the web interface will not have the new changes reflected online.
the updated amplify config file
the build setting is therefore updated as :
- add
.gitignore
or update the existing file to avoid/build
; - include
amplify.yml
in the repo ( or via the web dashboard inside AWS amplify ) ; - update the content of
amplify.yml
as the followings :
---
version: 1
env:
variables:
# always AVOID the prefix "v" !!
# update this accordingly to the latest / desired version
HUGO_VER: 0.139.3
# define the file to download and the path to it
HUGO_TAR: hugo_extended_"${HUGO_VER}"_Linux-64bit.tar.gz
DOWNLOAD_PREFIX: https://github.com/gohugoio/hugo/releases/download
# beware of the "v" in front of the version here
DOWNLOAD_PATH: "${DOWNLOAD_PREFIX}/v${HUGO_VER}"
frontend:
phases:
preBuild:
commands:
- sudo mkdir -p /public
- sudo dnf update -y
- wget "${DOWNLOAD_PATH}"/"$HUGO_TAR"
- tar -zxvf "${HUGO_TAR}"
- sudo mv hugo /usr/local/bin/
- /usr/local/bin/hugo version # verify the hugo version to be used
build:
commands:
# make sure the version downloaded above is used with absolute path
- /usr/local/bin/hugo -F --minify
artifacts:
baseDirectory: /public
files:
- '**/*'
cache:
paths: []
some notes on the above yaml file
- as of 2024-12-02, the theme
ananke
was used, which requires the latest version of hugo, or at least not working with the version of hugo came with the default build image in AWS Amplify (AWS Linux 2023
) ; - the version of hugo came with the default build image is
v0.12x.x
( something like that ) ; - an absolute path to the freshly downloaded hugo executable must be specified in the build command to make sure it won’t use the default version ;
- the command / keyword
build
has to be removed in the build command above ~