remove dev dependencies from development containers

This commit is contained in:
Zimeng Xiong
2026-02-07 09:27:39 -08:00
parent bbb23ca661
commit 06f4c0f537
8 changed files with 64 additions and 40 deletions
+9 -6
View File
@@ -3,12 +3,15 @@ FROM node:20-alpine AS builder
WORKDIR /app
# Native build deps for modules that may compile from source (e.g., better-sqlite3 on arm64)
RUN apk add --no-cache python3 make g++
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
# Install dependencies
RUN npm ci
RUN npm ci && npm cache clean --force
# Copy prisma schema
COPY prisma ./prisma/
@@ -25,7 +28,7 @@ RUN npx tsc
# Production stage
FROM node:20-alpine
# Install OpenSSL for Prisma and su-exec, create non-root user
# Install runtime packages and create non-root user
RUN apk add --no-cache openssl su-exec && \
addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
@@ -36,7 +39,10 @@ WORKDIR /app
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production
RUN apk add --no-cache --virtual .build-deps python3 make g++ && \
npm ci --omit=dev && \
npm cache clean --force && \
apk del .build-deps
# Copy prisma schema and migrations for runtime and hydration template
COPY prisma ./prisma/
@@ -48,9 +54,6 @@ COPY --from=builder /app/dist ./dist
# Copy the generated Prisma Client from builder to maintain the same structure
COPY --from=builder /app/src/generated ./dist/generated
# Generate Prisma Client in production (updates node_modules)
RUN npx prisma generate
# Create necessary directories (ownership will be set in entrypoint)
RUN mkdir -p /app/uploads /app/prisma