authoravatarclover caruso<git@paperclover.net>2026-11-21 17:36:33-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 00:44:03-08:00
logc584c4d8a4cca56a74abd108b2f6595ac50fd5ec
treedcaa6114f35b6a0cdb7e12759c9c1324a1b58b13
parentb952d99332a054941ad27516c5e83e7222f66c85
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Spacebar: read the fork straight from Shale storage

The fork is now the private repository snowcord-server. Mount its Shale directory read-only and read the branch tip and tree with git instead of polling and fetching over HTTP, so no token is needed and a push is seen within 250 ms. Assisted-by: claude-sonnet-5.5

3 files changed, 29 insertions(+), 29 deletions(-)

service/spacebar/build/supervisor.mjs+17-21
......@@ -6,12 +6,13 @@ import { basename } from "node:path";
66import { setTimeout as sleep } from "node:timers/promises";
77import { promisify } from "node:util";
88
9const { SOURCE_URL, BRANCH, PORT } = process.env;
9const { BRANCH, PORT } = process.env;
1010const WORK = "/work";
11const REPO = `${WORK}/repo.git`;
12const POLL_MS = 500;
11const REPO = "/source.git";
12const POLL_MS = 250;
1313const DRAIN_MS = 500;
1414const RETRY_FAILED_MS = 15000;
15const GIT = ["-c", "safe.directory=*", "--git-dir", REPO];
1516
1617const out = promisify(execFile);
1718const log = (...args) => console.log("[deploy]", ...args);
......@@ -21,7 +22,7 @@ const run = (cmd, args, opts = {}, ok = [0]) =>
2122 .once("error", reject)
2223 .once("exit", (code) => (ok.includes(code) ? resolve() : reject(new Error(`${basename(cmd)} ${args[0]} exited with ${code}`)))),
2324 );
24const git = (...args) => out("git", ["--git-dir", REPO, ...args]).then((result) => result.stdout.trim());
25const git = (...args) => out("git", [...GIT, ...args]).then((result) => result.stdout.trim());
2526
2627let live = null;
2728let wanted = null;
......@@ -46,11 +47,11 @@ createServer((client) => {
4647 upstream.on("error", end).on("close", end);
4748}).listen(Number(PORT));
4849
49async function remoteHead() {
50 const response = await fetch(`${SOURCE_URL}/info/refs?service=git-upload-pack`, { signal: AbortSignal.timeout(5000) });
51 if (!response.ok) throw new Error(`${SOURCE_URL} answered ${response.status}`);
52 return (await response.text()).match(new RegExp(`([0-9a-f]{40}) refs/heads/${BRANCH}(?=\\0|\\n)`))?.[1] ?? null;
53}
50const branchTip = () =>
51 git("rev-parse", "--verify", "--quiet", `refs/heads/${BRANCH}`).catch((error) => {
52 if (error.code !== 1) throw error;
53 return null;
54 });
5455
5556async function install(dir, modules) {
5657 const staging = `${modules}.partial`;
......@@ -104,9 +105,9 @@ function retire(old) {
104105}
105106
106107async function deploy() {
107 const target = wanted;
108 const rev = wanted;
108109 const current = () => {
109 if (wanted !== target) throw new Error("superseded by a newer push");
110 if (wanted !== rev) throw new Error("superseded by a newer push");
110111 };
111112 let release;
112113 let last = performance.now();
......@@ -119,18 +120,14 @@ async function deploy() {
119120 };
120121
121122 try {
122 await run("git", ["--git-dir", REPO, "fetch", "--quiet", "--depth", "1", "--no-tags", SOURCE_URL, `refs/heads/${BRANCH}`]);
123 const rev = await git("rev-parse", "FETCH_HEAD");
124 if (rev === live?.rev) return;
125123 const [committedAt, subject] = (await git("log", "-1", "--format=%ct%n%s", rev)).split("\n");
126124 log(`deploying ${rev.slice(0, 7)} ${subject}`);
127 lap("fetch");
128125
129126 release = { rev, dir: `${WORK}/rel/${rev}`, modules: null, port: 0, proc: null, sockets: new Set() };
130127 releases.add(release);
131128 rmSync(release.dir, { recursive: true, force: true });
132129 mkdirSync(release.dir, { recursive: true });
133 await run("bash", ["-c", 'set -o pipefail; git --git-dir "$0" archive "$1" | tar -x -C "$2"', REPO, rev, release.dir]);
130 await run("bash", ["-c", 'set -o pipefail; git -c safe.directory="*" --git-dir "$0" archive "$1" | tar -x -C "$2"', REPO, rev, release.dir]);
134131 lap("extract");
135132
136133 const lock = createHash("sha256");
......@@ -175,8 +172,8 @@ async function deploy() {
175172 if (old) retire(old);
176173 log(`live ${rev.slice(0, 7)} in ${((performance.now() - start) / 1000).toFixed(1)}s: ${laps.join(", ")}`);
177174 } catch (error) {
178 log(`${target.slice(0, 7)} failed: ${error.message}`);
179 failed = { rev: target, at: Date.now() };
175 log(`${rev.slice(0, 7)} failed: ${error.message}`);
176 failed = { rev, at: Date.now() };
180177 if (release) releases.delete(release);
181178 sweep();
182179 }
......@@ -184,15 +181,14 @@ async function deploy() {
184181
185182mkdirSync(`${WORK}/rel`, { recursive: true });
186183mkdirSync(`${WORK}/modules`, { recursive: true });
187await run("git", ["init", "--quiet", "--bare", REPO]);
188184process.on("SIGTERM", () => process.exit(0));
189185
190186(async () => {
191187 let problem = "";
192188 for (;; await sleep(POLL_MS)) {
193189 try {
194 const head = await remoteHead();
195 if (!head) throw new Error(`${SOURCE_URL} has no branch ${BRANCH}`);
190 const head = await branchTip();
191 if (!head) throw new Error(`${REPO} has no branch ${BRANCH}`);
196192 wanted = head;
197193 problem = "";
198194 } catch (error) {
service/spacebar/service.pkl+3-2
......@@ -1,5 +1,6 @@
11amends "../../config/Service.pkl"
22
3import "../../config/site.pkl" as site
34import "../postgres/service.pkl" as postgres
45
56local host = module.container.http.hostname
......@@ -24,7 +25,6 @@ container {
2425 build = "build"
2526 cpu = 1000
2627 memory = 3072
27 extraHosts { "shale.paperclover.net:host-gateway" }
2828
2929 http {
3030 containerPort = 3001
......@@ -35,11 +35,12 @@ container {
3535
3636 volumes {
3737 ["/data"] {}
38 // Shale keeps each repository under its UUID, which renaming and visibility changes leave alone.
39 ["/source.git"] { src = "\(site.root)/prod/shale/repositories_owned/006AH3H3QKH2KN318QXRNFBH4B"; readOnly = true }
3840 }
3941 tmpfs { "/work:rw,exec,size=3g" }
4042
4143 env {
42 ["SOURCE_URL"] = "https://shale.paperclover.net/discord-server.git"
4344 ["BRANCH"] = "main"
4445 ["HOME"] = "/work"
4546 ["CONFIG_PATH"] = "/spacebar/config.json"
tools/spacebar.md+9-6
......@@ -2,17 +2,17 @@
22
33`https://spacebar.paperclover.net` runs Clover's fork of
44[spacebarchat/server](https://github.com/spacebarchat/server) from branch `main` of
5`https://shale.paperclover.net/discord-server.git`. Pushing to that branch is the
6deploy; `tools/deploy.py` is only needed to change the service definition.
5the private Shale repository `https://shale.paperclover.net/snowcord-server.git`.
6Pushing to that branch is the deploy; `tools/deploy.py` is only needed to change the service definition.
77
88```
9~/dev/discord-server jj checkout, remotes: origin = Shale, upstream = GitHub
9~/dev/snowcord-server jj checkout, remotes: origin = Shale, upstream = GitHub
1010 (`master` mirrors upstream, `main` is what runs)
1111jj bookmark set main -r @- && jj git push -b main
1212curl https://spacebar.paperclover.net/_spacebar/api/version # commit that is live
1313```
1414
15A push is live about 4 seconds later (3.5 to 4.6 s measured from the start of the push). Dependency changes
15A push is live about 4 seconds later (3.4 to 4.6 s measured from the start of the push). Dependency changes
1616(`package.json` or the lockfile) add an `npm ci`, about 5 s. Previews run the same
1717supervisor against the same branch with a fresh database.
1818
......@@ -21,8 +21,11 @@ supervisor against the same branch with a fresh database.
2121[`supervisor.mjs`](../service/spacebar/build/supervisor.mjs) is the container's
2222only process, on a stock Node image with its working files in tmpfs `/work`.
2323
241. Every 500 ms it reads the branch tip from Shale's `info/refs`.
252. On a new tip it shallow-fetches, extracts the tree, installs `node_modules`
241. Every 250 ms it reads the branch tip from the repository's Shale storage,
25 mounted read-only at `/source.git`. Shale keeps a repository under its UUID,
26 so renaming it or changing its visibility does not affect the mount; a
27 recreated repository needs the new UUID in `service.pkl`.
282. On a new tip it extracts the tree with `git archive`, installs `node_modules`
2629 only when the dependency files changed, and builds with the repo's own
2730 `node_modules/.bin/tsc` (TypeScript 7, about 1 s).
28313. It starts the new server on a free port, waits for `/api/ping`, then points its