-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (54 loc) · 1.72 KB
/
Dockerfile
File metadata and controls
74 lines (54 loc) · 1.72 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# =========================
# Base image
# =========================
FROM node:22-alpine AS base
WORKDIR /app
# Set a sane default; you can override in docker-compose
ENV NODE_ENV=production
# Avoid npm telemetry noise
ENV NPM_CONFIG_FUND=false
ENV NPM_CONFIG_AUDIT=false
# =========================
# Install dependencies (prod only)
# =========================
FROM base AS deps
# Install dependencies needed to build native modules (if any)
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
# Install ONLY production deps for the final image
RUN npm ci --omit=dev
# =========================
# Build stage (needs devDependencies)
# =========================
FROM base AS builder
# Dev env for best TypeScript / build behavior
ENV NODE_ENV=development
# Build tooling
RUN apk add --no-cache python3 make g++
COPY package.json package-lock.json ./
RUN npm ci
# Copy source and TS config
COPY tsconfig.json ./
COPY src ./src
# Compile TypeScript -> dist/
RUN npm run build
# =========================
# Runtime image
# =========================
FROM node:22-alpine AS runner
WORKDIR /app
# Security: don't run as root
USER node
ENV NODE_ENV=production
# Copy package.json for npm scripts
COPY package.json ./
# Copy production node_modules and built JS
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
# Expose API port
EXPOSE 5000
# Healthcheck (simple HTTP hit to /health)
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD node -e "require('http').get('http://127.0.0.1:5000/health', r => { if (r.statusCode !== 200) process.exit(1); }).on('error', () => process.exit(1));"
# Start both API server and worker (via package.json "start")
CMD ["npm", "start"]