File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33# Using Debian slim for better native module compatibility
44# =============================================================================
55
6- FROM node:20-slim
6+ FROM node:20-slim AS builder
77
8- # Install dumb-init for proper signal handling
8+ # Install build dependencies for native modules (better-sqlite3)
99RUN apt-get update && apt-get install -y --no-install-recommends \
10- dumb-init \
11- wget \
10+ python3 \
11+ build-essential \
1212 && rm -rf /var/lib/apt/lists/*
1313
1414WORKDIR /app
@@ -26,6 +26,29 @@ RUN pnpm install --frozen-lockfile
2626COPY . .
2727RUN pnpm build
2828
29+ # =============================================================================
30+ # Production stage - minimal runtime image
31+ # =============================================================================
32+ FROM node:20-slim
33+
34+ # Install runtime dependencies only
35+ RUN apt-get update && apt-get install -y --no-install-recommends \
36+ dumb-init \
37+ wget \
38+ && rm -rf /var/lib/apt/lists/*
39+
40+ WORKDIR /app
41+
42+ # Enable pnpm for runtime
43+ RUN corepack enable pnpm
44+
45+ # Copy package files
46+ COPY package.json pnpm-lock.yaml* .npmrc* ./
47+
48+ # Copy built artifacts and node_modules from builder
49+ COPY --from=builder /app/dist ./dist
50+ COPY --from=builder /app/node_modules ./node_modules
51+
2952# Create non-root user for security
3053RUN groupadd --system --gid 1001 nodejs && \
3154 useradd --system --uid 1001 --gid nodejs appuser && \
Original file line number Diff line number Diff line change 33# Using Debian slim for better native module compatibility
44# =============================================================================
55
6- FROM node:20-slim
6+ FROM node:20-slim AS builder
77
8- # Install dumb-init for proper signal handling
8+ # Install build dependencies for native modules (better-sqlite3)
99RUN apt-get update && apt-get install -y --no-install-recommends \
10- dumb-init \
11- wget \
10+ python3 \
11+ build-essential \
1212 && rm -rf /var/lib/apt/lists/*
1313
1414WORKDIR /app
@@ -26,6 +26,29 @@ RUN pnpm install --frozen-lockfile
2626COPY . .
2727RUN pnpm build
2828
29+ # =============================================================================
30+ # Production stage - minimal runtime image
31+ # =============================================================================
32+ FROM node:20-slim
33+
34+ # Install runtime dependencies only
35+ RUN apt-get update && apt-get install -y --no-install-recommends \
36+ dumb-init \
37+ wget \
38+ && rm -rf /var/lib/apt/lists/*
39+
40+ WORKDIR /app
41+
42+ # Enable pnpm for runtime
43+ RUN corepack enable pnpm
44+
45+ # Copy package files
46+ COPY package.json pnpm-lock.yaml* .npmrc* ./
47+
48+ # Copy built artifacts and node_modules from builder
49+ COPY --from=builder /app/dist ./dist
50+ COPY --from=builder /app/node_modules ./node_modules
51+
2952# Create non-root user for security
3053RUN groupadd --system --gid 1001 nodejs && \
3154 useradd --system --uid 1001 --gid nodejs appuser && \
Original file line number Diff line number Diff line change 33# Using Debian slim for better native module compatibility
44# =============================================================================
55
6- FROM node:20-slim
6+ FROM node:20-slim AS builder
77
8- # Install dumb-init for proper signal handling
8+ # Install build dependencies for native modules (better-sqlite3)
99RUN apt-get update && apt-get install -y --no-install-recommends \
10- dumb-init \
11- wget \
10+ python3 \
11+ build-essential \
1212 && rm -rf /var/lib/apt/lists/*
1313
1414WORKDIR /app
@@ -26,6 +26,29 @@ RUN pnpm install --frozen-lockfile
2626COPY . .
2727RUN pnpm build
2828
29+ # =============================================================================
30+ # Production stage - minimal runtime image
31+ # =============================================================================
32+ FROM node:20-slim
33+
34+ # Install runtime dependencies only
35+ RUN apt-get update && apt-get install -y --no-install-recommends \
36+ dumb-init \
37+ wget \
38+ && rm -rf /var/lib/apt/lists/*
39+
40+ WORKDIR /app
41+
42+ # Enable pnpm for runtime
43+ RUN corepack enable pnpm
44+
45+ # Copy package files
46+ COPY package.json pnpm-lock.yaml* .npmrc* ./
47+
48+ # Copy built artifacts and node_modules from builder
49+ COPY --from=builder /app/dist ./dist
50+ COPY --from=builder /app/node_modules ./node_modules
51+
2952# Create non-root user for security
3053RUN groupadd --system --gid 1001 nodejs && \
3154 useradd --system --uid 1001 --gid nodejs appuser && \
You can’t perform that action at this time.
0 commit comments