datarhei-dragonfork-core/deploy/truenas/core/Dockerfile
Zac Gaetano 26991ec463
Some checks are pending
ci / vet + build (push) Waiting to run
ci / race tests (push) Blocked by required conditions
ci / WebRTC smoke (5-viewer fanout) (push) Blocked by required conditions
ci / WebRTC latency p95 gate (push) Blocked by required conditions
deploy: bundle the official Datarhei Restreamer UI
Replaces the placeholder Dragon Fork landing page at / with the real
React SPA — the same UI that ships in upstream's datarhei/restreamer
image. Operators get the full process management dashboard, log
viewer, restream config, and so on.

Implementation: a new Docker stage 'ui-builder' (node:21-alpine3.20)
clones datarhei/restreamer-ui at a pinned tag (v1.14.0), runs
'yarn install + yarn build' with PUBLIC_URL="./" so all asset
references are relative, and the runtime stage pulls /ui/build into
/core/static. The existing seed-data.sh script then copies it into
/core/data on first boot.

Stacking order in /core/static:
  1. UI bundle from ui-builder — provides index.html, the SPA bundle
     and assets, _player, _playersite, etc.
  2. Dragon Fork deploy/static/* — currently only whep-player.html;
     the placeholder index.html was removed so the UI's wins.

Pinned to v1.14.0 (the most recent tagged restreamer-ui release)
rather than 'main' for reproducible builds. Bumping the pin is a
one-line ARG override.

Image size: ~+25MB compressed (Restreamer UI bundle is ~3MB
gzipped, plus the build-stage layer overhead until pruned).

UI-side configuration: the SPA defaults to talking to the
same-origin /api endpoints, which is exactly what we want when
serving from Core. No '?address=' query string needed on the URL.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 12:58:51 +00:00

92 lines
3.6 KiB
Docker

# Dragon Fork datarhei Core image (M2 + WebRTC egress).
#
# Builds the real root Core binary — the one that replaces the M1 PoC
# in production. FFmpeg is baked in so restream processes can run the
# RTP output legs emitted by the WebRTC subsystem.
#
# Two-stage:
# 1. builder: compile a static Go binary (CGO off — no dynamic libs)
# 2. runtime: alpine with ffmpeg for the subprocess path
#
# Usage via compose:
# docker compose -f deploy/truenas/core/docker-compose.yml up -d --build
#
# The compose file drives configuration via CORE_* env vars — see
# README.md in this directory.
# ---- builder ----
# go.mod requires go 1.24; pinning the image keeps Docker's toolchain
# download off the hot path and makes the build reproducible.
FROM golang:1.24-alpine3.20 AS builder
WORKDIR /src
RUN apk add --no-cache git make
COPY . .
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
RUN make release && make import && make ffmigrate
# ---- ui-builder ----
# Builds the official Datarhei Restreamer UI (React 18 + MUI). Pinned
# to a specific tag so reproducible. PUBLIC_URL=./ makes asset
# references relative — the bundle then works when served from / or
# any subdirectory under Core's static-disk filesystem.
#
# Pulling from the public github mirror keeps the Forgejo runner's
# network footprint small; no auth required for clone.
FROM node:21-alpine3.20 AS ui-builder
ARG RESTREAMER_UI_REF=v1.14.0
RUN apk add --no-cache git
WORKDIR /ui
RUN git clone --depth=1 --branch ${RESTREAMER_UI_REF} \
https://github.com/datarhei/restreamer-ui.git . \
&& yarn install --frozen-lockfile --network-timeout 600000 \
&& PUBLIC_URL="./" GENERATE_SOURCEMAP=false yarn build
# ---- runtime ----
# Alpine with ffmpeg (Core shells out to it for every restream process).
# Scratch isn't an option here because the process manager needs ffmpeg
# on PATH.
FROM alpine:3.20 AS runtime
RUN apk add --no-cache ffmpeg tini ca-certificates
# make release's `-o core` lands the binary inside the core/ Go
# package directory (Go cannot overwrite a directory with a file, so
# it places the output file _inside_ it). The `import` and `ffmigrate`
# Makefile targets cd into app/<name> and write the binary back up to
# the repo root with a relative path, so those end up at /src/import
# and /src/ffmigrate.
COPY --from=builder /src/core/core /core/bin/core
COPY --from=builder /src/import /core/bin/import
COPY --from=builder /src/ffmigrate /core/bin/ffmigrate
COPY --from=builder /src/mime.types /core/mime.types
COPY --from=builder /src/run.sh /core/bin/run.sh
# Static content for /core/data, seeded on first boot by seed-data.sh.
# Stacking order:
# 1. Restreamer UI bundle (the React SPA — gives us index.html)
# 2. Dragon Fork extras (whep-player.html, etc.) — won't overwrite
# the UI's index.html (seed-data is no-clobber).
#
# The result: GET / serves the official Restreamer dashboard, and
# /whep-player.html serves the standalone WHEP smoke player.
COPY --from=ui-builder /ui/build/ /core/static/
COPY --from=builder /src/deploy/truenas/core/static/ /core/static/
COPY --from=builder /src/deploy/truenas/core/seed-data.sh /core/bin/seed-data.sh
RUN chmod +x /core/bin/seed-data.sh && mkdir -p /core/config /core/data
ENV CORE_CONFIGFILE=/core/config/config.json
ENV CORE_STORAGE_DISK_DIR=/core/data
ENV CORE_DB_DIR=/core/config
VOLUME ["/core/data", "/core/config"]
EXPOSE 8080/tcp
# Seed /core/data on first boot, then exec the upstream run.sh which
# handles imports, ffmpeg migrations, and the core binary. tini reaps
# child PIDs and forwards signals.
ENTRYPOINT ["/sbin/tini", "--", "/bin/sh", "-c", "/core/bin/seed-data.sh && exec /core/bin/run.sh"]
WORKDIR /core