-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (28 loc) · 1.39 KB
/
Copy pathDockerfile
File metadata and controls
40 lines (28 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ── Stage 1: Build ────────────────────────────────────────────────────────────
# Uses full Node image to compile TypeScript → JavaScript
FROM node:20-alpine AS builder
WORKDIR /app
# Install deps first (layer cached unless package.json changes)
COPY package*.json ./
RUN npm ci --ignore-scripts
# Copy source and compile
COPY tsconfig*.json ./
COPY src/ ./src/
RUN npm run build
# ── Stage 2: Production ───────────────────────────────────────────────────────
# Lean image — only compiled JS + production deps, no TypeScript, no devDeps
FROM node:20-alpine AS production
WORKDIR /app
ENV NODE_ENV=production
# Install only production dependencies
COPY package*.json ./
RUN npm ci --omit=dev --ignore-scripts && npm cache clean --force
# Copy compiled output from builder stage
COPY --from=builder /app/dist ./dist
# Run as non-root user (security best practice)
RUN addgroup -g 1001 -S nodejs && adduser -S appuser -u 1001
USER appuser
EXPOSE 5000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD node -e "require('http').get('http://localhost:5000/health', r => process.exit(r.statusCode === 200 ? 0 : 1))"
CMD ["node", "dist/server.js"]