-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
70 lines (50 loc) · 1.78 KB
/
Dockerfile.api
File metadata and controls
70 lines (50 loc) · 1.78 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
# Multi-stage Dockerfile for Node.js API Service
# Optimized for production deployment in Kubernetes
# Stage 1: Base image with dependencies
FROM node:24.12.0-alpine AS base
LABEL maintainer="Darshit Vora"
LABEL description="Node.js API Service with Temporal workflows"
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Set working directory
WORKDIR /usr/src/app
# Copy package files
COPY package*.json ./
# Stage 2: Development dependencies
FROM base AS development
ENV NODE_ENV=development
# Install all dependencies (including devDependencies)
RUN npm ci --include=dev
# Copy source code
COPY . .
# Expose port
EXPOSE ${PORT:-3015}
# Use dumb-init to handle signals properly
CMD ["dumb-init", "npm", "run", "start"]
# Stage 3: Production dependencies
FROM base AS production-deps
ENV NODE_ENV=production
# Install only production dependencies
RUN npm ci --omit=dev && npm cache clean --force
# Stage 4: Production build
FROM base AS production
ENV NODE_ENV=production
# Copy production dependencies from production-deps stage
COPY --from=production-deps /usr/src/app/node_modules ./node_modules
# Copy application source
COPY . .
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 && \
chown -R nodejs:nodejs /usr/src/app
# Create logs directory with proper permissions
RUN mkdir -p logs && chown -R nodejs:nodejs logs
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE ${PORT:-3015}
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:${PORT:-3015}/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"
# Use dumb-init to handle signals properly (PID 1 problem)
CMD ["dumb-init", "node", "./src/server.js"]