To host my Hugo generated static site I’ll need a web server.
For this task I have chosen to use nginx.
The container image will actually be build during deployment using a pipeline. More on that in a later post.
Containerfile
Let’s first take a look at the containerfile. It’s not overly complicated as I don’t need anything special.
Basically I am taking a standard nginx (alpine based) image and copying my site files as well as a configuration file into the container image.
FROM nginx:alpine
COPY public /usr/share/nginx/html
COPY jenkins/default.conf /etc/nginx/conf.d/default.conf
nginx configuration
The configuration file for nginx is also quite simple.
server {
listen 80;
server_name localhost;
location / {
add_header Content-Security-Policy "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline';";
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
It listens on localhost port 80. Has the location for the files defined as well as some security headers.
The unsafe-inline
parameter is necessary for the syntax highlighting to work.
Build
For completeness here is the build command.
docker build -t hugo-nginx:teknikuglen -f Containerfile .
Parting words
So that’s another image ready for deployment.