# Stage 1: build
FROM node:22-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

# Stage 2: runtime
FROM node:22-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
COPY package.json package-lock.json ./
RUN npm ci --omit=dev && npm cache clean --force
COPY --from=build /app/dist ./dist
COPY scripts ./scripts

ENV HOST=0.0.0.0 \
    PORT=4321 \
    DB_PATH=/app/data/insanitylab.db \
    UPLOADS_DIR=/app/uploads
EXPOSE 4321
CMD ["node", "./dist/server/entry.mjs"]
