# ── Install dependencies ─────────────────────────────────────────────────────
FROM node:22-alpine AS deps
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
COPY prisma ./prisma/
RUN pnpm install --frozen-lockfile

# ── Production ───────────────────────────────────────────────────────────────
FROM node:22-alpine
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
ENV NODE_ENV=production

COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm prisma generate

EXPOSE 3001

# Build Astro (needs DB) then start Fastify API
CMD ["sh", "-c", "pnpm prisma migrate deploy && pnpm build && node server.mjs"]
