FROM node:22-alpine AS builder
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build
RUN npm prune --production


FROM node:22-alpine

ARG PUBLIC_GIT_REF
ARG PUBLIC_BUILD_DATE
ENV PUBLIC_GIT_REF=$PUBLIC_GIT_REF
ENV PUBLIC_BUILD_DATE=$PUBLIC_BUILD_DATE

USER node:node
WORKDIR /app
COPY --from=builder --chown=node:node /app/build build/
COPY --from=builder --chown=node:node /app/node_modules node_modules/
COPY package.json .
EXPOSE 3000
ENV NODE_ENV=production
CMD [ "node", "build" ]