container

Hugo Container

I am using Hugo to build this website and it made sense for me to automate this.

The first step on that journey is to create a container to use for the static site files generation.

I’ll be using OpenSuse as a base as I’m comfortable with it.

Container file

I came up with the following Containerfile

FROM opensuse/tumbleweed:latest

RUN zypper -n in hugo && \
    zypper -n clean

COPY --chmod=555 container-entrypoint.sh /usr/local/bin/

WORKDIR /src

EXPOSE 1313

ENTRYPOINT [ "container-entrypoint.sh" ]

CMD [ "hugo" ]

The container-entrypoint.sh file checks for source files and will abort if none are found.

Build image

podman build -t teknikuglen/hugo-builder:latest -f Containerfile .

Run container

The container also serves draft files when the -D switch is used.

podman run --rm -v $(pwd)/src:/src -p 127.0.0.1:1313:1313 teknikuglen/hugo-builder hugo server -D

Generate output files

The following is the command to run to generate the final files you can use on your web server.

podman run --rm -v $(pwd)/src:/src teknikuglen/hugo-builder hugo -d /src/site_build

Conclusion

So that’s one container ready. If you are interested in the source files they can be found in my git repo at podman-hugo🔗