Skip to content
Myr

Bootstrap the demo stage, give it generated secrets, and write down what each stage holds

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- `bun run bootstrap -- --stage demo` made projects-demo, layers-demo, front-page-demo (migrations 0001 to 0004 applied), oauth-demo, evidence-demo and releases-demo, and wrote the D1 and KV ids into demo's block of apps/platform/wrangler.jsonc. Red first: the dry run listed six to create; a second real run created 0 and found every required secret, and the dry run then said "would create 0". dev-oscabriel re-checked the same way: created 0, every required secret present. - Demo's secrets are generated, as the dev stage's are (the orchestrator's decision under the user's blanket yes, extending the recorded dev-only rule to demo): OPERATOR_TOKEN, COOKIE_KEY, PASSWORD_PEPPER (32 random bytes, base64url), MASTER_KEY (64 hex) and SESSION_TOKENS for bram, ines-v, okafor, okonkwo, lin-h, wren, tamsin, ivo, marisol, dagny and pell, kept only in a mode-600 file outside the repo, set with `wrangler secret put <NAME> --env demo` from stdin, never printed. The first put made platform-demo as a placeholder Worker (no code, no workers.dev route) until the demo's first deploy. - infra/deploy.ts takes STAGE_SECRETS_FILE for demo too, and SecretsFileNotForStage is gone: varlock-wrangler resolves every required name on each deploy, so without the file demo's first deploy could not resolve its secrets. Test: deploy.test.ts's demo case now holds that the platform step alone gets the file's values, and the message test names an unreadable file instead. - infra/stages.md has the six parts the teardown and the user need: stages, resources per stage (name, created by, when, keep), the throwaway ledger summary plus the pre-ledger leftovers on dev-oscabriel, the teardown policy, the status of every human step on 2026-10-08 (rotate both stages' generated secrets before going public), and the URLs. The how-to sections follow under "Running a stage". - H6 confirmed from evidence: the account's subscriptions, read again, list workers_paid as Paid, and the sandbox's containers and both Workflows have run on dev-oscabriel since 2026-10-07. - ASSUMPTION: a placeholder Worker made by `wrangler secret put` is replaced cleanly by the first `wrangler deploy` (it has no migrations tag, so every Durable Object migration applies); the demo's deploy shows it.

authored by oscabriel · committed by oscabriel · parent 61ef4c0 · Browse files · 5 files+191 added−69 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+191 added−69 removed

  • tests:+42 added−10 removed
  • other:+149 added−59 removed

5 files+191 added−69 removed

modified:apps/platform/wrangler.jsonc+2 added-2 removed
228 unmodified lines
229 "d1_databases": [230 {231 "binding": "FRONT_PAGE",232 "database_name": "front-page-demo",233 "database_id": "00000000-0000-0000-0000-000000000000",233 "database_id": "a83fc9b1-1414-4d9c-b83c-b1e468cfc5d4",234 "migrations_dir": "migrations",235 },236 ],237 // KV namespace `oauth-demo`.238 "kv_namespaces": [239 { "binding": "OAUTH_KV", "id": "00000000000000000000000000000000" },239 { "binding": "OAUTH_KV", "id": "c9b3fb4d9bd04b458051519f2f8cd0e8" },240 ],241 "r2_buckets": [242 { "binding": "EVIDENCE", "bucket_name": "evidence-demo" },243 { "binding": "RELEASES", "bucket_name": "releases-demo" },
34 unmodified lines
modified:infra/.env.schema+3 added-3 removed
24 unmodified lines
2526# Nothing here is a person's token. The swarm (`bun run swarm`) signs in as27# the demo's fictional people with apps/platform/.env.schema's28# SESSION_TOKENS, run as `bunx varlock run --path apps/platform/ -- bun29# scripts/swarm.ts …`, so no script or agent reads a `.env*` file. On a dev30# stage those tokens come from the stage's secrets file outside the repo31# (STAGE_SECRETS_FILE, infra/stages.md); on `demo` a person sets them.29# scripts/swarm.ts …`, so no script or agent reads a `.env*` file. On every30# stage those tokens come from the stage's generated secrets file outside the31# repo (STAGE_SECRETS_FILE, infra/stages.md).
modified:infra/deploy.ts+7 added-29 removed
19 unmodified lines
20 * with its own login, never the read-mostly infra token.21 *22 * `STAGE_SECRETS_FILE` names a dotenv file outside the repo whose values the23 * platform's deploy carries as its environment, which varlock reads before24 * any `.env` file (spec §8.3 O1: the dev stage's generated secrets). Only the25 * items `apps/platform/.env.schema` declares are passed, to that one step,26 * and no value is ever printed. With `--stage demo` it refuses the file27 * before it spawns anything: demo's secrets are a person's to set (H5).24 * any `.env` file: a stage's generated secrets, on every stage (spec §8.325 * O1, extended to demo). Only the items `apps/platform/.env.schema` declares26 * are passed, to that one step, and no value is ever printed.27 *28 * Each step runs with its own folder's `node_modules/.bin` first on `PATH`,29 * since `varlock-wrangler` starts `wrangler` by name.30 */
42 unmodified lines
73 return `STAGE_SECRETS_FILE names ${this.file}, which can't be read`;74 }75}7678/**79 * `STAGE_SECRETS_FILE` was given for `demo`: generated secrets are the dev80 * stage's alone, and `demo`'s are a person's to set (spec §8.3 O1, H5).81 */82export class SecretsFileNotForStage extends Schema.TaggedError<SecretsFileNotForStage>()(83 "SecretsFileNotForStage",84 { stage: Schema.String }85) {86 override get message() {87 return `STAGE_SECRETS_FILE is for dev stages only: set ${this.stage}'s secrets with varlock (infra/stages.md)`;88 }89}9077/** One command of the deploy, run from `cwd` (relative to the repo root). */78interface Step {79 readonly name: string;80 readonly command: string;
64 unmodified lines
145];146147/**148 * The values `STAGE_SECRETS_FILE` holds for the items the platform's163 * `.env.schema` declares: none when it isn't set. Only a dev stage takes one.149 * `.env.schema` declares: none when it isn't set.150 */165const platformSecrets = (root: string, stage: Stage) =>151const platformSecrets = (root: string) =>152 Effect.gen(function* () {153 const fs = yield* FileSystem.FileSystem;154 const path = yield* Path.Path;155
4 unmodified lines
160 if (Option.isNone(file)) {161 return {};162 }163178 if (stage === "demo") {179 return yield* new SecretsFileNotForStage({ stage });180 }181164 const contents = yield* fs165 .readFileString(file.value)166 .pipe(167 Effect.mapError(() => new SecretsFileUnreadable({ file: file.value }))
99 unmodified lines
267export const deploy = (268 argv: readonly string[]269): Effect.Effect<270 void,289 | NoStage290 | UnknownStage291 | StepFailed292 | SecretsFileUnreadable293 | SecretsFileNotForStage,271 NoStage | UnknownStage | StepFailed | SecretsFileUnreadable,272 ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path273> =>274 Effect.gen(function* () {275 const stage = yield* stageOf(argv);
4 unmodified lines
280 const web = yield* fs281 .exists(path.join(root, "apps/web/wrangler.jsonc"))282 .pipe(Effect.orDie);283306 const platformEnv = yield* platformSecrets(root, stage);284 const platformEnv = yield* platformSecrets(root);285286 yield* Effect.forEach(287 stepsOf(stage, { platformEnv, web }),288 (step) => runStep(root, stage, step),
16 unmodified lines
modified:infra/stages.md+137 added-25 removed
modified:packages/config/test/deploy.test.ts+42 added-10 removed
15 unmodified lines
1617import {18 deploy,19 NoStage,20 SecretsFileNotForStage,20 StepFailed,21 UnknownStage,22} from "../../../infra/deploy.ts";23import { repoRoot } from "./root.ts";
364 unmodified lines
388 expect(message).toBe("platform exited 3, so nothing after it ran");389 })390 );391393 it.live("says where demo's secrets come from instead", () =>392 it.live("names the secrets file it could not read", () =>393 Effect.gen(function* () {394 const message = yield* messageOf(["--stage", "demo"], {395 env: { STAGE_SECRETS_FILE: "/nowhere/demo.secrets" },396 });397398 expect(message).toBe(400 "STAGE_SECRETS_FILE is for dev stages only: set demo's secrets with varlock (infra/stages.md)"399 "STAGE_SECRETS_FILE names /nowhere/demo.secrets, which can't be read"400 );401 })402 );403});404405describe("a deploy to demo", () => {406 it.live(408 "refuses STAGE_SECRETS_FILE, whose generated values are the dev stage's alone, before it spawns anything",407 "hands the platform's deploy the values in STAGE_SECRETS_FILE, as a dev stage's does: demo's secrets are generated too",408 () =>409 Effect.gen(function* () {410 const fs = yield* FileSystem.FileSystem;411 const path = yield* Path.Path;412 const dir = yield* fs.makeTempDirectoryScoped();413 const file = path.join(dir, "demo.secrets");414415 yield* fs.writeFileString(416 file,417 [418 "# generated for demo",419 "OPERATOR_TOKEN=operator-token-that-is-long-enough-000",420 "MASTER_KEY=00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",421 ].join("\n")422 );423424 const { result, spawned } = yield* run(["--stage", "demo"], {412 env: { STAGE_SECRETS_FILE: "/nowhere/demo.secrets" },425 env: { STAGE_SECRETS_FILE: file },426 });427415 expect(result).toStrictEqual(416 Result.fail(new SecretsFileNotForStage({ stage: "demo" }))417 );418 expect(spawned).toStrictEqual([]);419 })428 expect(Result.isSuccess(result)).toBeTruthy();429 expect(spawned.map(line)).toStrictEqual([430 ".$ bun run verify",431 "apps/sandbox$ wrangler deploy --env demo",432 "apps/platform$ varlock-wrangler deploy --env demo",433 "apps/web$ bun run build",434 "apps/web$ wrangler deploy --env demo",435 ".$ bun run bootstrap --stage demo --check-triggers",436 ".$ bun scripts/smoke.ts --stage demo",437 ]);438 expect(439 spawned.map(({ env }) =>440 ["MASTER_KEY", "OPERATOR_TOKEN"].filter((name) => name in env)441 )442 ).toStrictEqual([443 [],444 [],445 ["MASTER_KEY", "OPERATOR_TOKEN"],446 [],447 [],448 [],449 [],450 ]);451 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer))452 );453});