From ce372062867ae1fbc98895d3a268ab40d6a5c684 Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Wed, 24 Dec 2025 00:28:39 -0300 Subject: [PATCH] fix(backoffice): simplify Dockerfile for proper source code copying --- backoffice/Dockerfile | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/backoffice/Dockerfile b/backoffice/Dockerfile index 7e0a174..7df8777 100644 --- a/backoffice/Dockerfile +++ b/backoffice/Dockerfile @@ -8,35 +8,28 @@ FROM node:20-alpine AS base RUN corepack enable && corepack prepare pnpm@9.15.4 --activate RUN apk add --no-cache libc6-compat -# Stage 2: Fetch dependencies (better cache utilization) +# Stage 2: Install dependencies FROM base AS deps WORKDIR /app -COPY pnpm-lock.yaml ./ -RUN pnpm fetch +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile # Stage 3: Build FROM base AS builder WORKDIR /app - -# Copy lockfile and fetch cache -COPY pnpm-lock.yaml ./ COPY --from=deps /app/node_modules ./node_modules +COPY package.json pnpm-lock.yaml ./ +COPY tsconfig*.json nest-cli.json ./ +COPY src ./src -# Copy package files and install -COPY package.json ./ -RUN pnpm install --frozen-lockfile --offline - -# Copy source and build -COPY . . +# Build the application RUN pnpm build -# Prune dev dependencies -RUN pnpm prune --prod && \ - pnpm store prune && \ - rm -rf /root/.local/share/pnpm/store +# Prune dev dependencies for production +RUN pnpm prune --prod # ============================================================================= -# Stage 4: Production - Minimal runtime (Distroless alternative: Alpine) +# Stage 4: Production - Minimal runtime # ============================================================================= FROM node:20-alpine AS production @@ -51,18 +44,6 @@ COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules COPY --from=builder --chown=nestjs:nodejs /app/package.json ./ -# Remove unnecessary files to reduce size -RUN find node_modules -name "*.md" -delete 2>/dev/null || true && \ - find node_modules -name "*.d.ts" -delete 2>/dev/null || true && \ - find node_modules -name "CHANGELOG*" -delete 2>/dev/null || true && \ - find node_modules -name "LICENSE*" -delete 2>/dev/null || true && \ - find node_modules -name "*.map" -delete 2>/dev/null || true && \ - find node_modules -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \ - find node_modules -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \ - find node_modules -type d -name "__tests__" -exec rm -rf {} + 2>/dev/null || true && \ - find node_modules -type d -name "docs" -exec rm -rf {} + 2>/dev/null || true && \ - rm -rf /tmp/* /var/cache/apk/* - # Environment ENV NODE_ENV=production ENV BACKOFFICE_PORT=3001