fix: robust Dockerfile for Backoffice with pnpm prod-deps
This commit is contained in:
parent
64d13581df
commit
ed1b3c2e53
1 changed files with 13 additions and 12 deletions
|
|
@ -5,21 +5,24 @@ FROM node:22-alpine AS base
|
|||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
WORKDIR /app
|
||||
|
||||
# ===== STAGE 2: Dependencies =====
|
||||
FROM base AS deps
|
||||
# ===== STAGE 2: Prod Dependencies =====
|
||||
FROM base AS prod-deps
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
|
||||
# Cache do pnpm store para builds mais rápidas
|
||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm install --prod --frozen-lockfile
|
||||
|
||||
# Generate Prisma Client in prod-deps to include engines
|
||||
COPY prisma ./prisma
|
||||
RUN pnpm prisma:generate
|
||||
|
||||
# ===== STAGE 3: Build =====
|
||||
FROM deps AS build
|
||||
FROM base AS build
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
||||
pnpm install --frozen-lockfile
|
||||
COPY . .
|
||||
RUN pnpm prisma:generate && pnpm build
|
||||
|
||||
# ===== STAGE 4: Production =====
|
||||
|
||||
# ===== STAGE 4: Production (Distroless) =====
|
||||
FROM gcr.io/distroless/nodejs22-debian12:nonroot
|
||||
|
||||
|
|
@ -27,10 +30,8 @@ WORKDIR /app
|
|||
|
||||
# Copia apenas o necessário para produção
|
||||
COPY --from=build --chown=nonroot:nonroot /app/dist ./dist
|
||||
COPY --from=build --chown=nonroot:nonroot /app/prisma ./prisma
|
||||
COPY --from=build --chown=nonroot:nonroot /app/node_modules/.prisma ./node_modules/.prisma
|
||||
COPY --from=build --chown=nonroot:nonroot /app/node_modules/@prisma ./node_modules/@prisma
|
||||
COPY --from=deps --chown=nonroot:nonroot /app/node_modules ./node_modules
|
||||
# Copy full node_modules from prod-deps (includes prisma client/engines)
|
||||
COPY --from=prod-deps --chown=nonroot:nonroot /app/node_modules ./node_modules
|
||||
COPY --chown=nonroot:nonroot package.json ./
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
|
|
|||
Loading…
Reference in a new issue