-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.node
More file actions
100 lines (73 loc) · 2.17 KB
/
Copy pathDockerfile.node
File metadata and controls
100 lines (73 loc) · 2.17 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
# Node.js WebSocket Relay Dockerfile for Monarchs Chat System
# Multi-stage build for production
# ===================================================================
# Build Stage
# ===================================================================
FROM node:20-alpine AS builder
# Install build dependencies for native modules
RUN apk add --no-cache \
python3 \
make \
g++
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# ===================================================================
# Production Stage
# ===================================================================
FROM node:20-alpine AS production
# Install runtime dependencies
RUN apk add --no-cache \
curl \
ca-certificates \
tini
# Create non-root user for security
RUN addgroup -g 1000 -S nodejs && \
adduser -u 1000 -S -G nodejs -s /bin/sh nodejs
# Set working directory
WORKDIR /home/nodejs
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production && \
npm cache clean --force
# Copy application source
COPY server.js ./
COPY config.yaml ./
# Set ownership
RUN chown -R nodejs:nodejs /home/nodejs
# Switch to non-root user
USER nodejs
# Expose WebSocket port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Environment variables
ENV NODE_ENV=production
ENV HOME=/home/nodejs
# Use tini for proper signal handling
ENTRYPOINT ["/sbin/tini", "--"]
# Start command
CMD ["node", "server.js"]
# Labels
LABEL maintainer="Monarchs Team" \
version="2.0.0" \
description="Monarchs Chat System - Node.js WebSocket Relay"
# ===================================================================
# Development Stage (optional)
# ===================================================================
FROM builder AS development
WORKDIR /app
# Copy source code
COPY server.js ./
COPY config.yaml ./
# Install all dependencies including dev
RUN npm install
# Expose ports
EXPOSE 8080
# Development command with hot reload
CMD ["npm", "run", "dev"]