Public: anyone can read this; the crew can change it.
A deployed forge keeps its data on its volume: the boot names it FORGE_DATA #16343
Check · Review · Land · Live done — Landed and live in production.
sold/forge-data-on-volume → main 3 commits 1 thread · 1 unresolved
10 files
changed +31
−15
docs/features/deploy-to-hetzner.md +1 −1
| @@ -4,7 +4,7 @@ row: A pinned forge | ||
| 4 | 4 | --- |
| 5 | 5 | # Deploy a pinned forge to Hetzner Cloud (#16200) |
| 6 | 6 | |
| 7 | A pinned forge can run in your own Hetzner Cloud project the way it runs on DigitalOcean: one server, one volume as `FORGE_APP_DATA`, and a version that moves only when you press Update. | |
| 7 | A pinned forge can run in your own Hetzner Cloud project the way it runs on DigitalOcean: one server, one volume as `FORGE_DATA`, and a version that moves only when you press Update. | |
| 8 | 8 | |
| 9 | 9 | 1. **Make a token.** In the Hetzner Cloud console open the project, Security → API tokens, and make a token with **Read & Write**. Hetzner scopes a token to one project and offers nothing narrower, and a read-only token can only check a forge, never make one. |
| 10 | 10 | 2. **Attach it.** Settings → Cloud accounts (`/settings/cloud`), provider Hetzner Cloud, then **allow writes** on the account. The token is sealed; it is opened for one call at a time. |
docs/features/pinned-forge.md +2 −2
| @@ -85,8 +85,8 @@ Prices are list prices as last read (USD a month); the owner's own bill is the t | ||
| 85 | 85 | |
| 86 | 86 | | Target | Status | What runs | Cost | Refused / caveat | |
| 87 | 87 | |---|---|---|---|---| |
| 88 | | DigitalOcean | **deploys today** | One droplet (Ubuntu 24.04) at the forge's place, with a 10 GiB block volume in the same datacenter as `FORGE_APP_DATA`. An Update deletes the droplet and starts a new one on the same volume, so data is untouched. | ~$12 + ~$1.20 | A token cannot be narrowed below "create droplets and volumes". | | |
| 89 | | Hetzner Cloud | **deploys today** | One server (Ubuntu 24.04) with a 10 GiB volume as `FORGE_APP_DATA`, at the forge's place. See `deploy-to-hetzner.md`. | the API's list price + the volume | The token must be read-write; Hetzner offers nothing narrower. | | |
| 88 | | DigitalOcean | **deploys today** | One droplet (Ubuntu 24.04) at the forge's place, with a 10 GiB block volume in the same datacenter as `FORGE_DATA`. An Update deletes the droplet and starts a new one on the same volume, so data is untouched. | ~$12 + ~$1.20 | A token cannot be narrowed below "create droplets and volumes". | | |
| 89 | | Hetzner Cloud | **deploys today** | One server (Ubuntu 24.04) with a 10 GiB volume as `FORGE_DATA`, at the forge's place. See `deploy-to-hetzner.md`. | the API's list price + the volume | The token must be read-write; Hetzner offers nothing narrower. | | |
| 90 | 90 | | AWS | not written | EC2 `t4g.small` + EBS gp3, same boot script; SigV4 already exists for reads. | ~$12 + ~$0.80 + public IPv4 ~$3.65 | Wants a role scoped to a tag rather than a long-lived key. | |
| 91 | 91 | | Azure | not written | B1ms VM + managed disk through a service principal on one resource group. | ~$15 + ~$1 + public IP ~$3.65 | Needs a resource group, network and public IP first: three calls more. | |
| 92 | 92 | | Cloudflare | **refused** | Workers/Durable Objects keep state, but not as files a Bun process opens. Containers run, with a disk wiped on sleep or replace. | Workers Paid from $5 | No volume that survives; the forge refuses rather than lose repositories quietly. | |
src/cloud/machine.ts +1 −1
| @@ -109,7 +109,7 @@ export function bootConfig(p: Booted, dataDir: string): string { | ||
| 109 | 109 | // A row from before `checkConfig` refused these names may still hold one: it is dropped, so what |
| 110 | 110 | // the boot sets is said once and in its own place. |
| 111 | 111 | const settings = Object.fromEntries(Object.entries(p.config).filter(([k]) => !BOOT_NAMES.includes(k))); |
| 112 | const env = Object.entries({ ...settings, ...servedEnv(p), FORGE_APP_DATA: dataDir }) | |
| 112 | const env = Object.entries({ ...settings, ...servedEnv(p), FORGE_DATA: dataDir }) | |
| 113 | 113 | .map(([k, v]) => `${k}=${v}`) |
| 114 | 114 | .join("\n"); |
| 115 | 115 | // Every interpolated value is validated in core/pinned.ts (version, source, config, host) or by |
src/cloud/targets.ts +2 −2
| @@ -23,7 +23,7 @@ export const TARGETS: readonly Target[] = [ | ||
| 23 | 23 | id: "digitalocean", |
| 24 | 24 | label: "DigitalOcean", |
| 25 | 25 | status: "first", |
| 26 | runs: "One droplet (Ubuntu, Bun from the pinned source) with one block volume mounted as FORGE_APP_DATA. Replacing the droplet keeps the volume, so a version change never touches the data.", | |
| 26 | runs: "One droplet (Ubuntu, Bun from the pinned source) with one block volume mounted as FORGE_DATA. Replacing the droplet keeps the volume, so a version change never touches the data.", | |
| 27 | 27 | cost: "read from DigitalOcean's own sizes, in US dollars: GET /api/v1/places?provider=digitalocean", |
| 28 | 28 | refused: "Nothing the forge needs is refused; the token must be able to create droplets and volumes, which DigitalOcean cannot narrow further.", |
| 29 | 29 | }, |
| @@ -31,7 +31,7 @@ export const TARGETS: readonly Target[] = [ | ||
| 31 | 31 | id: "hetzner", |
| 32 | 32 | label: "Hetzner Cloud", |
| 33 | 33 | status: "first", |
| 34 | runs: "One server (Ubuntu, Bun from the pinned source) with one volume mounted as FORGE_APP_DATA, in Nuremberg. The forge reads Hetzner's own list and orders the cheapest cost-optimized (CX) type with at least 2 GiB that is in stock there; when none can be ordered it says so before it makes anything. Replacing the server keeps the volume.", | |
| 34 | runs: "One server (Ubuntu, Bun from the pinned source) with one volume mounted as FORGE_DATA, in Nuremberg. The forge reads Hetzner's own list and orders the cheapest cost-optimized (CX) type with at least 2 GiB that is in stock there; when none can be ordered it says so before it makes anything. Replacing the server keeps the volume.", | |
| 35 | 35 | cost: "read from Hetzner's own pricing and converted to US dollars at the day's reference rate: GET /api/v1/places?provider=hetzner", |
| 36 | 36 | refused: "Nothing the forge needs is refused; the token must be read-write, and Hetzner scopes it to one project and offers nothing narrower.", |
| 37 | 37 | }, |
src/core/pinned.ts +1 −1
| @@ -88,7 +88,7 @@ const VALUE = /^[A-Za-z0-9 _.,:\/@+=-]{0,512}$/; | ||
| 88 | 88 | * What the boot config sets itself (`servedEnv` and the data directory, `cloud/machine.ts`): the |
| 89 | 89 | * forge's name, its listeners, who may say the client's address, its claim, its sandbox, its data. |
| 90 | 90 | */ |
| 91 | export const BOOT_NAMES: readonly string[] = ["FORGE_URL", "FORGE_HOST", "FORGE_BIND", "FORGE_TRUSTED_PROXIES", "FORGE_SSH_PORT", "FORGE_FIRST_ADMIN_SEED", "FORGE_CREW_SANDBOX", "FORGE_APP_DATA"]; | |
| 91 | export const BOOT_NAMES: readonly string[] = ["FORGE_URL", "FORGE_HOST", "FORGE_BIND", "FORGE_TRUSTED_PROXIES", "FORGE_SSH_PORT", "FORGE_FIRST_ADMIN_SEED", "FORGE_CREW_SANDBOX", "FORGE_DATA", "FORGE_APP_DATA"]; | |
| 92 | 92 | const SECRETISH = /SECRET|TOKEN|PASSWORD|PASSWD|PASSPHRASE|PRIVATE|CREDENTIAL|COOKIE|AUTH(?!OR)|API_?KEY|ACCESS_?KEY|(?:^|_)KEYS?(?:_|$)/; |
| 93 | 93 | // A name that steers the dynamic loader, the runtime, the path or the shell of the process it is |
| 94 | 94 | // set for is never a setting: it is the unit's environment, and a forge that runs as itself must |
test/pinned-claim.test.ts +2 −2
| @@ -1133,12 +1133,12 @@ describe("the name and the boot config", () => { | ||
| 1133 | 1133 | PUBLIC_NAME: "Acme", |
| 1134 | 1134 | }); |
| 1135 | 1135 | // What the boot sets comes after the config, the data directory last of all. |
| 1136 | expect(Object.keys(env).at(-1)).toBe("FORGE_APP_DATA"); | |
| 1136 | expect(Object.keys(env).at(-1)).toBe("FORGE_DATA"); | |
| 1137 | 1137 | expect(Object.keys(env).indexOf("PUBLIC_NAME")).toBeLessThan( |
| 1138 | 1138 | Object.keys(env).indexOf("FORGE_URL"), |
| 1139 | 1139 | ); |
| 1140 | 1140 | // And none of it is a setting a deploy may name: every name the boot sets is refused. |
| 1141 | for (const name of [...Object.keys(servedEnv(booted())), "FORGE_APP_DATA"]) { | |
| 1141 | for (const name of [...Object.keys(servedEnv(booted())), "FORGE_DATA"]) { | |
| 1142 | 1142 | expect(BOOT_NAMES).toContain(name); |
| 1143 | 1143 | const r = checkConfig({ [name]: "x" }); |
| 1144 | 1144 | expect(r.ok ? "" : r.error).toContain("is set by the deploy itself"); |
test/pinned-data-dir.test.ts added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { bootConfig } from "../src/cloud/machine.ts"; | |
| 3 | import { dataDirOf } from "../src/kernel/preflight.ts"; | |
| 4 | ||
| 5 | // The first real deploy (test1, 2026-11-24) answered 502 behind its proxy: the boot named the | |
| 6 | // volume FORGE_APP_DATA, which a forge that is not a hosted child ignores, so it looked for its | |
| 7 | // data in its read-only checkout. The forge must find its data on the volume the boot mounted. | |
| 8 | test("a deployed forge keeps its data on the volume its boot mounted", () => { | |
| 9 | const boot = bootConfig( | |
| 10 | { name: "acme", source: "https://forge.example.org/trevato/forge", version: "a".repeat(40), config: {}, host: "acme.forges.example.com", app: "alice/shop", claimHash: "0".repeat(64), claimExpires: "2026-12-01T00:00:00.000Z" } as any, | |
| 11 | "/mnt/forge_acme_data", | |
| 12 | ); | |
| 13 | const line = /content: ("FORGE_URL=[^\n]*")/.exec(boot)![1]!; | |
| 14 | const env = Object.fromEntries((JSON.parse(line) as string).trim().split("\n").map((l) => [l.slice(0, l.indexOf("=")), l.slice(l.indexOf("=") + 1)])); | |
| 15 | expect(dataDirOf(env)).toBe("/mnt/forge_acme_data"); | |
| 16 | }); |
test/pinned-forge.test.ts +1 −1
| @@ -92,7 +92,7 @@ describe("pinned forge", () => { | ||
| 92 | 92 | expect(droplet.volumes).toEqual(["vol-1"]); |
| 93 | 93 | expect(JSON.stringify(calls.map((c) => c.body))).not.toContain(TOKEN); |
| 94 | 94 | expect(droplet.user_data).toContain(`checkout --detach ${V1}`); |
| 95 | expect(droplet.user_data).toContain("FORGE_APP_DATA=/mnt/forge_acme_data"); | |
| 95 | expect(droplet.user_data).toContain("FORGE_DATA=/mnt/forge_acme_data"); | |
| 96 | 96 | const p = getPinned(app.db, "acme")!; |
| 97 | 97 | expect(p).toMatchObject({ state: "running", volume: "vol-1" }); |
| 98 | 98 | const events = JSON.stringify(app.db.query("SELECT payload FROM event WHERE kind LIKE 'pinned.%'").all()); |
test/pinned-harden.test.ts +4 −4
| @@ -51,7 +51,7 @@ describe.each(Object.entries(boots))("the %s machine", (_name, boot) => { | ||
| 51 | 51 | test("is valid cloud-config", () => { |
| 52 | 52 | expect(boot().startsWith("#cloud-config\n")).toBe(true); |
| 53 | 53 | expect(doc.runcmd.every((c) => typeof c === "string")).toBe(true); |
| 54 | expect(file(doc, "/etc/forge/env")).toContain("FORGE_APP_DATA="); | |
| 54 | expect(file(doc, "/etc/forge/env")).toContain("FORGE_DATA="); | |
| 55 | 55 | }); |
| 56 | 56 | |
| 57 | 57 | test("the forge runs as its own user, from a Bun root owns, never as root", () => { |
| @@ -131,7 +131,7 @@ describe.each(Object.entries(boots))("the %s machine", (_name, boot) => { | ||
| 131 | 131 | expect(doc.packages).toContain("caddy"); |
| 132 | 132 | expect(boot()).not.toContain("apt-get"); |
| 133 | 133 | expect(file(doc, "/etc/forge/env")).toContain("FORGE_BIND=127.0.0.1\n"); |
| 134 | const dir = /^FORGE_APP_DATA=(\/mnt\/\S+)$/m.exec(file(doc, "/etc/forge/env"))![1]!; | |
| 134 | const dir = /^FORGE_DATA=(\/mnt\/\S+)$/m.exec(file(doc, "/etc/forge/env"))![1]!; | |
| 135 | 135 | // Its config is where the package reads it before the package exists, so its first start is |
| 136 | 136 | // on this and never on a welcome page; nothing copies a config in afterwards. |
| 137 | 137 | expect(file(doc, "/etc/caddy/Caddyfile")).toBe(`{\n\tstorage file_system ${dir}/caddy\n}\nacme.forge.test {\n\treverse_proxy 127.0.0.1:3000\n}\n`); |
| @@ -199,8 +199,8 @@ describe.each(Object.entries(boots))("the %s machine", (_name, boot) => { | ||
| 199 | 199 | }); |
| 200 | 200 | |
| 201 | 201 | test("the forge's own data directory is applied last, after anything config said", () => { |
| 202 | const env = file(parse(boot().replace("PUBLIC_NAME=Acme", "FORGE_APP_DATA=/evil\\nPUBLIC_NAME=Acme")), "/etc/forge/env"); | |
| 203 | expect(env.trim().split("\n").at(-1)).toMatch(/^FORGE_APP_DATA=\/mnt\//); | |
| 202 | const env = file(parse(boot().replace("PUBLIC_NAME=Acme", "FORGE_DATA=/evil\\nPUBLIC_NAME=Acme")), "/etc/forge/env"); | |
| 203 | expect(env.trim().split("\n").at(-1)).toMatch(/^FORGE_DATA=\/mnt\//); | |
| 204 | 204 | }); |
| 205 | 205 | }); |
| 206 | 206 |
test/pinned-hetzner.test.ts +1 −1
| @@ -86,7 +86,7 @@ describe("hetzner target", () => { | ||
| 86 | 86 | const [volume, server] = [calls[0]!.body, calls[2]!.body]; |
| 87 | 87 | expect(volume.location).toBe("nbg1"); |
| 88 | 88 | expect(server).toMatchObject({ server_type: "cx23", location: volume.location, volumes: [77], automount: true }); |
| 89 | expect(server.user_data).toContain("FORGE_APP_DATA=/mnt/HC_Volume_77"); | |
| 89 | expect(server.user_data).toContain("FORGE_DATA=/mnt/HC_Volume_77"); | |
| 90 | 90 | expect(server.user_data).toContain(`checkout --detach ${V1}`); |
| 91 | 91 | expect(server.user_data).not.toContain(TOKEN); |
| 92 | 92 | expect(getPinned(app.db, "acme")).toMatchObject({ target: "hetzner", state: "running", volume: "77", remote: "501", datacenter: "nbg1", size: "cx23" }); |
new above
offline
The DigitalOcean row still says
FORGE_APP_DATA. The deployed boot now setsFORGE_DATA, as the Hetzner row below it does. Change this to match.