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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

sold/forge-data-on-volume → main 3 commits 1 thread · 1 unresolved

  • Merged. sold/forge-data-on-volume was merged into main as bedd8d3.

Review

Sign in to review this change.
10 files changed +31 −15
docs/features/deploy-to-hetzner.md +1 −1
@@ -4,7 +4,7 @@ row: A pinned forge
44 ---
55 # Deploy a pinned forge to Hetzner Cloud (#16200)
66
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.
88
99 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.
1010 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
8585
8686 | Target | Status | What runs | Cost | Refused / caveat |
8787 |---|---|---|---|---|
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". |
outdated

The DigitalOcean row still says FORGE_APP_DATA. The deployed boot now sets FORGE_DATA, as the Hetzner row below it does. Change this to match.

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. |
9090 | 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. |
9191 | 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. |
9292 | 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 {
109109 // A row from before `checkConfig` refused these names may still hold one: it is dropped, so what
110110 // the boot sets is said once and in its own place.
111111 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 })
113113 .map(([k, v]) => `${k}=${v}`)
114114 .join("\n");
115115 // 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[] = [
2323 id: "digitalocean",
2424 label: "DigitalOcean",
2525 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.",
2727 cost: "read from DigitalOcean's own sizes, in US dollars: GET /api/v1/places?provider=digitalocean",
2828 refused: "Nothing the forge needs is refused; the token must be able to create droplets and volumes, which DigitalOcean cannot narrow further.",
2929 },
@@ -31,7 +31,7 @@ export const TARGETS: readonly Target[] = [
3131 id: "hetzner",
3232 label: "Hetzner Cloud",
3333 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.",
3535 cost: "read from Hetzner's own pricing and converted to US dollars at the day's reference rate: GET /api/v1/places?provider=hetzner",
3636 refused: "Nothing the forge needs is refused; the token must be read-write, and Hetzner scopes it to one project and offers nothing narrower.",
3737 },
src/core/pinned.ts +1 −1
@@ -88,7 +88,7 @@ const VALUE = /^[A-Za-z0-9 _.,:\/@+=-]{0,512}$/;
8888 * What the boot config sets itself (`servedEnv` and the data directory, `cloud/machine.ts`): the
8989 * forge's name, its listeners, who may say the client's address, its claim, its sandbox, its data.
9090 */
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"];
9292 const SECRETISH = /SECRET|TOKEN|PASSWORD|PASSWD|PASSPHRASE|PRIVATE|CREDENTIAL|COOKIE|AUTH(?!OR)|API_?KEY|ACCESS_?KEY|(?:^|_)KEYS?(?:_|$)/;
9393 // A name that steers the dynamic loader, the runtime, the path or the shell of the process it is
9494 // 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", () => {
11331133 PUBLIC_NAME: "Acme",
11341134 });
11351135 // 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");
11371137 expect(Object.keys(env).indexOf("PUBLIC_NAME")).toBeLessThan(
11381138 Object.keys(env).indexOf("FORGE_URL"),
11391139 );
11401140 // 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"]) {
11421142 expect(BOOT_NAMES).toContain(name);
11431143 const r = checkConfig({ [name]: "x" });
11441144 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", () => {
9292 expect(droplet.volumes).toEqual(["vol-1"]);
9393 expect(JSON.stringify(calls.map((c) => c.body))).not.toContain(TOKEN);
9494 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");
9696 const p = getPinned(app.db, "acme")!;
9797 expect(p).toMatchObject({ state: "running", volume: "vol-1" });
9898 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) => {
5151 test("is valid cloud-config", () => {
5252 expect(boot().startsWith("#cloud-config\n")).toBe(true);
5353 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=");
5555 });
5656
5757 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) => {
131131 expect(doc.packages).toContain("caddy");
132132 expect(boot()).not.toContain("apt-get");
133133 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]!;
135135 // Its config is where the package reads it before the package exists, so its first start is
136136 // on this and never on a welcome page; nothing copies a config in afterwards.
137137 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) => {
199199 });
200200
201201 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\//);
204204 });
205205 });
206206
test/pinned-hetzner.test.ts +1 −1
@@ -86,7 +86,7 @@ describe("hetzner target", () => {
8686 const [volume, server] = [calls[0]!.body, calls[2]!.body];
8787 expect(volume.location).toBe("nbg1");
8888 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");
9090 expect(server.user_data).toContain(`checkout --detach ${V1}`);
9191 expect(server.user_data).not.toContain(TOKEN);
9292 expect(getPinned(app.db, "acme")).toMatchObject({ target: "hetzner", state: "running", volume: "77", remote: "501", datacenter: "nbg1", size: "cx23" });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs