# Ignore hadolint version pinning rules
# hadolint global ignore=DL3016,DL3018
FROM docker.io/library/node:20-alpine AS builder
ENV CONFIGURATION=production

RUN apk add --no-cache git npm \
  && rm -rf /var/cache/apk/*
RUN npm install -g @angular/cli

WORKDIR /app
COPY . /app
RUN npm install \
  && ng build "typescript-xmlrpc" --configuration=$CONFIGURATION \
  && ng build "cobbler-api" --configuration=$CONFIGURATION \
  && ng build "cobbler-frontend" --configuration=$CONFIGURATION

FROM docker.io/nginxinc/nginx-unprivileged:1.31-alpine
ENV COBBLER_WEB_BASE_PATH=""
ENV COBBLER_WEB_ABSOLUTE_REDIRECT="on"
WORKDIR /usr/share/nginx/html
USER 0
RUN ["rm", "index.html", "50x.html"]
COPY --from=builder /app/docker/default.conf.template /etc/nginx/templates/default.conf.template
COPY --from=builder /app/docker/*.sh /docker-entrypoint.d/
COPY --from=builder /app/dist/cobbler-frontend/browser /usr/share/nginx/html
RUN chown -R 101:101 /usr/share/nginx/html
USER 101
