0097. Self-hosting: one setup script, its data, the AI choice and a demo player
Source:
docs/decisions/0097-self-hosting-setup-and-demo-data.md. Generated at build time; edit the source file.
Date: 2026-11-23. Status: accepted (lane selfhost, the owner’s open-source launch plan, Lane L4).
Context
Section titled “Context”Once the repository is public, strangers must be able to run the whole project, data included.
A fresh clone that followed the old CONTRIBUTING.md on Windows 11 (Git Bash, Docker Desktop
29.1, Compose 5.0) hit these snags:
nvm usefails under nvm-windows, which does not read.nvmrc.cp .env.example .envpublishes fixed host ports, and a second stack fails withBind for 127.0.0.1:48025 failed: port is already allocated.- A plain
docker compose up -d --buildstarts every service, includingrust-devand the old TypeScriptworker. - On a Docker host without the shared Rust caches, that
upstops withexternal volume "ci-cargo-registry" not found: the cache script came after it (reproduced in a scratch project, because the dry-run host already had the volumes). - The sign-in page says “Check your email”, but no mail reaches Mailpit: sign-up is invite-only
and
INVITE_ALLOWLISTis empty. - Nothing mentions the Syzygy tables, the Lichess reference or Maia, and every page stays empty until a real chess.com account is imported and analysed.
The first full-mode run of the new script found two more: lichess-db syzygy --dest /data/syzygy
wrote to C:/Program Files/Git/data/syzygy inside the container, because Git Bash rewrote the
argument, and the 2013-01 month cannot build a band reference (below).
Decision
Section titled “Decision”scripts/setup.sh [minimal|full|configure|doctor|data|ai|ai-start|ai-stop|ai-status], POSIX sh (Git Bash, macOS, Linux), idempotent, neversudo: it says what to install.--yes(or no terminal) takes the defaults, for CI..envis merged from.env.example: missing keys are appended, no existing line changes. Local defaults are set only where empty:ALLOW_UNVERIFIED_LINKS=1, the user’s email inINVITE_ALLOWLIST(--email, the prompt, orplayer@rematch.testwhen neither), a random 64-hexBETTER_AUTH_SECRET,COMPOSE_PATH_SEPARATOR=:, andCOMPOSE_FILEwith the ports file plus the Maia and local-Claude overlays as chosen (each added once). Values travel toawkthrough the environment, never argv.- Ports are configurable (
WEB_PORT,MAILPIT_PORT,POSTGRES_PORT,REDIS_PORT, or--no-ports); the web’sBETTER_AUTH_URLfollowsWEB_PORT, so sign-in links do. The e2e overlay pins it to 3100, where the qa browser reaches web. - Checks: Docker 24+, Compose 2.24+ (the local-Claude overlay uses
!override), Docker memory (12 GiB recommended, a warning only), free disk per mode, Node 22 and pnpm 12 (needed only on the host for--ai=local), and free ports.doctorre-checks everything, the services, the worker’sai:line and the data, and explains each failure. - Start:
rust-cache-init.shfirst, thenup -d --build --waitof the services the app needs only (postgres, redis, mailpit, web, rust-worker, and ai-sidecar unless local), then a wait for the worker’s migrations.
- Data. A Compose
dataservice (profiledata) runs the worker image’slichess-dbwithdata/writable.- Syzygy 3-4-5 (290 files, 984 MB, 101 s on the dry run):
lichess-db syzygy, each file verified against the pinnedsyzygy-345.sha256and resumable per file (ADR-R2-22).dc()setsMSYS_NO_PATHCONV=1for Docker only and passes the checkout aspwd -W; thedataservice runs as the host user on Linux. - A Lichess month:
lichess-db build, streamed and verified against Lichess’ssha256sums.txt(ADR-R2-9). The binary already samples (--max-games,--expected-games), so no Rust change was needed. The default month is 2013-01 (18 MB, 121,332 games), kept whole: it built the opening explorer in about 40 s on the dry run (59,585 rows). It cannot build the band reference: the reference filter requires[%clk]comments, which Lichess dumps carry from 2017-04 on, and the dry run failed withno reference player qualified in any cell. So the script adds--band-referenceonly for a month from 2017-04 on (2017-04 is 3.5 GB and 11.3M games; 2026-10 is 31 GB and 95.4M games) and says so otherwise. It prints the size and game count (fromcounts.txt) first and skips a kind that is already built for that month. A stream cannot resume mid-file; a stopped build starts the month again. - Maia is opt-in in full mode (
--maia): the overlay and its image (the weights are downloaded and SHA-256-checked bymaia2at build time). - Minimal mode downloads none of these; the app works without them (no tablebase probe, “Not compared yet”, difficulty pending).
- Syzygy 3-4-5 (290 files, 984 MB, 101 s on the dry run):
- The AI choice (menu, or
--ai=local|key|none):local: requiresclaude auth statusto reportloggedIn, else explains/login; adds the local-Claude overlay; startspnpm --filter @ci/ai-sidecar start:localin the background with a pidfile (.cache/ai-sidecar.pid, log beside it) and waits for/healthto reportauth: "local". One line says it is for the user’s own local use only (ADR 0062 Amendment 2). On Git Bashai-stopends the native process tree withtaskkill /T.key: read withstty -echo(or from$ANTHROPIC_API_KEY, or stdin), checked with a models-list call (no tokens), the key handed to curl in a private header file, written only to.env, never printed. A rejected key writes nothing.none: computed reports only; clears a stored key.setup.sh aiswitches later.
- A demo player,
pnpm seed:demo(scripts/seed-demo.shruns it in the web container, so it needs no host port or host Node). It writes a fictional player’s analysed games, profile, example report, weekly review, strengths and trainer positions, built from the synthetic worlds of the e2e seeds and their test writers (public fixture games with fictional names). It is recognised by its usernamedemo.player: neither chess.com nor Lichess allows a dot, so no real account can collide. It touches only its own rows (the dev database may hold real accounts), re-seeds idempotently (fixed ids, dates moved by whole weeks so the newest game is from the last seven days), and--removedeletes it (the user’s login stays). It refuses production and any non-local database host (assertLocal).- The header shows a small “Demo data” label (
bg-well,text-ink-soft, tokens only). - Neither the web’s “Sync now” nor the worker’s recurring sync (
DEMO_USERNAME_PREFIXinanalysis::jobs::sync) ever asks a platform for it.
- The header shows a small “Demo data” label (
- CI proof.
.github/workflows/self-host.yml(weekly and manual, read-only, actions pinned by SHA) runssetup.sh minimal --yes --ai=none,seed:demotwice,doctor, and a Playwright smoke (playwright.selfhost.config.ts, in the qa container withdocker-compose.smoke.yml): sign in through Mailpit, the overview with the demo label, the trainer, the report. The shell tests (scripts/test-setup.sh, no Docker) also run in the CItsjob. Full mode is too heavy for CI and is tested by hand.
Consequences
Section titled “Consequences”- One command from clone to a signed-in app with content; the docs (CONTRIBUTING, Getting started) describe minimal and full, the data table, the AI options and the snags.
- A new
.env.examplekey reaches existing checkouts on the nextsetup.shrun. - The demo’s dates move with the calendar; its screenshots are not baselines.
- Re-seeding resets the demo’s trainer progress (it is demo data).