ARG APP_VERSION=4.2.3

FROM node:22-alpine AS builder
ARG APP_VERSION

WORKDIR /app

COPY package.json ./
RUN npm install

COPY . .
RUN node --experimental-strip-types --import="file:///app/scripts/sveltekit-resolver.mjs" scripts/export-homepage-content.mjs
RUN npm run build

FROM node:22-alpine AS runner
ARG APP_VERSION

WORKDIR /app
ENV NODE_ENV=production
ENV APP_VERSION=${APP_VERSION}
LABEL org.opencontainers.image.version="${APP_VERSION}"

COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/build ./build
COPY --from=builder /app/scripts/sync-homepage-content.mjs ./scripts/sync-homepage-content.mjs
COPY --from=builder /app/deploy-data/homepage-content.json ./deploy-data/homepage-content.json

EXPOSE 3000

CMD ["node", "build"]
