From c1158b6f7b5deb3cd0bc0c27460b4bb42ca8556d Mon Sep 17 00:00:00 2001 From: clover caruso Date: Sun, 22 Nov 2026 02:12:53 -0800 Subject: [PATCH] Serve Spacebar and its voice from phoenix-selfhosted and drop spacebar.* Move the API, gateway and CDN to phoenix-selfhosted.paperclover.net, serve voice from voice.phoenix-selfhosted, give /work a persistent volume instead of a memory-backed tmpfs, fetch the Pion pin through git, and run the Go build and SFU with a minimal environment. Assisted-by: claude-sonnet-5.5 --- service/spacebar/build/supervisor.mjs | 37 ++++++++++++++++++--------- service/spacebar/service.pkl | 5 ++-- service/spacebar/voice-network.json | 2 +- tools/phoenix-box.md | 2 +- tools/spacebar.md | 12 +++++---- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/service/spacebar/build/supervisor.mjs b/service/spacebar/build/supervisor.mjs index a23ad23da7341f835e0853763cb201449c6032ae..e013f7294188fd8c146494bb7e72ca02e8acf709 100644 --- a/service/spacebar/build/supervisor.mjs +++ b/service/spacebar/build/supervisor.mjs @@ -2,7 +2,7 @@ import { execFile, spawn } from "node:child_process"; import { createHash } from "node:crypto"; import { resolve4 } from "node:dns/promises"; import { once } from "node:events"; -import { copyFileSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, renameSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs"; +import { copyFileSync, createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs"; import { connect, createServer } from "node:net"; import { basename } from "node:path"; import { createInterface } from "node:readline"; @@ -165,20 +165,33 @@ async function prepareSfu(release) { if (pin.owner !== "spacebarchat" || pin.repo !== "pion-webrtc" || !/^[a-f0-9]{40}$/.test(pin.rev)) { throw new Error("invalid Snowcord Pion SFU pin"); } - const binary = `${WORK}/pion-sfu-${pin.rev}`; + const name = `pion-sfu-${pin.rev}`; + const binary = `${WORK}/${name}`; if (existsSync(binary)) return binary; - const scratch = mkdtempSync(`${WORK}/build-sfu-`); + const scratch = `${WORK}/sfu-build`; + const source = `${scratch}/source`; + rmSync(scratch, { recursive: true, force: true }); + mkdirSync(source, { recursive: true }); try { - const source = await fetch(`https://codeload.github.com/spacebarchat/pion-webrtc/tar.gz/${pin.rev}`, { signal: AbortSignal.timeout(60000) }); - if (!source.ok) throw new Error(`Pion SFU download failed with HTTP ${source.status}`); - writeFileSync(`${scratch}/source.tar.gz`, new Uint8Array(await source.arrayBuffer())); - await run("tar", ["-xzf", `${scratch}/source.tar.gz`, "-C", scratch]); - await run("/usr/local/go/bin/go", ["build", "-trimpath", "-o", `${scratch}/pion-sfu`, "."], { - cwd: `${scratch}/pion-webrtc-${pin.rev}/pion-sfu`, - env: { ...process.env, GOTOOLCHAIN: "local", CGO_ENABLED: "0" }, + // Fetching by full object id makes git verify the commit; go.sum pins every module. + await run("git", ["-C", source, "init", "--quiet"]); + await run("git", ["-C", source, "fetch", "--quiet", "--depth", "1", `https://github.com/${pin.owner}/${pin.repo}`, pin.rev]); + await run("git", ["-C", source, "-c", "advice.detachedHead=false", "checkout", "--quiet", "FETCH_HEAD"]); + await run("/usr/local/go/bin/go", ["build", "-trimpath", "-buildvcs=false", "-o", `${scratch}/pion-sfu`, "."], { + cwd: `${source}/pion-sfu`, + env: { + PATH: process.env.PATH, + HOME: scratch, + GOPATH: `${scratch}/go`, + GOCACHE: `${scratch}/cache`, + GOFLAGS: "-mod=readonly -modcacherw", + GOTOOLCHAIN: "local", + CGO_ENABLED: "0", + }, }); renameSync(`${scratch}/pion-sfu`, binary); + for (const entry of readdirSync(WORK)) if (entry.startsWith("pion-sfu-") && entry !== name) rmSync(`${WORK}/${entry}`, { force: true }); return binary; } finally { rmSync(scratch, { recursive: true, force: true }); @@ -203,10 +216,10 @@ async function startVoice(release) { if (stopping || live !== release) return; const [ip] = addresses; - const start = (command, args, env = process.env) => capture(spawn(command, args, { + const start = (command, args, env) => capture(spawn(command, args, { cwd: "/data", stdio: ["ignore", "pipe", "pipe"], env, })).on("error", (error) => log(`voice process: ${error.message}`)); - voice = { release, sfu: start(binary, ["-ip", ip, "-port", VOICE_MEDIA_PORT]), signaling: null }; + voice = { release, sfu: start(binary, ["-ip", ip, "-port", VOICE_MEDIA_PORT], {}), signaling: null }; await waitForVoice(voice.sfu, () => statSync("/tmp/sfu-ipc.sock", { throwIfNoEntry: false })?.isSocket()); if (stopping) return; diff --git a/service/spacebar/service.pkl b/service/spacebar/service.pkl index dbdf1e83e64797d6027af6c354da293691467b55..89f5d1fe05e302b8b6f2d0496aba40365a6de324 100644 --- a/service/spacebar/service.pkl +++ b/service/spacebar/service.pkl @@ -32,10 +32,9 @@ container { http { containerPort = 3001 - subdomain = "spacebar" + subdomain = "phoenix-selfhosted" checkPath = "/api/ping" forwardRealIp = true - plainHostnames { "phoenix-selfhosted.\(site.domain)" } } tcp { @@ -47,12 +46,12 @@ container { volumes { ["/data"] {} + ["/work"] {} // Shale keeps each repository under its UUID, which renaming and visibility changes leave alone. ["/source.git"] { src = "\(site.root)/prod/shale/repositories_owned/006AH3H3QKH2KN318QXRNFBH4B"; readOnly = true } // Production writes the server log into the sandbox workspace; previews keep their own. ["/logs"] { when (!site.preview) { src = "\(site.root)/work/snowcord-server/logs" } } } - tmpfs { "/work:rw,exec,size=3g" } env { ["BRANCH"] = "main" diff --git a/service/spacebar/voice-network.json b/service/spacebar/voice-network.json index 1ee97792773e1a6480c108f9a3977d9450ad78ea..95ed0ae18e1af6e48f759a83bb371798719c7a46 100644 --- a/service/spacebar/voice-network.json +++ b/service/spacebar/voice-network.json @@ -1,5 +1,5 @@ { - "subdomain": "spacebar-voice", + "subdomain": "voice.phoenix-selfhosted", "signaling": 17404, "media": 6000 } diff --git a/tools/phoenix-box.md b/tools/phoenix-box.md index 538b9e5f5e2f0cf3e429a1e741af3d51c4de769e..0e98508ce0b4549fecda7aab406fbceef79cff4e 100644 --- a/tools/phoenix-box.md +++ b/tools/phoenix-box.md @@ -17,7 +17,7 @@ on the tailnet. (any start clears it). Restarts log to `~/Library/Logs/m3-phoenix-box-revive.log`. After a host reboot nothing runs until Clover unlocks FileVault and logs in. - **Names:** the guest has no DNS (its gateway is blocked), so `/etc/hosts` maps - `spacebar.paperclover.net` to `100.64.0.1`. Go ignores `/etc/hosts` on macOS unless + `phoenix-selfhosted.paperclover.net` to `100.64.0.1`. Go ignores `/etc/hosts` on macOS unless `GODEBUG=netdns=go`, which `run-phoenix-spacebar` sets for the Caddy relay. - **Access:** Softnet also blocks host to guest, so there is no SSH or Screen Sharing. Tart's own VNC server (random password per run, printed to `run.log` in diff --git a/tools/spacebar.md b/tools/spacebar.md index 534a47efa4514344ba01f0f0fd4cee9e5959b107..4b77e89570d7af4d17cca466e2dc32a418a42966 100644 --- a/tools/spacebar.md +++ b/tools/spacebar.md @@ -1,6 +1,6 @@ # Spacebar -`https://spacebar.paperclover.net` runs Clover's fork of +`https://phoenix-selfhosted.paperclover.net` runs Clover's fork of [spacebarchat/server](https://github.com/spacebarchat/server) from branch `main` of the private Shale repository `https://shale.paperclover.net/snowcord-server.git`. Pushing to that branch is the deploy; `tools/deploy.py` is only needed to change the service definition. @@ -9,7 +9,7 @@ Pushing to that branch is the deploy; `tools/deploy.py` is only needed to change ~/dev/snowcord-server jj checkout, remotes: origin = Shale, upstream = GitHub (`master` mirrors upstream, `main` is what runs) jj bookmark set main -r @- && jj git push -b main -curl https://spacebar.paperclover.net/_spacebar/api/version # commit that is live +curl https://phoenix-selfhosted.paperclover.net/_spacebar/api/version # commit that is live ``` A push is live about 4 seconds later (3.4 to 4.6 s measured from the start of the push). Dependency changes @@ -19,7 +19,7 @@ supervisor against the same branch with a fresh database. ## How it works [`supervisor.mjs`](../service/spacebar/build/supervisor.mjs) is the container's -only process, on a stock Node image with its working files in tmpfs `/work`. +only process, on a stock Node image with its working files in the persistent `/work` volume. 1. Every 250 ms it reads the branch tip from the repository's Shale storage, mounted read-only at `/source.git`. Shale keeps a repository under its UUID, @@ -52,10 +52,12 @@ start that is still waiting. Rolling back is pushing the old commit again. ## Voice -The production service publishes the voice WebSocket at `spacebar-voice.paperclover.net:443`. +The production service publishes the voice WebSocket at `voice.phoenix-selfhosted.paperclover.net:443`. [`voice-network.json`](../service/spacebar/voice-network.json) configures the loopback WebSocket mapping and the UDP media port. The supervisor builds Pion -from the Snowcord revision's `flake.lock` and caches the binary for that pin. +from the Snowcord revision's `flake.lock`: git fetches the pinned commit, `go.sum` +pins the modules, and the build and SFU run with a minimal environment. The binary +is kept in `/work` for that pin, so a restart needs no network. It starts one SFU and one standalone voice process after the API is healthy. Each app release restarts voice, and an unavailable voice process retries while the API continues serving. Previews leave voice disabled. -- 2.54.1