# The published Atlas page as a container, on Red Hat's hardened images: build the static site with Node, check
# the nginx config with the nginx builder (it has a shell), then serve with the distroless nginx runtime (no shell
# or package manager, UID 65532, port 8080). .gitea/workflows/image.yml builds this on every push to main and
# pushes it to harbor.kenschiano.net/home/threshing-atlas:latest; Argo CD Image Updater rolls the deployment
# (kubefiles, web/threshing-atlas) when that digest changes.
ARG NODE_TAG=22
ARG NGINX_TAG=latest

FROM registry.access.redhat.com/hi/nodejs:${NODE_TAG}-builder AS build
# Only /site leaves this stage, so build as root
USER root
WORKDIR /src
COPY . .
RUN node site/build.js /site

# Fail the build on a bad config, since the runtime image can't run `nginx -t` for us
FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}-builder AS nginx-check
COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf
RUN nginx -t -e /dev/stderr

FROM registry.access.redhat.com/hi/nginx:${NGINX_TAG}
COPY --from=nginx-check /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /site /usr/share/nginx/html
EXPOSE 8080
