# Production image for the dezky platform-api (NestJS, ESM + NodeNext).
# Build context = this directory (services/platform-api).
# syntax=docker/dockerfile:1

FROM node:22-alpine AS build
WORKDIR /app
RUN corepack enable
# Install deps first for layer caching (pnpm version comes from packageManager).
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

FROM node:22-alpine AS deps
WORKDIR /app
RUN corepack enable
COPY package.json pnpm-lock.yaml ./
# Production-only deps for the runtime layer (no dev/build tooling).
RUN pnpm install --frozen-lockfile --prod

FROM node:22-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3001
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY package.json ./
EXPOSE 3001
# main.ts compiles to dist/main.js; NodeNext ESM output is run directly by node.
CMD ["node", "dist/main.js"]
