From c025993384d56396bf65881eaff5def9da0bb98f Mon Sep 17 00:00:00 2001 From: "T. Narantuya" Date: Fri, 29 Aug 2025 18:52:31 +0900 Subject: [PATCH] Refactor Dockerfile to optimize production dependency installation - Updated the Dockerfile to install only production dependencies, skipping unnecessary scripts to streamline the build process. - Removed the copying of node_modules from the builder stage to reduce image size and improve efficiency. - Ensured necessary postinstall scripts are executed for essential packages like Prisma and bcrypt. --- apps/bff/Dockerfile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/bff/Dockerfile b/apps/bff/Dockerfile index 018e0727..38d85671 100644 --- a/apps/bff/Dockerfile +++ b/apps/bff/Dockerfile @@ -76,16 +76,19 @@ COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./ COPY packages/shared/package.json ./packages/shared/ COPY apps/bff/package.json ./apps/bff/ -# Copy built applications and dependencies from builder +# Install ONLY production dependencies (no dev dependencies) +# Skip scripts to avoid Husky, but allow other necessary postinstall scripts later +ENV HUSKY=0 +RUN pnpm install --frozen-lockfile --prod --ignore-scripts + +# Run only necessary postinstall scripts (Prisma, bcrypt, etc.) +RUN pnpm rebuild bcrypt @prisma/client @prisma/engines + +# Copy built applications from builder COPY --from=builder /app/packages/shared/dist ./packages/shared/dist COPY --from=builder /app/apps/bff/dist ./apps/bff/dist COPY --from=builder /app/apps/bff/prisma ./apps/bff/prisma -# Copy node_modules from builder (includes all dependencies) -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/packages/shared/node_modules ./packages/shared/node_modules -COPY --from=builder /app/apps/bff/node_modules ./apps/bff/node_modules - # Generate Prisma client in the production image (ensures engines and client are present) WORKDIR /app/apps/bff RUN pnpm prisma generate