FROM node:20-alpine AS build

WORKDIR /app

ARG NEXT_PUBLIC_GOOGLE_CLIENT_ID
ARG NEXT_PUBLIC_MICROSOFT_CLIENT_ID
ARG NEXT_PUBLIC_MICROSOFT_TENANT
ARG NEXT_PUBLIC_API_BASE_URL

ENV NEXT_PUBLIC_GOOGLE_CLIENT_ID=$NEXT_PUBLIC_GOOGLE_CLIENT_ID
ENV NEXT_PUBLIC_MICROSOFT_CLIENT_ID=$NEXT_PUBLIC_MICROSOFT_CLIENT_ID
ENV NEXT_PUBLIC_MICROSOFT_TENANT=$NEXT_PUBLIC_MICROSOFT_TENANT
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL

COPY package*.json .npmrc ./
RUN npm ci

COPY . .
RUN npm run build

FROM nginx:1.29.8-alpine

COPY nginx.conf.template /etc/nginx/jobtracker.conf.template
COPY configure-nginx-origin.sh /docker-entrypoint.d/15-jobtracker-origin.sh
RUN chmod +x /docker-entrypoint.d/15-jobtracker-origin.sh
COPY --from=build /app/out /usr/share/nginx/html

EXPOSE 80

CMD ["nginx","-g","daemon off;"]
