# syntax = docker/dockerfile:1.13
FROM docker.io/library/node:22.14.0 AS builder
WORKDIR /app

RUN --mount=type=cache,target=/app/.npm \
    --mount=type=bind,source=package.json,target=package.json \
    --mount=type=bind,source=package-lock.json,target=package-lock.json \
    npm ci --ignore-scripts --cache /app/.npm --prefer-offline

COPY api api

RUN --mount=type=bind,source=package.json,target=package.json \
    --mount=type=bind,source=package-lock.json,target=package-lock.json \
    npm run build-api

COPY . .

RUN npm run build

FROM docker.io/library/node:22.14.0-alpine3.21
WORKDIR /app

ENV PORT=5000 \
    HOST=0.0.0.0

COPY --from=builder /app/.output/ ./

USER node
EXPOSE 5000
CMD ["node", "server/index.mjs"]
