FROM node:22-alpine AS build

# Same value as the backend's BUILD_VERSION so the client can compare them.
ARG BUILD_VERSION=unknown
ENV VITE_BUILD_VERSION=${BUILD_VERSION}

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --no-audit --no-fund
COPY . .
RUN npm run build

FROM nginx:alpine

# Defaults; override at runtime. The nginx entrypoint runs envsubst over
# /etc/nginx/templates/*.template, so only these referenced vars are replaced.
ENV API_TOKEN_HEADER=X-API-Token
ENV API_TOKEN=

COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/templates/default.conf.template

# Marker so the deploy can verify the served build matches the commit.
ARG BUILD_VERSION=unknown
RUN printf '%s' "${BUILD_VERSION}" > /usr/share/nginx/html/.build-version

EXPOSE 80
