Skip to content
Myr

stages.ts

This file

Path

infra/stages.ts

172 lines · 5.6 KiB · TypeScript

Last changed by

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

lines 1–3why, one step back
1// The one table of stages and the resources each owns, each named by its job
2// plus the stage, never the brand. `packages/config/test/bootstrap.test.ts`3// holds every Worker's `wrangler.jsonc` env blocks to it.

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

line 4why, one step back
4import { Brand } from "@repo/brand";

Close W7: cross-compile the release again, guard pi's edits, and keep the swarm out of this checkoutoscabrielbefore adoption842f042

line 5why, one step back
5import { Effect, FileSystem, Option, Path, Schema } from "effect";

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 6–11why, one step back
6
7export const Stage = Schema.Union([8 Schema.TemplateLiteral([9 "dev-",10 Schema.String.check(Schema.isPattern(/^[a-z0-9]+$/u)),11 ]),

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

line 12why, one step back
12 Schema.Literal("prod"),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 13–16why, one step back
13]);
1415export type Stage = typeof Stage.Type;16

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

line 17why, one step back
17// Each has an `env` block in every Worker's `wrangler.jsonc`; add a stage to both.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 18–19why, one step back
18export const stages = [
19 "dev-oscabriel",

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

line 20why, one step back
20 "prod",

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 21–22why, one step back
21] as const satisfies readonly Stage[];
22

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 23–24why, one step back
23// The stages people see: no script makes a throwaway project or seeds a
24// fictional one on them without being told to.

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

line 25why, one step back
25export const publicStages: ReadonlySet<string> = new Set<Stage>(["prod"]);

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 26–29why, one step back
26
27export interface Hosts {28 readonly platform: string;29 readonly web: string;

Serve the web's www host as a redirect to its bare hostoscabrielbefore adoption05cecd1

lines 30–31why, one step back
30 // More Custom Domains on the web's Worker, each answered with a 301 to `web`.
31 readonly webAliases: readonly string[];

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 32–43why, one step back
32}
3334// A stage served on the brand's own domain, as Workers Custom Domains. The35// names live here, not in `wrangler.jsonc`, so the brand stays in36// `packages/brand`: `infra/deploy.ts` hands them to Wrangler as `--domain`37// and as the URL vars, and such a stage turns its `workers.dev` route off.38// What such a stage's `wrangler.jsonc` holds in each URL var: `.invalid`39// never resolves, so a deploy that skipped `--var` fails where it shows.40export const URL_FROM_DEPLOY = "https://from-infra-deploy.invalid";4142export const customHosts = (stage: Stage): Option.Option<Hosts> =>43 stage === "prod"

Serve the web's www host as a redirect to its bare hostoscabrielbefore adoption05cecd1

