FROM node:24-alpine AS build

WORKDIR /app

ARG NPM_REGISTRY=https://registry.npmmirror.com

COPY package*.json ./
RUN --mount=type=cache,target=/root/.npm \
    npm ci \
      --registry="${NPM_REGISTRY}" \
      --fetch-retries=5 \
      --fetch-retry-mintimeout=20000 \
      --fetch-retry-maxtimeout=120000 \
      --no-audit \
      --no-fund

COPY . .
RUN npm run build

FROM node:24-alpine AS runtime

RUN apk add --no-cache nginx

COPY --from=build /app/dist /usr/share/nginx/html
COPY --from=build /app/server /app/server
COPY docker/nginx.conf /etc/nginx/http.d/default.conf

ENV INQUIRY_API_PORT=5174

EXPOSE 80

CMD ["sh", "-c", "node /app/server/cms-server.mjs & exec nginx -g 'daemon off;'"]
