Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
110 lines (82 loc) · 2.56 KB
/
Copy pathDockerfile
File metadata and controls
110 lines (82 loc) · 2.56 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Multi-stage build for WhatsApp Flow Server
# Supports AMD64 and ARM64 architectures
# ======================
# Stage 1: Builder
# ======================
FROM node:25-alpine AS builder
# Build arguments
ARG VERSION=dev
ARG BUILD_DATE=unknown
# Install build dependencies
RUN apk add --no-cache python3 make g++
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies for build)
RUN npm ci --prefer-offline --no-audit
# Copy source code
COPY tsconfig.json ./
COPY src ./src
# Build the application
RUN npm run build && \
echo "Build version: ${VERSION}" && \
echo "Build date: ${BUILD_DATE}"
# ======================
# Stage 2: Production
# ======================
FROM node:25-alpine
# Metadata labels
LABEL maintainer="Guilherme Jansen"
LABEL org.opencontainers.image.title="WhatsApp Flow Server"
LABEL org.opencontainers.image.description="WhatsApp Flow Server with DDD architecture"
LABEL org.opencontainers.image.source="https://github.com/guilhermejansen/whatsapp-flow"
LABEL org.opencontainers.image.vendor="Guilherme Jansen"
# Build arguments
ARG VERSION=dev
ARG BUILD_DATE=unknown
# Environment labels
LABEL version="${VERSION}"
LABEL build.date="${BUILD_DATE}"
# Install runtime dependencies
RUN apk add --no-cache \
dumb-init \
curl \
tini \
ca-certificates \
postgresql-client && \
update-ca-certificates
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production --prefer-offline --no-audit && \
npm cache clean --force
# Install tsx globally for running TypeScript scripts
RUN npm install -g tsx@4.20.6
# Copy built application from builder stage
COPY --from=builder /app/dist ./dist
# Copy scripts for runtime usage (migrations, key generation, etc)
COPY scripts ./scripts
COPY tsconfig.json ./
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Create directories
RUN mkdir -p /app/logs /app/keys && \
chmod 755 /app/logs /app/keys
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Set ownership
RUN chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# Expose port
EXPOSE 3000
# Use tini to handle signals properly
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/docker-entrypoint.sh"]
# Start application
CMD ["node", "dist/main.js"]