ARG NODE_VERSION=22
FROM node:${NODE_VERSION}-alpine AS base
WORKDIR /app

FROM base AS build
COPY package.json package-lock.json ./
RUN npm install
COPY --link ./ ./
RUN npm run build

FROM build AS master
RUN npm run generate

FROM scratch AS static
COPY --from=master /app/.output/public .

FROM base AS prod
ENV NODE_ENV=production
COPY --from=master /app/.output /app/.output
CMD [ "node", ".output/server/index.mjs" ]