lines 44–48why, one step back
44 ? Option.some({
45 platform: `git.${Brand.domain}`,46 web: Brand.domain,47 webAliases: [`www.${Brand.domain}`],48 })

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 49–50why, one step back
49 : Option.none();
50

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 51–55why, one step back
51export interface Resources {
52 readonly platform: string;53 readonly sandbox: string;54 readonly web: string;55 readonly projects: string;

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

line 56why, one step back
56 // Private: every project's layer repos.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 57–61why, one step back
57 readonly layers: string;
58 readonly frontPage: string;59 readonly oauth: string;60 readonly evidence: string;61 readonly releases: string;

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

line 62why, one step back
62 readonly codeCache: string;

Merge observability into mainoscabrielbefore adoption1985111

lines 63–67why, one step back
63 // Workers Analytics Engine's domain metrics: made by its first write, so
64 // bootstrap makes none, and named with `_`, since SQL reads it as a table.65 // The platform's `METRICS` binding writes it, and the refusal alert66 // (`alerts.ts`) reads it.67 readonly metrics: string;

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 68–73why, one step back
68 readonly answer: string;
69 readonly onPush: string;70}7172export const resources = (stage: Stage): Resources => ({73 answer: `answer-${stage}`,

Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c

line 74why, one step back
74 codeCache: `code-cache-${stage}`,

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 75–77why, one step back
75 evidence: `evidence-${stage}`,
76 frontPage: `front-page-${stage}`,77 layers: `layers-${stage}`,

Merge observability into mainoscabrielbefore adoption1985111

line 78why, one step back
78 metrics: `metrics_${stage.replaceAll("-", "_")}`,

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 79–112why, one step back
79 oauth: `oauth-${stage}`,
80 onPush: `on-push-${stage}`,81 platform: `platform-${stage}`,82 projects: `projects-${stage}`,83 releases: `releases-${stage}`,84 sandbox: `sandbox-${stage}`,85 web: `web-${stage}`,86});8788const decodeStage = Schema.decodeUnknownOption(Stage);8990export const declaredStage = (raw: string): Option.Option<Stage> =>91 Option.filter(decodeStage(raw), (stage) =>92 stages.some((declared) => declared === stage)93 );9495export const flagValue = (96 argv: readonly string[],97 flag: string98): Option.Option<string> => {99 const joined = argv.find((arg) => arg.startsWith(`${flag}=`));100101 if (joined !== undefined) {102 return Option.some(joined.slice(flag.length + 1));103 }104105 const at = argv.indexOf(flag);106107 return Option.filter(108 Option.fromNullishOr(at === -1 ? undefined : argv[at + 1]),109 (value) => !value.startsWith("--")110 );111};112

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

lines 113–114why, one step back
113// `runMain` prints only a failure's tag and message, so each infra failure's
114// message says what to do. None carries a secret's value.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 115–146why, one step back
115
116export class NoStage extends Schema.TaggedError<NoStage>()("NoStage", {}) {117 override readonly message = `no --stage: name one of ${stages.join(", ")}`;118}119120export class UnknownStage extends Schema.TaggedError<UnknownStage>()(121 "UnknownStage",122 { stage: Schema.String }123) {124 override get message() {125 return `--stage ${this.stage} is not a stage infra/stages.ts declares (${stages.join(", ")})`;126 }127}128129export const stageOf = (argv: readonly string[]) =>130 Effect.gen(function* () {131 const raw = yield* Effect.fromOption(flagValue(argv, "--stage")).pipe(132 Effect.mapError(() => new NoStage())133 );134135 return yield* Effect.fromOption(declaredStage(raw)).pipe(136 Effect.mapError(() => new UnknownStage({ stage: raw }))137 );138 });139140export const repoRoot = Effect.flatMap(Path.Path, (path) =>141 path.fromFileUrl(new URL("..", import.meta.url))142).pipe(Effect.orDie);143144export const subdomainFile = "infra/workers-dev.json";145146export const WorkersDev = Schema.Struct({ subdomain: Schema.NonEmptyString });

Close W7: cross-compile the release again, guard pi's edits, and keep the swarm out of this checkoutoscabrielbefore adoption842f042

lines 147–159why, one step back
147
148export const recordedSubdomain = Effect.gen(function* () {149 const fs = yield* FileSystem.FileSystem;150 const path = yield* Path.Path;151152 return yield* fs153 .readFileString(path.join(yield* repoRoot, subdomainFile))154 .pipe(155 Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(WorkersDev))),156 Effect.map(({ subdomain }) => subdomain),157 Effect.option158 );159});

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 160–161why, one step back
160
161export const platformOrigin = (stage: Stage, subdomain: string) =>

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 162–166why, one step back
162 Option.match(customHosts(stage), {
163 onNone: () =>164 `https://${resources(stage).platform}.${subdomain}.workers.dev`,165 onSome: ({ platform }) => `https://${platform}`,166 });

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 167–168why, one step back
167
168export const webOrigin = (stage: Stage, subdomain: string) =>

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 169–172why, one step back
169 Option.match(customHosts(stage), {
170 onNone: () => `https://${resources(stage).web}.${subdomain}.workers.dev`,171 onSome: ({ web }) => `https://${web}`,172 });