forked from HyperscapeAI/hyperscape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.server
More file actions
134 lines (111 loc) · 4.86 KB
/
Dockerfile.server
File metadata and controls
134 lines (111 loc) · 4.86 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Multi-stage Dockerfile for Hyperscape Game Server (Railway Deployment)
# Builds the server with all dependencies and creates a lean runtime image
# Run from repository root: docker build -f Dockerfile.server .
# ============================================================================
# Stage 1: Builder - Install dependencies and build packages
# ============================================================================
FROM oven/bun:1.1.38-debian AS builder
# Install build dependencies for native modules (canvas, better-sqlite3)
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
pkg-config \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy package files for dependency installation
COPY package.json bun.lock ./
COPY packages/physx-js-webidl/package.json ./packages/physx-js-webidl/
COPY packages/procgen/package.json ./packages/procgen/
COPY packages/impostors/package.json ./packages/impostors/
COPY packages/decimation/package.json ./packages/decimation/
COPY packages/shared/package.json ./packages/shared/
COPY packages/server/package.json ./packages/server/
COPY packages/client/package.json ./packages/client/
# Set CI environment to skip asset download in postinstall
ENV CI=true
ENV SKIP_ASSETS=true
# Copy source code and scripts FIRST
COPY scripts ./scripts
COPY packages/physx-js-webidl ./packages/physx-js-webidl
COPY packages/procgen ./packages/procgen
COPY packages/impostors ./packages/impostors
COPY packages/decimation ./packages/decimation
COPY packages/shared ./packages/shared
COPY packages/server ./packages/server
COPY packages/client ./packages/client
COPY turbo.json ./
COPY tsconfig.json ./
# Install dependencies with all scripts (now that source files are available)
# Trust all lifecycle scripts for this build
RUN bun install --trust
# Note: Assets are served from CDN - no local clone needed
# Manifests are fetched at server startup from PUBLIC_CDN_URL
# Build packages in explicit dependency order (Turbo filter doesn't resolve cross-package deps correctly)
WORKDIR /app
RUN cd packages/physx-js-webidl && bun run build && \
cd ../decimation && bun run build && \
cd ../shared && bun run build && \
cd ../impostors && bun run build && \
cd ../procgen && bun run build && \
cd ../server && bun run build && \
cd ../client && bun run build
# Copy client build to server public directory
RUN mkdir -p /app/packages/server/public && \
cp -r /app/packages/client/dist/* /app/packages/server/public/
# ============================================================================
# Stage 2: Runtime - Minimal production image
# ============================================================================
FROM oven/bun:1.1.38-debian AS runtime
# Install runtime dependencies for native modules and healthcheck
RUN apt-get update && apt-get install -y \
libcairo2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libjpeg62-turbo \
libgif7 \
librsvg2-2 \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy package files for production install
COPY package.json bun.lock ./
COPY packages/physx-js-webidl/package.json ./packages/physx-js-webidl/
COPY packages/procgen/package.json ./packages/procgen/
COPY packages/impostors/package.json ./packages/impostors/
COPY packages/decimation/package.json ./packages/decimation/
COPY packages/shared/package.json ./packages/shared/
COPY packages/server/package.json ./packages/server/
# Set CI environment to skip asset download
ENV CI=true
ENV SKIP_ASSETS=true
ENV NODE_ENV=production
# Copy node_modules from builder (faster than reinstalling)
COPY --from=builder /app/node_modules ./node_modules
# Copy built artifacts from builder
COPY --from=builder /app/packages/physx-js-webidl/dist ./packages/physx-js-webidl/dist
COPY --from=builder /app/packages/procgen/dist ./packages/procgen/dist
COPY --from=builder /app/packages/impostors/dist ./packages/impostors/dist
COPY --from=builder /app/packages/decimation/dist ./packages/decimation/dist
COPY --from=builder /app/packages/shared/build ./packages/shared/build
COPY --from=builder /app/packages/server/dist ./packages/server/dist
COPY --from=builder /app/packages/server/public ./packages/server/public
# Copy server source files needed at runtime (for paths, configs, etc.)
COPY --from=builder /app/packages/server/src ./packages/server/src
# Create manifests directory - manifests are fetched from CDN at startup
RUN mkdir -p ./packages/server/world/assets/manifests
# Set working directory to server
WORKDIR /app/packages/server
# Expose WebSocket port (default 5555, configurable via PORT env)
EXPOSE 5555
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
CMD curl -f http://localhost:${PORT:-5555}/status || exit 1
# Run the server
CMD ["bun", "run", "start"]