ci/cd

Deploy static site to nginx in docker/kubernetes

Author Photo

Mikael Eklund

· 1 min read
Thumbnail

As Astro is a static site generator and I needed to deploy it to my okd cluster I started to develop against a local Nginx installation that worked. But when I deployed it on my okd cluster the first url worked. But when I clicked a link the base port in my okd route was added and the link did not work.

First there is my Dockerfile. It’s a two step to minimize the size of the container:

# stage build
FROM node:16-alpine
RUN npm install -g pnpm
WORKDIR /app
# copy everything to the container
COPY . .
# install everything to the container
RUN pnpm install
# build Astro-site
RUN pnpm run build

# stage run
FROM nginxinc/nginx-unprivileged
#USER nginx
WORKDIR /app
# copy dependency list
COPY --from=0 /app/package*.json ./
COPY --from=0 /app/default /etc/nginx/conf.d/default.conf
# copy built SvelteKit app to /app
COPY --from=0 /app/dist /usr/share/nginx/html

I coundn’t use the stock Nginx due to okd not wanting to run containers as root. The nginxinc/nginx-unprivileged fixed that.

server {
    listen       8080;
    server_name  localhost;
    absolute_redirect off;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}

server_name localhost; that I add to the default.conf nginx settings is what solves this problem.

#astro#blog#ocp#okd#argocd#nginx#docker
Author Photo

About Mikael Eklund

Mikael Eklund is a Senior it technology specialist. With a passion for technology and programming.