-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.server
More file actions
61 lines (48 loc) · 1.79 KB
/
Dockerfile.server
File metadata and controls
61 lines (48 loc) · 1.79 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
# Server Dockerfile - Colyseus game server
FROM node:20-alpine3.20 AS builder
RUN apk add --no-cache git
WORKDIR /app
# Install all workspaces (shared + server) in builder
COPY package.json package-lock.json ./
COPY shared/package.json ./shared/
COPY server/package.json ./server/
RUN npm install --workspaces --include-workspace-root
COPY shared ./shared
RUN npm run build --workspace=shared
# Build server
COPY server/package.json ./server/
COPY shared/package.json ./shared/
# shared/dist is already built in this stage, no need to copy from another stage
RUN npm ci --workspace=server --workspace=shared --production=false
COPY server ./server
COPY shared ./shared
RUN npm run build --workspace=server
# Production runtime
FROM node:20-alpine3.20
RUN apk add --no-cache git
WORKDIR /app
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
# Copy workspace root package.json + lockfile
COPY package.json package-lock.json ./
# Copy entire shared directory (needed for @shared path resolution)
COPY shared ./shared
COPY --from=builder /app/shared/dist ./shared/dist
# Copy server package
COPY server/package.json ./server/
COPY --from=builder /app/server/dist ./server/dist
# Install production dependencies (workspace linking needs the full structure)
# QEMU emulation for multi-arch builds can be flaky with network, so we increase retries/timeouts
RUN npm config set fetch-retries 5 \
&& npm config set fetch-retry-mintimeout 20000 \
&& npm config set fetch-retry-maxtimeout 120000 \
&& npm install --workspaces --include-workspace-root --production=true
# Change ownership to non-root user
RUN chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
EXPOSE 3000
ENV NODE_ENV=production
ENV PORT=3000
CMD ["node", "server/dist/index.js"]