deploy: ship a Dragon Fork landing page at / (fixes root 404)
Some checks failed
ci / vet + build (push) Successful in 9m49s
ci / race tests (push) Failing after 8m1s
ci / WebRTC smoke (5-viewer fanout) (push) Successful in 9m46s
ci / WebRTC latency p95 gate (push) Successful in 10m5s

A clean post-merge deploy showed an unintended UX wart: hitting
http://<host>:<port>/ in a browser returned 404 'File not found'
because Core's static-disk handler serves /core/data and we never
put anything there. Functionally fine — the API and Swagger are
reachable on /api and /api/swagger — but a confusing first
impression for a brand-new operator.

Fix is deploy-side, not code-side: ship a small landing page +
the existing test/whep-player.html as default content for the data
volume.

Pieces:
  deploy/truenas/core/static/
    index.html         — Dragon Fork-branded landing page; links
                         to Swagger and the WHEP player; live
                         /api status panel.
    whep-player.html   — same self-contained Pion subscriber that
                         lives at test/whep-player.html.
  deploy/truenas/core/seed-data.sh
    First-boot script. Copies /core/static/* into /core/data/
    only when the destination filename doesn't already exist —
    operator-supplied content is never clobbered, so this is a
    safe addition that respects upstream's contract that
    /core/data is operator-owned.
  deploy/truenas/core/Dockerfile
    COPYs the static dir and seed script into the runtime image,
    wraps the entrypoint as 'seed-data.sh && exec run.sh' (run.sh
    itself is unchanged from upstream).

Image size impact: ~15KB.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Zac Gaetano 2026-05-03 12:44:04 +00:00
parent 7df7ad2f6e
commit 45f39a9132
4 changed files with 467 additions and 2 deletions

View file

@ -47,7 +47,13 @@ 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
RUN mkdir -p /core/config /core/data
# Dragon Fork landing page + browser WHEP player. Seeded into
# /core/data on first boot by /core/bin/seed-data.sh below; the seed
# is a no-op when the operator has already put content in /core/data.
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
@ -56,5 +62,8 @@ ENV CORE_DB_DIR=/core/config
VOLUME ["/core/data", "/core/config"]
EXPOSE 8080/tcp
ENTRYPOINT ["/sbin/tini", "--", "/core/bin/run.sh"]
# 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

View file

@ -0,0 +1,33 @@
#!/bin/sh
# seed-data.sh — first-boot seed of /core/data with Dragon Fork
# landing page artifacts (index.html, whep-player.html).
#
# Runs from the entrypoint before bin/core. Skips itself if any of the
# target files already exist, so user-supplied content (or content from
# a previous deploy that they edited) is never clobbered.
#
# Source dir: /core/static (baked by the Dockerfile)
# Target dir: /core/data (operator-mounted; what Core serves at /)
set -e
SRC=/core/static
DST="${CORE_STORAGE_DISK_DIR:-/core/data}"
if [ ! -d "$SRC" ]; then
# No static dir baked — nothing to seed. Fall through silently.
exit 0
fi
if [ ! -d "$DST" ]; then
mkdir -p "$DST"
fi
for f in "$SRC"/*; do
[ -e "$f" ] || continue
name=$(basename "$f")
if [ ! -e "$DST/$name" ]; then
cp -p "$f" "$DST/$name"
echo "seed-data: copied $name -> $DST/$name"
fi
done

View file

@ -0,0 +1,69 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Datarhei — Dragon Fork</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root { color-scheme: dark; --fg:#e7e7ea; --bg:#0d0e12; --accent:#ff6633; --muted:#8b8e98; --panel:#1a1c22; }
* { box-sizing: border-box; }
body { margin:0; font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif; background:var(--bg); color:var(--fg); min-height:100vh; }
header { padding:1.5rem 2rem; border-bottom:1px solid #232530; }
header h1 { margin:0; font-size:1.2rem; letter-spacing:0.02em; }
header h1 .accent { color:var(--accent); }
header .subtitle { color:var(--muted); font-size:0.85rem; margin-top:0.3rem; }
main { max-width:840px; margin:0 auto; padding:2rem; }
h2 { font-size:1.05rem; margin-top:2rem; color:var(--muted); text-transform:uppercase; letter-spacing:0.06em; }
.card { background:var(--panel); border-radius:10px; padding:1.25rem 1.5rem; margin-bottom:1rem; }
.card a { color:var(--accent); text-decoration:none; font-weight:600; }
.card a:hover { text-decoration:underline; }
.card p { color:var(--muted); margin:0.4rem 0 0; font-size:0.9rem; }
code { background:#0d0e12; padding:0.1rem 0.4rem; border-radius:4px; font:0.85em ui-monospace,Menlo,Consolas,monospace; }
footer { padding:2rem; text-align:center; color:var(--muted); font-size:0.8rem; }
</style>
</head>
<body>
<header>
<h1>Datarhei <span class="accent">Dragon Fork</span></h1>
<div class="subtitle">a fork of <a href="https://github.com/datarhei/core" style="color:var(--muted)">datarhei/core</a> with native WebRTC (WHEP) egress</div>
</header>
<main>
<h2>Quick links</h2>
<div class="card">
<a href="/api/swagger/index.html">API documentation (Swagger UI)</a>
<p>Full HTTP API including <code>/api/v3/process</code>, <code>/api/v3/whep/{id}</code>, RTMP / SRT / config / metrics. Most endpoints require a JWT — issue one via <code>POST /api/login</code>.</p>
</div>
<div class="card">
<a href="/whep-player.html">Browser WHEP player</a>
<p>Self-contained subscriber for any process whose <code>config.webrtc.enabled = true</code>. Paste the WHEP URL and a JWT; press Subscribe.</p>
</div>
<h2>About this build</h2>
<div class="card" id="about">Loading…</div>
<h2>How to add a WebRTC stream</h2>
<div class="card">
<p style="color:var(--fg)">Create a process with <code>"webrtc": { "enabled": true }</code>. Once it starts, <code>POST /api/v3/whep/&lt;process-id&gt;</code> takes an SDP offer and returns an SDP answer.</p>
</div>
</main>
<footer>Datarhei — Dragon Fork &middot; Apache License 2.0 &middot; Built on datarhei Core + Pion WebRTC</footer>
<script>
fetch('/api')
.then(r => r.json())
.then(d => {
const el = document.getElementById('about');
const v = d.version || {};
el.innerHTML = '<p style="color:var(--fg)">' +
'<strong>' + (d.fork || d.app) + '</strong> &middot; ' +
'instance <code>' + (d.name || '?') + '</code> &middot; ' +
'version <code>' + (v.number || '?') + '</code> &middot; ' +
'commit <code>' + ((v.repository_commit || '?').slice(0,8)) + '</code>' +
'</p>';
})
.catch(() => {
document.getElementById('about').innerHTML =
'<p>Status panel needs an authenticated request. Visit <a href="/api/swagger/index.html">Swagger</a> to log in.</p>';
});
</script>
</body>
</html>

View file

@ -0,0 +1,354 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dragon Fork — WHEP Player</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
color-scheme: light dark;
--fg: #e7e7ea;
--bg: #0d0e12;
--accent: #ff6633;
--muted: #8b8e98;
--good: #5dd29c;
--warn: #ffb45e;
--bad: #ff6470;
--panel: #1a1c22;
}
* { box-sizing: border-box; }
body {
margin: 0;
font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
padding: 1.25rem 1.5rem;
border-bottom: 1px solid #232530;
display: flex;
align-items: baseline;
gap: 0.75rem;
}
header h1 {
margin: 0;
font-size: 1.05rem;
letter-spacing: 0.02em;
}
header h1 .accent { color: var(--accent); }
header .subtitle { color: var(--muted); font-size: 0.85rem; }
main {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
padding: 1.5rem;
max-width: 1200px;
width: 100%;
margin: 0 auto;
flex: 1;
}
@media (min-width: 900px) {
main {
grid-template-columns: 360px 1fr;
align-items: start;
}
}
.panel {
background: var(--panel);
border-radius: 10px;
padding: 1.25rem;
}
label {
display: block;
margin-top: 0.75rem;
color: var(--muted);
font-size: 0.78rem;
text-transform: uppercase;
letter-spacing: 0.06em;
}
input[type=text] {
width: 100%;
padding: 0.55rem 0.7rem;
margin-top: 0.25rem;
background: #0d0e12;
border: 1px solid #2a2c36;
border-radius: 6px;
color: var(--fg);
font: inherit;
}
input[type=text]:focus { border-color: var(--accent); outline: none; }
.actions {
display: flex;
gap: 0.5rem;
margin-top: 1.25rem;
}
button {
flex: 1;
padding: 0.7rem 1rem;
border: none;
border-radius: 6px;
background: var(--accent);
color: #000;
font-weight: 600;
cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: #2a2c36; color: var(--fg); }
video {
width: 100%;
background: #000;
border-radius: 10px;
aspect-ratio: 16 / 9;
}
.stats {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.4rem 1rem;
margin-top: 1rem;
font-size: 0.85rem;
}
.stats .label { color: var(--muted); }
.stats .value { font-variant-numeric: tabular-nums; }
.pill {
display: inline-block;
padding: 0.1rem 0.55rem;
border-radius: 999px;
font-size: 0.75rem;
background: #2a2c36;
}
.pill.good { background: rgba(93,210,156,0.18); color: var(--good); }
.pill.warn { background: rgba(255,180,94,0.18); color: var(--warn); }
.pill.bad { background: rgba(255,100,112,0.20); color: var(--bad); }
.log {
margin-top: 1rem;
max-height: 220px;
overflow-y: auto;
background: #0d0e12;
padding: 0.6rem 0.8rem;
border-radius: 6px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.78rem;
line-height: 1.4;
white-space: pre-wrap;
word-break: break-word;
}
.log .ts { color: var(--muted); }
</style>
</head>
<body>
<header>
<h1>Dragon Fork <span class="accent">WHEP</span></h1>
<span class="subtitle">manual smoke test for the WebRTC egress path</span>
</header>
<main>
<section class="panel">
<label for="whep-url">WHEP endpoint</label>
<input id="whep-url" type="text" placeholder="http://10.0.0.25:8090/api/v3/whep/myStream"
value="">
<label for="bearer">JWT bearer token</label>
<input id="bearer" type="text" placeholder="eyJhbGciOi…">
<div class="actions">
<button id="btn-play">Subscribe</button>
<button id="btn-stop" class="secondary" disabled>Disconnect</button>
</div>
<div class="stats">
<span class="label">ICE</span> <span id="stat-ice" class="value pill">idle</span>
<span class="label">Connection</span> <span id="stat-conn" class="value pill">idle</span>
<span class="label">Resource</span> <span id="stat-res" class="value"></span>
<span class="label">Video codec</span> <span id="stat-vcodec" class="value"></span>
<span class="label">Audio codec</span> <span id="stat-acodec" class="value"></span>
<span class="label">Inbound bitrate</span><span id="stat-bitrate" class="value"></span>
</div>
<div id="log" class="log" aria-live="polite"></div>
</section>
<section class="panel" style="padding:0;background:#000;">
<video id="video" controls autoplay playsinline muted></video>
</section>
</main>
<script>
// --- tiny state -------------------------------------------------
const $ = (id) => document.getElementById(id);
const log = (line, level='info') => {
const ts = new Date().toLocaleTimeString();
const div = document.createElement('div');
div.innerHTML = `<span class="ts">${ts}</span> <span class="lvl-${level}">${line}</span>`;
$('log').prepend(div);
};
const setPill = (el, text, klass) => { el.textContent = text; el.className = 'value pill ' + klass; };
let pc = null;
let resourceURL = null; // absolute or path; whichever the server returned
let bitrateTimer = null;
// --- subscribe / disconnect -------------------------------------
$('btn-play').addEventListener('click', subscribe);
$('btn-stop').addEventListener('click', disconnect);
// Pre-populate WHEP endpoint from query string for shareable URLs
// (e.g. file:///.../whep-player.html?url=http://.../whep/foo&token=…).
(function bootstrap() {
const q = new URLSearchParams(location.search);
if (q.get('url')) $('whep-url').value = q.get('url');
if (q.get('token')) $('bearer').value = q.get('token');
})();
async function subscribe() {
if (pc) { log('already connected; disconnect first', 'warn'); return; }
const url = $('whep-url').value.trim();
const token = $('bearer').value.trim();
if (!url) { log('WHEP URL is required', 'bad'); return; }
$('btn-play').disabled = true;
$('btn-stop').disabled = false;
setPill($('stat-ice'), 'gathering', 'warn');
setPill($('stat-conn'), 'connecting', 'warn');
pc = new RTCPeerConnection({
// No ICE servers: production deploy advertises NAT1To1 host
// candidates, which work over the LAN. Add stun:/turn: here
// if you're testing across NAT.
iceServers: [],
});
pc.ontrack = (evt) => {
log(`ontrack: kind=${evt.track.kind}`, 'info');
// Both tracks share the same MediaStream; attach once.
if ($('video').srcObject !== evt.streams[0]) {
$('video').srcObject = evt.streams[0];
}
};
pc.oniceconnectionstatechange = () => {
const s = pc.iceConnectionState;
let klass = 'warn';
if (s === 'connected' || s === 'completed') klass = 'good';
else if (s === 'failed' || s === 'disconnected' || s === 'closed') klass = 'bad';
setPill($('stat-ice'), s, klass);
log(`ICE state: ${s}`);
};
pc.onconnectionstatechange = () => {
const s = pc.connectionState;
let klass = 'warn';
if (s === 'connected') klass = 'good';
else if (s === 'failed' || s === 'disconnected' || s === 'closed') klass = 'bad';
setPill($('stat-conn'), s, klass);
log(`PC state: ${s}`);
};
pc.addTransceiver('video', { direction: 'recvonly' });
pc.addTransceiver('audio', { direction: 'recvonly' });
try {
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
// Wait for ICE gathering to complete so the offer is non-trickle.
await new Promise((res) => {
if (pc.iceGatheringState === 'complete') return res();
pc.addEventListener('icegatheringstatechange', () => {
if (pc.iceGatheringState === 'complete') res();
});
});
const headers = { 'Content-Type': 'application/sdp' };
if (token) headers['Authorization'] = 'Bearer ' + token;
const resp = await fetch(url, {
method: 'POST',
headers,
body: pc.localDescription.sdp,
});
if (!resp.ok) {
const body = await resp.text();
throw new Error(`WHEP POST ${resp.status}: ${body || resp.statusText}`);
}
// Per WHEP spec: server returns SDP answer; Location is the resource.
const loc = resp.headers.get('Location');
if (loc) {
// Resolve relative Location against the WHEP URL.
try { resourceURL = new URL(loc, url).toString(); }
catch { resourceURL = loc; }
$('stat-res').textContent = resourceURL;
}
const answer = await resp.text();
await pc.setRemoteDescription({ type: 'answer', sdp: answer });
log(`subscribed (${resp.status})`, 'good');
// Pull codec info out of the SDP for a quick UI hint.
const codec = (kind, sdp) => {
const m = new RegExp(`m=${kind}[^\r\n]*[\r\n](?:[abc][^\r\n]*[\r\n]){0,30}?a=rtpmap:\\d+ ([^/\r\n]+)`).exec(sdp);
return m ? m[1] : '?';
};
$('stat-vcodec').textContent = codec('video', answer);
$('stat-acodec').textContent = codec('audio', answer);
bitrateTimer = setInterval(updateBitrate, 1000);
} catch (err) {
log(`error: ${err.message}`, 'bad');
await disconnect();
}
}
async function disconnect() {
if (bitrateTimer) { clearInterval(bitrateTimer); bitrateTimer = null; }
$('btn-play').disabled = false;
$('btn-stop').disabled = true;
// WHEP: best-effort DELETE on the resource URL the server gave us.
if (resourceURL) {
try {
const headers = {};
const token = $('bearer').value.trim();
if (token) headers['Authorization'] = 'Bearer ' + token;
const r = await fetch(resourceURL, { method: 'DELETE', headers });
log(`DELETE ${r.status}`, r.ok ? 'good' : 'warn');
} catch (e) {
log(`DELETE failed: ${e.message}`, 'warn');
}
resourceURL = null;
}
if (pc) { pc.close(); pc = null; }
$('video').srcObject = null;
setPill($('stat-ice'), 'idle', '');
setPill($('stat-conn'), 'idle', '');
$('stat-res').textContent = '—';
$('stat-vcodec').textContent = '—';
$('stat-acodec').textContent = '—';
$('stat-bitrate').textContent = '—';
}
// --- bitrate sampling -------------------------------------------
let lastBytes = null;
let lastTs = null;
async function updateBitrate() {
if (!pc || pc.connectionState !== 'connected') return;
const stats = await pc.getStats();
let bytes = 0;
stats.forEach((r) => {
if (r.type === 'inbound-rtp' && !r.isRemote) bytes += r.bytesReceived || 0;
});
const now = performance.now();
if (lastBytes !== null) {
const kbps = ((bytes - lastBytes) * 8) / ((now - lastTs) || 1);
$('stat-bitrate').textContent = kbps.toFixed(0) + ' kbps';
}
lastBytes = bytes;
lastTs = now;
}
</script>
</body>
</html>