Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (65 loc) · 3.19 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (65 loc) · 3.19 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
# Dockerfile
# Rust sidecar: builds the nexus-stream-proxy binary used as the byte pipe
# for video playback. Needs musl-dev + openssl for the static linking that
# lets the binary run in the alpine-based runtime stage.
#
# Plain single-stage build (no dep-cache warmup trick): cargo's fingerprint
# tracking doesn't always detect source changes when a cached dummy build is
# replaced with real source, producing a binary from the dummy. Accepting a
# longer first-build time in exchange for a correct build every time.
FROM rust:1.85-alpine AS rust-build
RUN apk add --no-cache musl-dev pkgconfig openssl-dev openssl-libs-static
WORKDIR /stream-proxy
COPY stream-proxy/Cargo.toml stream-proxy/Cargo.lock ./
COPY stream-proxy/src ./src
COPY stream-proxy/tests ./tests
RUN cargo build --release
FROM node:22-alpine AS deps
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@latest --activate
# python3 + build tools: better-sqlite3 tries prebuild-install first but falls
# back to node-gyp compilation when the prebuilt binary for this exact Node
# version isn't available. Without these, the fallback fails with "gyp ERR!
# find Python" and the whole deps stage dies.
RUN apk add --no-cache python3 make g++
# pnpm-workspace.yaml is REQUIRED — it carries the onlyBuiltDependencies
# allowlist for better-sqlite3. Without it, pnpm 10 blocks the install
# script and the native .node binding never builds, leading to a runtime
# "Could not locate the bindings file" crash. See gotcha_pnpm_better_sqlite3.md
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
FROM node:22-alpine AS build
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@latest --activate
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM node:22-alpine AS runtime
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@latest --activate
# Same reason as deps stage — better-sqlite3 may fall back to node-gyp.
RUN apk add --no-cache python3 make g++
# Same as deps stage — pnpm-workspace.yaml must be present BEFORE pnpm install
# so the better-sqlite3 build allowlist is honored. Forgetting it produces a
# silently-broken image that crashes on first DB query.
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile --prod
COPY --from=build /app/build ./build
COPY --from=build /app/package.json ./
# Custom entrypoint that wraps adapter-node's handler so we can attach the
# WebSocket upgrade listener on /api/ws. The SvelteKit build alone doesn't
# expose the http.Server instance.
COPY server.js ./
# Rust stream proxy: handles the byte pipe for video playback.
# Placed in the path the Node supervisor (src/lib/server/stream-proxy.ts) expects.
COPY --from=rust-build /stream-proxy/target/release/nexus-stream-proxy /app/stream-proxy/target/release/nexus-stream-proxy
# Drizzle migrations must ship in the runtime image — bootstrapSchema() runs
# them on first boot. Without this folder, fresh installs skip bootstrap and
# crash on the first query against any newly added column.
COPY --from=build /app/drizzle ./drizzle
ENV NODE_ENV=production
ENV PORT=8585
ENV DATABASE_URL=./data/nexus.db
RUN mkdir -p /app/data
EXPOSE 8585
CMD ["node", "server.js"]