-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (47 loc) · 1.54 KB
/
Copy pathDockerfile
File metadata and controls
65 lines (47 loc) · 1.54 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
# =============================================================================
# Stage 1: Builder - compile TypeScript
# =============================================================================
FROM node:22-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies for build)
RUN npm ci
# Copy source code
COPY tsconfig.json ./
COPY src/ ./src/
# Build TypeScript
RUN npm run build
# =============================================================================
# Stage 2: Runtime - minimal production image
# =============================================================================
FROM node:22-alpine AS runtime
# Build arguments with defaults
ARG PORT=3000
ARG TLS_PORT=3443
# Environment variables for runtime
ENV PORT=${PORT}
ENV TLS_PORT=${TLS_PORT}
ENV NODE_ENV=production
WORKDIR /app
# Install curl for healthcheck
RUN apk add --no-cache curl
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm ci --omit=dev && \
chown -R nodejs:nodejs /app
# Copy built application from builder stage
COPY --from=builder /app/dist/ ./dist/
# Switch to non-root user
USER nodejs
# Expose ports
EXPOSE ${PORT} ${TLS_PORT}
# Health check using curl
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -sf http://localhost:${PORT}/health || exit 1
# Start the relay server
CMD ["node", "dist/relay/server.js"]