Public: anyone can read this; the crew can change it.

Infrastructure: run any container image on a machine, from image to a working address #17630

opened this in answer to

Merged 19h 54m ago, live in production

scout/forge:scout/17625-infrastructure-run-any-container-image-o → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/17625-infrastructure-run-any-container-image-o was merged into main as 7401c73.

Review

Sign in to review this change.
3 files changed +100 −0
docs/REFERENCE.md +1
@@ -602,6 +602,7 @@ This page is the front door. Everything else is a file of its own under
602602 - [`docs/MAIL-RELAY.md`](MAIL-RELAY.md) — design: an inherited mail sending key that never leaves its holder (#15872).
603603 - [`docs/CLOUD.md`](CLOUD.md) — clouds are capacity, never dependency, and the cloud accounts an admin keeps.
604604 - [`docs/CLUSTER.md`](CLUSTER.md) — the check lane as Kubernetes Jobs.
605 - [`docs/SERVICES.md`](SERVICES.md) — design: any container image as a service on a machine, from image to an https address, generalising the game box.
605606 - [`docs/EXTRACT.md`](EXTRACT.md) — the forge on a machine of its own, and the platform it grew up in switched off: what a host owes it, the moves in order, and what is given up.
606607 - [`docs/PLATFORM.md`](PLATFORM.md) — everything the forge still takes from open-platform, what replaces each, what is done, and the issue for the next step; the order and the gate for switching the platform off.
607608 - [`docs/ops/ROLL.md`](ops/ROLL.md) — rolling a release.
docs/SERVICES.md added +98
@@ -0,0 +1,98 @@
1 # Services: run any container image on a machine (design, #17625)
2
3 Part of the cloud mission (#17532). A **service** is one container image, configured, running on a machine
4 of the owner's, at an https address. This is a design: nothing here is built yet. It generalises the game
5 box (`docs/features/game-box.md`); it does not add a second agent, a second plan or a second machine path.
6
7 ## 1. What of the game box is general, and what is Minecraft's
8
9 | General (becomes the service) | Minecraft's (stays in `src/games/`) |
10 | --- | --- |
11 | `agent.sh`: sync every 5 s, writes `compose.yml` and `.env`, `docker compose up`, queued jobs, logs, diag, self-update by sha | rcon, `rcon-cli`, `RCON_<SERVICE>` env keys |
12 | The machine: `planWants`, drivers, volume mount, hardening, DNS record, retire, ceiling, cost in the plan tray | Ports 25565/tcp and 19132/udp, swap for JVMs, `boot.ts` constants |
13 | The token (`fgb_`, hash only), diag, the owner-only console | Mods, Modrinth, packs, worlds, presets, `sleep`, `lend`, `metrics` |
14 | `compose.ts`: the compose file read from a repository branch HEAD, edited by commits | `FORWARDING_SECRET`, Geyser, the SRV record |
15 | Snapshots (`snapshots.ts`) of a volume, listed by the agent | "World" as the unit of a snapshot |
16
17 The cut: rename nothing yet. A `game_box` row gains `kind` (`game` today, `service`), and the game-only
18 modules keep checking `kind === "game"`. The agent learns three general things it lacks (below); every
19 Minecraft verb stays behind the game's kind. `/services` and a Services terminal screen are the doors, over
20 one action (`src/actions/services.ts`) that the MCP `services` tool also calls.
21
22 ## 2. The image: built, and pinned by digest
23
24 - **A repository with a Dockerfile:** the box builds it (`docker build`) from the commit the plan names, never
25 from a branch name. A `docker compose` file is generated from the service's settings (below) and committed to
26 the repository by the same path a game's is, so a change is a pull the crew can propose.
27 - **An image:** the plan resolves the tag to a digest (`registry /v2/<name>/manifests/<tag>`, one read) and the
28 compose file holds `image: name@sha256:…`. A tag is only ever what the owner typed; what runs is the digest.
29 A new digest is a new deploy and shows in the plan as "was `abc123`, now `def456`".
30 - A registry host is an outside call: it goes in `forge.json` `egress` when built.
31
32 ## 3. Secrets
33
34 Variables are plain in the compose file. Secrets are sealed at the service's scope (`GAME_<NAME>_…` pattern,
35 `secretKey`), never in the repository. The sync answer carries them once, into the agent's `.env` (mode 600),
36 as the game's forwarding secret is today. The compose file refers to `${NAME:?}`, so a missing one fails the
37 deploy before anything starts. Never in logs: the agent redacts every secret value from the log lines it posts.
38
39 ## 4. https and domains
40
41 The box runs Caddy as a second compose service it owns (not the owner's): it gets a certificate for the
42 service's host by itself and proxies to the service's one named port. Only 80/443 open (the game box opens
43 25565); the cloud firewall the forge already makes for forges fits. DNS is the game's A record in a Cloudflare
44 zone a connected token can write; with none, the plan says to set it by hand and the https check waits.
45 No host given: the plan refuses; the forge does not invent a domain.
46
47 ## 5. Deploy, health, rollback
48
49 1. The plan shows each step and its monthly cost against the ceiling (as every `planWants` plan).
50 2. The agent pulls the new digest and starts it beside the old one (`docker compose up -d` with the
51 health check as `healthcheck:` from the settings: path, expected status, interval).
52 3. **A bad deploy is stopped:** a service that is not `healthy` within the settings' deadline (default 120 s)
53 is not switched to; the proxy keeps the old container, the agent reports `failed: unhealthy`, and
54 `/services/<name>` says so first.
55 4. **Rollback is one action:** the previous digest and compose sha are kept (the last 5); "Roll back" queues a
56 deploy of them, through the same health gate.
57 5. Logs: the agent already streams new log lines per service; the page and terminal read them.
58
59 ## 6. Backup, and a restore that was tried
60
61 The volume's snapshots exist for worlds; the general form is "the volume's directory, tarred while the service is
62 stopped or quiesced, kept off the machine". A restore is only counted when it was **drilled**: the agent restores
63 the newest snapshot into a scratch directory, starts nothing, and checks the tar lists and its size matches;
64 the verdict is kept like `restore-drill` (`docs/RECOVERY.md`) and the page says "Last restore tried: <when>, ok"
65 or "never tried". The first slice is not done until one real service has a restore that was tried.
66
67 ## 7. Isolation between two clients on one machine
68
69 The default is **one machine per client**: the cost is the machine's price, said in the plan. Two services of
70 one owner share a machine: separate compose projects, separate Docker networks, no host network, no
71 `privileged`, no Docker socket, `mem_limit`/`cpus` per service from the settings, a volume directory each.

Next: two clients on one machine are refused here, but nothing names where that refusal lives. Put it in step 2's plan check, with a test, so it is enforced and not only written down.

72 Two *clients* on one machine is refused until user namespaces and per-project limits are proved on a real
73 box; the plan says "one machine each" rather than allowing it quietly.
74
75 ## 8. When the machine dies
76
77 State is on the volume, the compose file is in the repository, and the token is remade on a replace. So a
78 replace (`planWants`, existing path) brings a new machine that pulls the same digest and mounts the same
79 volume. What is lost: writes since the last backup if the volume dies with it. The page says which of the two
80 happened, from the cloud's own state, and offers "Replace" or "Restore into a new machine".
81
82 ## 9. Cost against what it replaces
83
84 The plan shows the machine, the volume and the DNS record per month. Against a hosted container service (Fly,
85 Vercel, Cloudflare), the comparison is the same plan row with the other host's price from `src/cloud/prices.ts`
86 when it has one; where it does not, "not priced" and no guess. Other hosts come afterwards as integrations
87 through the same plan, each behind `mayUse` and `cloud.json`.
88
89 ## The first slice, in order
90
91 1. `kind` on the box row; the agent's general verbs (build or pull by digest, health gate, previous-digest
92 rollback) behind it, with tests against the agent's existing stand-ins.
93 2. The plan (`want: { service: true, … }`) with the image, port, variables, secrets, volume, memory and host.
94 3. Caddy and the DNS record; the https check.
95 4. The page, the terminal screen and the MCP tool, and their how-to in `docs/features/`.
96 5. The restore drill, run once for real on one service.
97
98 Each is a pull of its own. This pull is step 0: the design.
src/view/doc_sections.ts +1
@@ -96,6 +96,7 @@ export const DOC_LINES: Record<string, Line> = {
9696 "SPIKE-CLOUDFLARE.md": ["internals", "An unapplied experiment.", "Experiment: a forge on Cloudflare"],
9797 "SPIKE-SEARCH-READING.md": ["internals", "A measurement that stopped at step 1.", "Experiment: a search-first reading layer"],
9898 "SPIKE-UNKERNEL.md": ["internals", "A spike measuring unkernel under Bun as a sandbox.", "Spike: unkernel under Bun"],
99 "SERVICES.md": ["internals", "Design: any container image as a service.", "Services: run any container image"],
99100 "BACKLOG.md": ["internals", "Where ideas live: the map and the Later gate."],
100101 };
101102

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs