Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
309 lines (238 loc) · 10.5 KB
/
Copy pathDockerfile
File metadata and controls
309 lines (238 loc) · 10.5 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# ==============================================================================
# Base image
# ==============================================================================
FROM node:26.5.1-slim AS base
WORKDIR /app
# ==============================================================================
# Install all build dependencies
# ==============================================================================
FROM base AS deps
# Native module compilation requirements.
RUN apt-get update && \
apt-get install -y python3 make g++ && \
rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json ./
COPY patches/ patches/
COPY common/package.json common/
COPY bcf/package.json bcf/
COPY blertbank-client/package.json blertbank-client/
COPY web/package.json web/
COPY socket-server/package.json socket-server/
COPY blertbank/package.json blertbank/
COPY effect-runner/package.json effect-runner/
RUN npm ci
# ==============================================================================
# Install production-only dependencies
# ==============================================================================
FROM base AS deps-prod
COPY package.json package-lock.json ./
COPY patches/ patches/
COPY common/package.json common/
COPY bcf/package.json bcf/
COPY blertbank-client/package.json blertbank-client/
COPY web/package.json web/
COPY socket-server/package.json socket-server/
COPY blertbank/package.json blertbank/
COPY effect-runner/package.json effect-runner/
RUN npm ci && npm prune --omit=dev
# ==============================================================================
# Build common (protobuf generation + tsc)
# ==============================================================================
FROM deps AS common-build
COPY tsconfig.base.json ./
COPY proto/ proto/
COPY common/ common/
RUN npm run -w common build
# ==============================================================================
# Build bcf
# ==============================================================================
FROM common-build AS bcf-build
COPY bcf/ bcf/
RUN npm run -w @blert/bcf build
# ==============================================================================
# Build blertbank-client
# ==============================================================================
FROM common-build AS blertbank-client-build
COPY blertbank-client/ blertbank-client/
RUN npm run -w @blert/blertbank-client build
# ==============================================================================
# Build web app
# ==============================================================================
FROM bcf-build AS web-build
# Web depends on both bcf and blertbank-client.
COPY --from=blertbank-client-build /app/blertbank-client/dist/ blertbank-client/dist/
# NEXT_PUBLIC_ vars must be present at build time
ARG NEXT_PUBLIC_LIVE_SERVER_URL=http://localhost:3010
ARG NEXT_PUBLIC_BLERTCOIN_ENABLED=false
# Umami analytics, inlined into client bundles. Disabled if left unset.
ARG NEXT_PUBLIC_UMAMI_WEBSITE_ID=
ARG NEXT_PUBLIC_UMAMI_SCRIPT_URL=
# Dummy values so server modules can be evaluated during page data collection.
# These are never used at runtime.
ENV BLERT_DATABASE_URI=postgres://build:build@localhost/build
ENV BLERT_DATA_REPOSITORY=file:///tmp
ENV BLERT_WEB_REPOSITORY=file:///tmp
COPY web/ web/
RUN npm run -w web build
# ==============================================================================
# Build socket-server
# ==============================================================================
FROM common-build AS socket-server-build
COPY socket-server/ socket-server/
RUN npm run -w @blert/socket-server build
# ==============================================================================
# Build blertbank
# ==============================================================================
FROM common-build AS blertbank-build
COPY blertbank/ blertbank/
RUN npm run -w @blert/blertbank build
# ==============================================================================
# Build effect-runner
# ==============================================================================
FROM common-build AS effect-runner-build
COPY effect-runner/ effect-runner/
RUN npm run -w @blert/effect-runner build
# ==============================================================================
# Runtime: web
# ==============================================================================
FROM base AS web
ENV NODE_ENV=production
ENV PORT=3000
COPY --from=web-build /app/web/.next/standalone/ ./
COPY --from=web-build /app/web/.next/static/ web/.next/static/
COPY --from=web-build /app/web/public/ web/public/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
EXPOSE 3000
CMD ["node", "web/server.js"]
# ==============================================================================
# Runtime: socket-server
# ==============================================================================
FROM base AS socket-server
ENV NODE_ENV=production
ENV PORT=3003
COPY --from=deps-prod /app/node_modules/ node_modules/
COPY --from=common-build /app/common/dist/ common/dist/
COPY --from=common-build /app/common/generated/ common/generated/
COPY --from=common-build /app/proto/recording_config.json .
COPY --from=common-build /app/proto/attack_definitions.json .
COPY --from=common-build /app/proto/spell_definitions.json .
COPY --from=socket-server-build /app/socket-server/dist/ socket-server/dist/
COPY common/package.json common/
COPY socket-server/package.json socket-server/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
EXPOSE 3003
CMD ["node", "socket-server/dist/app.js"]
# ==============================================================================
# Runtime: blertbank
# ==============================================================================
FROM base AS blertbank
ENV NODE_ENV=production
ENV PORT=3003
COPY --from=deps-prod /app/node_modules/ node_modules/
COPY --from=common-build /app/common/dist/ common/dist/
COPY --from=common-build /app/common/generated/ common/generated/
COPY --from=blertbank-build /app/blertbank/dist/ blertbank/dist/
COPY common/package.json common/
COPY blertbank/package.json blertbank/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
EXPOSE 3003
CMD ["node", "blertbank/dist/app.js"]
# ==============================================================================
# Runtime: effect-runner
# ==============================================================================
FROM base AS effect-runner
ENV NODE_ENV=production
ENV PORT=3003
COPY --from=deps-prod /app/node_modules/ node_modules/
COPY --from=common-build /app/common/dist/ common/dist/
COPY --from=common-build /app/common/generated/ common/generated/
COPY --from=effect-runner-build /app/effect-runner/dist/ effect-runner/dist/
COPY common/package.json common/
COPY effect-runner/package.json effect-runner/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
EXPOSE 3003
CMD ["node", "effect-runner/dist/app.js"]
# ==============================================================================
# Runtime: migrate (runs the main database's migrations)
# ==============================================================================
FROM base AS migrate
ENV NODE_ENV=production
COPY --from=deps-prod /app/node_modules/ node_modules/
COPY --from=common-build /app/common/dist/ common/dist/
COPY --from=common-build /app/common/generated/ common/generated/
COPY common/package.json common/
COPY common/migrations/ common/migrations/
CMD ["node", "common/dist/migrations/migrate.js"]
# ==============================================================================
# Shared Rust workspace
# ==============================================================================
FROM rust:1-slim AS rust-workspace
WORKDIR /app
# Install protobuf compiler for prost-build.
RUN apt-get update && \
apt-get install -y protobuf-compiler && \
rm -rf /var/lib/apt/lists/*
# Lay out the workspace with every member stubbed, along with blertlib's build
# inputs. Each service stage builds its dependencies against the stubs first,
# so they are cached separately from source changes.
COPY Cargo.toml Cargo.lock ./
COPY blertlib/Cargo.toml blertlib/build.rs ble
7586
rtlib/
COPY challenge-harder/Cargo.toml challenge-harder/
COPY live-server/Cargo.toml live-server/
COPY proto/ proto/
COPY web/resources/extended_items.json web/resources/
RUN mkdir -p blertlib/src challenge-harder/src live-server/src && \
touch blertlib/src/lib.rs && \
echo 'fn main() {}' > challenge-harder/src/main.rs && \
echo 'fn main() {}' > live-server/src/main.rs
# ==============================================================================
# Build live-server
# ==============================================================================
FROM rust-workspace AS live-server-build
RUN cargo build --release -p live-server
COPY blertlib/src/ blertlib/src/
COPY live-server/src/ live-server/src/
RUN touch blertlib/src/lib.rs live-server/src/main.rs && \
cargo build --release -p live-server
# ==============================================================================
# Runtime: live-server
# ==============================================================================
FROM debian:trixie-slim AS live-server
RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=live-server-build /app/target/release/live-server /usr/local/bin/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
ENV PORT=3010
EXPOSE 3010
CMD ["live-server"]
# ==============================================================================
# Build challenge-harder
# ==============================================================================
FROM rust-workspace AS challenge-harder-build
COPY challenge-harder/build.rs challenge-harder/
RUN cargo build --release -p challenge-harder
COPY blertlib/src/ blertlib/src/
COPY challenge-harder/src/ challenge-harder/src/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
RUN touch blertlib/src/lib.rs challenge-harder/src/main.rs && \
cargo build --release -p challenge-harder
# ==============================================================================
# Runtime: challenge-harder
# ==============================================================================
FROM debian:trixie-slim AS challenge-harder
RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=challenge-harder-build /app/target/release/challenge-harder /usr/local/bin/
ARG BLERT_COMMIT_SHA
ENV BLERT_COMMIT_SHA=$BLERT_COMMIT_SHA
ENV PORT=3003
EXPOSE 3003
CMD ["challenge-harder"]