11# ===== BUILD STAGE =====
2- FROM node:20-alpine AS builder
2+ FROM node:20-bookworm-slim AS builder
33
44WORKDIR /app
55
6- # Install system dependencies required for native module compilation,
7- # plus curl and bash (needed to run the Bun installation script)
8- RUN apk add --no-cache python3 make g++ curl bash
9-
10- # Install Bun globally and relocate it to a shared, persistent location
11- RUN curl -fsSL https://bun.sh/install | bash \
12- && mv /root/.bun /opt/bun \
13- && ln -s /opt/bun/bin/bun /usr/local/bin/bun
14-
15- # Ensure Bun is available in PATH for subsequent commands
16- ENV PATH="/opt/bun/bin:${PATH}"
17-
186# Copy package manifests to install dependencies
197COPY package*.json ./
208
21- # Install all dependencies (including devDependencies) using Bun
22- # --frozen-lockfile ensures reproducible builds
23- # --concurrent-scripts and --network-concurrency optimize install speed
24- RUN bun install --frozen-lockfile
9+ # Install all dependencies (including devDependencies) for build
10+ RUN npm ci
2511
2612# Copy source code and build the application
2713COPY src/ ./src/
2814COPY tsconfig.json ./
29- RUN bun run build
15+ RUN NODE_OPTIONS= "--max-old-space-size=4096" npm run build
3016
31- # Remove devDependencies to reduce image size
32- # (Removing all the devDependencies that we dont need in the final build)
17+ # Remove devDependencies to reduce image size for the runtime image
3318RUN npm prune --omit=dev
3419
3520
3621# ===== PRODUCTION STAGE =====
37- FROM node:20-alpine AS production
22+ FROM node:20-bookworm-slim AS production
3823
3924WORKDIR /app
4025
41- # Install timezone data for proper TZ support
42- RUN apk add --no-cache tzdata
43-
4426# Create a dedicated non-root user for security
45- RUN addgroup -g 1001 -S appgroup \
46- && adduser -u 1001 -S appuser -G appgroup
27+ RUN groupadd --gid 1001 appgroup \
28+ && useradd --uid 1001 --gid appgroup --system --no-create-home appuser
4729
4830# Copy only production artifacts from the builder stage
4931COPY --from=builder /app/node_modules ./node_modules/
@@ -66,4 +48,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
6648 CMD node -e "require('http').get('http://localhost:8080/health', (res) => process.exit(res.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
6749
6850# Start the application using npm
69- ENTRYPOINT ["npm" , "start" ]
51+ ENTRYPOINT ["npm" , "start" ]
0 commit comments