Hugo is a popular open-source static site generator. A static site generator creates flat HTML files rather than relying on dynamic content like Javascript. Static sites typically have a smaller storage requirement and are more performant than dynamic websites, though they also have a much reduced feature set. However most people would say a site that supports full dynamic content that is used just for article content (like this site) would be a waste.
There are a fair few Hugo Docker images out there, but I decided to make my own to practice Dockerfile creation and to fully understand the image that I end up running. Please see my article regarding building a Docker image for the first time as a prerequisite to this build.
TAR file build-out
In addition to the Dockerfile for the .tar file I’ll be creating I also need to include several other files:
entrypoint.sh file contents detailed herein; script for container start
nginx.conf file contents detailed herein; main configuration options for Nginx webserver
net.redbarrel.knowhow.conf specific Nginx config for the site
SSH server is also installed so that the site contents can be managed by the administrator. Tips on defining content for a blog site in Hugo is covered in another article.
Dockerfile
FROM alpine:3.17.3
ENV SSHUSER=ENV SSHPASSWORD=RUN apk add --update --no-cache \
git \
gcompat \
libc6-compat \
libstdc++ \
nginx \
openssh
RUN echo 'PasswordAuthentication yes' >> /etc/ssh/sshd.config
RUN ln -s /lib/libc.so.6 /usr/lib/libresolv.so.2
RUN mkdir /etc/nginx/sites-available /etc/nginx/sites-enabled
COPY nginx.conf /etc/nginx/
COPY net.redbarrel.knowhow.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/net.redbarrel.knowhow.conf /etc/nginx/sites-enabled/net.redbarrel.knowhow.conf
COPY hugo /usr/local/bin/
RUN chmod +x /usr/local/bin/hugo
COPY hugo-cron /etc/cron.d/hugo-cron
RUN chmod +x /etc/cron.d/hugo-cron
RUN crontab /etc/cron.d/hugo-cron
RUN touch /var/log/cron.log
COPY entrypoint.sh /
WORKDIR /srv
ENTRYPOINT ["/entrypoint.sh"]