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.
This commit is contained in:
T. Narantuya 2025-08-29 18:52:31 +09:00
parent e9c8d193b7
commit c025993384

View File

@ -76,16 +76,19 @@ COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY packages/shared/package.json ./packages/shared/ COPY packages/shared/package.json ./packages/shared/
COPY apps/bff/package.json ./apps/bff/ 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/packages/shared/dist ./packages/shared/dist
COPY --from=builder /app/apps/bff/dist ./apps/bff/dist COPY --from=builder /app/apps/bff/dist ./apps/bff/dist
COPY --from=builder /app/apps/bff/prisma ./apps/bff/prisma 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) # Generate Prisma client in the production image (ensures engines and client are present)
WORKDIR /app/apps/bff WORKDIR /app/apps/bff
RUN pnpm prisma generate RUN pnpm prisma generate