diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a0bf8b..63200fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: fetch-depth: 0 - uses: sourceplane/orun-action@v1.2.0 with: - version: v2.48.0 + version: v2.49.0 - env: # Surface the best-effort catalog auto-sync (execution.state.autopushCatalog). # A successful push prints "✓ pushed catalog …"; ORUN_VERBOSE also makes @@ -83,7 +83,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - uses: sourceplane/orun-action@v1.2.0 with: - version: v2.48.0 + version: v2.49.0 # exec-id is the RUN id alone (no attempt suffix): a `gh run rerun # --failed` then RESUMES the same orun execution — jobs that succeeded in # a prior attempt stay completed, so re-run lanes' cross-job dependencies @@ -92,13 +92,19 @@ jobs: # job when it terminally failed in a prior attempt (no-op on first # attempts) — together they make `gh run rerun --failed` a true resume. - run: | + # --retry only on re-run attempts: on a fresh attempt a failed + # upstream is a genuine failure and dependents must fail fast; on a + # resume (gh run rerun --failed) the upstream's own retry lane will + # re-open it, so lanes wait out the race instead. + retry_flag="" + if [ "${GITHUB_RUN_ATTEMPT:-1}" -gt 1 ]; then retry_flag="--retry"; fi orun run \ --plan plan.json \ --runner github-actions \ --remote-state \ --job "${{ matrix.job-id }}" \ --exec-id "${{ github.run_id }}" \ - --retry + $retry_flag env: # GITHUB_TOKEN is the only credential CI holds — GitHub-issued and # ephemeral. Every provider credential (Cloudflare token + account diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md new file mode 100644 index 0000000..fddddf1 --- /dev/null +++ b/BOOTSTRAP.md @@ -0,0 +1,107 @@ +# BOOTSTRAP — fresh product from this baseline, one workflow + +How to go from **nothing** to a **fully deployed working baseline** (all +terraform infra, the 12-worker fleet, api-edge, the console — live on +stage+prod) with one workflow run plus two OAuth consents. Proven end-to-end +by the `nimbus` instantiation (2026-07-28); the residual manual reruns it +needed are engineered away (smoke retry, resume dep-grace, single-run flow). + +Target wall-clock: **under an hour**. The long pole is Supabase project +creation (~5–10 min per environment); the worker fleet itself converges in +minutes. + +## 0. What you need + +- GitHub org access (repo creation) and a machine with `git`, `gh`, `node`, + `python3`, and the `orun` CLI ≥ v2.49.0. +- A Cloudflare account (Workers paid plan for the fleet) and its **Account + API token** (the console's Connect recipe lists the exact permission + groups). +- A Supabase organization (capacity for `-stage` / `-prod` + projects) whose OAuth consent you can grant. +- An Orun Cloud workspace for the product (`workspace:` in `intent.yaml`). + +## 1. Instantiate the repo from the blueprint + +```bash +blueprints/run-phases.sh # from the baseline checkout; see blueprints/ +``` + +Rebrand values (`tooling/rebrand/values.example.json`): `repoName`, +`productName`, `productDomain`, and `workersDevSubdomain`. Keeping the +baseline's workers.dev subdomain is fine when the fork shares the Cloudflare +account — worker names are brand-prefixed, and the rebrand sweep accepts a +kept subdomain (it only flags the subdomain when you *changed* it). + +The first CI push runs only the offline verify fleet: every deployable +component starts **parked** (`flows/subscriptions/`). + +## 2. Link the workspace + +```bash +orun auth login --device # approve at app.orun.dev/cli/device +orun cloud link # links / AND allow-lists CI +orun cloud check --org # verifies the OIDC allow-list took +``` + +## 3. Run the workflow + +```bash +orun workflow run flows/bootstrap-flow.yaml --set org= +``` + +Preflight **waits up to 10 minutes** for the two provider connections — grant +them in the console (→ Integrations) while it polls: + +- **Cloudflare**: paste the Account API token (in-console recipe). +- **Supabase**: OAuth consent; pick the organization that owns this product's + projects. Scopes live on the OAuth app itself — changing them later + **revokes every existing connection of that app across all workspaces** + (secrets go `orphaned`; re-connect + `flows/create-secrets.sh ` + self-heals). + +Then the flow runs unattended: brokered secrets → one main push un-parking +the whole fleet (feedback service-bindings stripped) → **one convergence +run** deploying everything in DAG order (supabase → db-migrate + hyperdrive → +workers → api-edge → console), auto-resumed through transient failures → a +final push restoring the service bindings → live-endpoint verification. + +`flows/README.md` documents each step and the ordering guarantees; +`ai/context/fork-from-baseline.md` records the fork provenance. + +## 4. After the baseline is live + +- **Custom domain**: create the product zone in Cloudflare, then un-park + `cloudflare-domain` (`node flows/park.mjs unpark cloudflare-domain`, PR it — + or `flows/batch.sh domain cloudflare-domain`). +- **Runtime secrets** (OAuth client secrets, billing keys, …): seed with + `orun secrets set --org --env `; the next deploy pushes + them to the workers (`wire-now-seed-later` — nothing blocks on them). +- **Incremental rollouts**: normal PRs; `flows/batch.sh` for grouped + enable-style changes. + +## Troubleshooting (everything we hit doing this for real) + +| Symptom | Cause → fix | +|---|---| +| Preflight times out on connections | Consent not granted yet — console → Integrations, then re-run the flow (idempotent). | +| Secrets listed `orphaned` | Their connection was revoked/replaced (e.g. OAuth app scopes changed). Re-connect the provider; `flows/create-secrets.sh ` recreates against the ACTIVE connection. | +| Supabase lane: `does not support oauth access` on `/billing/addons` | Provider ≥ 1.6.0 sneaked in — the roots pin `~> 1.5.1`; keep the pin. | +| Supabase lane: duplicate project name | The org already has `-` (a half-torn-down previous attempt). Adoption imports it automatically when it's the *same* product re-bootstrapping; otherwise delete the stray project. | +| Terraform: resource already exists (10014 etc.) with empty platform state | `adopt.tf` handles this by importing at plan time — present in kv / hyperdrive / supabase roots. Roots without adoption must be state-migrated or the resource deleted. | +| Convergence run fails, lanes look transient | `flows/converge.sh ` resumes it (`gh run rerun --failed` = true resume: exec-id + `--retry`). The flow already does this ×3. | +| Worker verify lane: missing `WIRING_*` / `SUPABASE_*` secret | Its terraform upstream hasn't applied (check that lane first) — inside one convergence run the DAG guarantees order; across manual partial runs it does not. | +| CLI login dies with 429 `rate_limited` | Fixed ≥ v2.48.1 (redeem honors Retry-After). Upgrade the CLI. | +| Many lanes queued, none claiming | Runner-pool starvation — `max-parallel: 8` in ci.yml is deliberate (resolve-herd); patience, or check the run isn't superseded. | + +## Architecture invariants this depends on + +- **CI holds one credential: `GITHUB_TOKEN`.** Provider credentials are + brokered per run from workspace integrations; terraform state lives on the + platform (`backend "http"`, run-token auth); terraform outputs travel as + lease-published job-output secrets. No AWS, no Secrets Manager, no + long-lived provider tokens anywhere. +- **Resume-capable CI**: exec-id is the GitHub run id (no attempt suffix) and + every lane passes `--retry` — `gh run rerun --failed` is a true resume. +- **Parked-by-default fleet** at instantiation; the bootstrap un-parks it in + one push. `cloudflare-domain` is the only component parked by design. diff --git a/flows/README.md b/flows/README.md index 092c07d..8dda1fe 100644 --- a/flows/README.md +++ b/flows/README.md @@ -4,12 +4,17 @@ This product boots **entirely against its Orun Cloud workspace** (the `workspace:` in `intent.yaml`; a fork carries provenance in `.orun/provenance.*.lock` and `ai/context/fork-from-baseline.md`) — CI holds no provider credential; every secret is brokered from the workspace's -integrations at run time. Every command below takes the workspace org slug; -the examples write ``. +integrations at run time, and Terraform state lives on the platform +(`backend "http"`). There is no AWS anywhere in the loop. Every command below +takes the workspace org slug; the examples write ``. + +The full operator runbook (fresh product from the blueprint → live baseline) +is [BOOTSTRAP.md](../BOOTSTRAP.md); this file documents the flow itself. ## One-time operator prerequisites -The workflow preflights each of these and stops with instructions if missing: +The workflow preflights each of these; the two console steps can be clicked +*while the flow runs* — preflight polls for up to 10 minutes: 1. **CLI login** — `orun auth login --device`, approve the code at `https://app.orun.dev/cli/device` in a browser session that belongs to the @@ -24,9 +29,6 @@ The workflow preflights each of these and stops with instructions if missing: console (Git Repos) — the CLI cannot grant it. `orun cloud link` must have been run from a clone with a GitHub remote (it records the numeric repo id the OIDC exchange resolves by). -4. **AWS (org-owned, via `aws-admin`)** — the per-repo GitHub-OIDC roles - (`-github-sourceplane--plan`) and the Terraform state prefix. - Without them the `bootstrap` Terraform batch fails at its first plan. ## The workflow @@ -34,39 +36,58 @@ The workflow preflights each of these and stops with instructions if missing: orun workflow run flows/bootstrap-flow.yaml --set org= ``` -- **preflight** — auth, allow-list, integrations present. +- **preflight** — auth, allow-list, then POLLS for ACTIVE Cloudflare + + Supabase connections (up to 10m, printing the console URL) so the OAuth + consents can be granted while the flow runs. - **create-secrets** — five project-rung secrets from the integrations (workers-deploy / hyperdrive-edit / account-id / management-access / org-id). Brokered and fact templates only: no value is ever typed or seen. -- **batches** — every deployable component starts *parked* - (`subscribe.environments: []`, originals stashed in - `flows/subscriptions/`). Each batch step un-parks a group, opens a PR, - requires its checks green, merges, then requires the merge's main - convergence run (the deploy + per-worker smoke) green before the next - batch starts: + Idempotent and self-healing: a key whose integration connection was revoked + (health `orphaned`) is revoked and recreated against the current ACTIVE + connection. +- **deploy-all** — ONE main push: `park.mjs unpark --all` restores every + deployable component's environment subscriptions (`cloudflare-domain` stays + parked until the product zone exists in the Cloudflare account), and + `tooling/bootstrap/cycle-break.mjs --strip` removes the service-binding + feedback edges so first-boot workers deploy in DAG order without + referencing not-yet-existing services. +- **converge** — waits for that push's main convergence run: the platform DAG + orders supabase → db-migrate/cloudflare-hyperdrive → the worker fleet → + api-edge → web-console-next inside the ONE run; terraform applies + lease-publish their outputs (`SUPABASE_*`, `WIRING_*`) and downstream lanes + resolve them at claim time. `flows/converge.sh` auto-resumes the run + through transient failures (`gh run rerun --failed`; CI is + exec-id + `--retry` resume-capable), budget 3 — a real regression still + fails every resume and surfaces. +- **restore-bindings** — second (final) push: `cycle-break.mjs --restore` + puts the stripped service bindings back (every worker they point at now + exists) and requires that convergence green too. +- **verify-live** — curls the deployed api-edge `/health` + console endpoints + on both environments and fails on any dead endpoint. - | # | batch | components | - |---|---|---| - | 1 | infra-foundation | cloudflare-kv | - | 2 | data-a | supabase (its secretOutputs lease-publish the DB creds the next batch reads) | - | 3 | data-b | db-migrate, cloudflare-hyperdrive | - | 4 | workers-a | policy, membership, events, projects | - | 5 | workers-b | identity, config, webhooks, notifications, metering, admin | - | 6 | workers-c | billing, integrations | - | 7 | edge | api-edge | - | 8 | console | web-console-next | +Every step is also runnable by hand (`flows/converge.sh [run-id] [resumes]`, +`flows/create-secrets.sh `, `node flows/park.mjs unpark --all`), and a +failed flow resumes by re-running the workflow — completed steps are no-ops +(the fleet is already un-parked, `cycle-break --strip/--restore` are +idempotent, and secrets self-heal). `flows/batch.sh ` +remains for *incremental* rollouts after the baseline is live (it PRs a batch +and waits for checks + convergence), but the bootstrap itself no longer +batches. - `cloudflare-domain` stays parked until the `lumen.app` zone exists in the - Cloudflare account. -- **verify-live** — curls the deployed api-edge + console endpoints on both - environments and fails on any dead endpoint. +## First-boot ordering guarantees (why one run works) -Every step is also runnable by hand (`flows/batch.sh `, -`flows/create-secrets.sh `), and a failed batch resumes by re-running the -workflow — completed batches are no-ops (their components are already -un-parked and deployed). `create-secrets` also self-heals: a key whose -integration connection was revoked (health `orphaned`) is revoked and -recreated against the current ACTIVE connection. +- Terraform lanes publish their consumable outputs as **job-output secrets** + (lease-bound, published by the runner on job success) — no separate sync + step, no ordering gap: a downstream lane's `secretEnv` resolves at claim + time, after its dependency completed inside the same run. +- Adoption (`infra/terraform/*/terraform/adopt.tf`): when the platform state + is empty but the provider already has the resource (a baseline predating + the platform backend, or a recovered workspace), the plan imports it + instead of colliding — fresh products create normally. +- The smoke step retries with backoff (stack-tectonic ≥ 0.18.1), riding out + first-deploy workers.dev propagation. +- `--retry` lanes wait for their upstreams' retry claims during a resume + (orun ≥ v2.49.0) instead of dying on the resume race. ## Runtime worker secrets (wire-now-seed-later) diff --git a/flows/bootstrap-flow.yaml b/flows/bootstrap-flow.yaml index 22beff3..69e40a7 100644 --- a/flows/bootstrap-flow.yaml +++ b/flows/bootstrap-flow.yaml @@ -3,19 +3,25 @@ kind: Workflow metadata: name: bootstrap-flow # Full first-boot of this product against its Orun Cloud workspace (the -# `workspace:` in intent.yaml): verify CLI auth, repo allow-listing, and provider -# integrations; create the five provider secrets from those integrations -# (brokered — no value is ever typed or seen); then deploy the platform in -# dependency-ordered batches, one PR each, requiring the PR checks AND the -# merge's main convergence run green before the next batch starts. +# `workspace:` in intent.yaml), in ONE convergence run: verify CLI auth, repo +# allow-listing, and provider integrations (waiting while the operator clicks +# the two OAuth consents if needed); create the five provider secrets from +# those integrations (brokered — no value is ever typed or seen); un-park the +# ENTIRE deployable fleet in a single main push with the service-binding +# feedback edges stripped; ride the one main convergence run to green (the +# platform DAG orders supabase → db-migrate/hyperdrive → workers → edge → +# console, and job-output secrets publish/resolve inside the run) — resuming +# it through transient failures; then restore the feedback bindings with a +# second push and verify the live endpoints. # # Run it from the repo root: orun workflow run flows/bootstrap-flow.yaml -# Operator prerequisites (once, documented in flows/README.md): +# Operator prerequisites (once, documented in flows/README.md and BOOTSTRAP.md): # - orun auth login --device (approve at app.orun.dev/cli/device; # a browser session in the workspace — # the Chrome extension works when the # operator is an agent) -# - Cloudflare + Supabase connected in the workspace (console → Integrations) +# - Cloudflare + Supabase connected in the workspace (console → Integrations; +# preflight WAITS for these, so they can be clicked while the flow runs) # - This repo allow-listed for CI OIDC (console → Git Repos; `orun cloud # check` verifies — the CLI cannot grant it, the console can) inputs: @@ -43,62 +49,90 @@ steps: echo "repo not allow-listed for {{ inputs.org }}: allow it in the console (Git Repos) — the CLI cannot grant this" >&2 exit 1 } - echo "── integrations (ACTIVE connections required)" - list="$(orun integrations list --org "{{ inputs.org }}" --json)" + echo "── integrations (ACTIVE connections; polling up to 10m so consents can be clicked now)" active() { - printf '%s' "$list" | python3 -c "import json,sys; rows=json.load(sys.stdin); sys.exit(0 if any(r.get('provider')=='$1' and r.get('status')=='active' for r in rows) else 1)" + orun integrations list --org "{{ inputs.org }}" --json | + python3 -c "import json,sys; rows=json.load(sys.stdin); sys.exit(0 if any(r.get('provider')=='$1' and r.get('status')=='active' for r in rows) else 1)" } - active cloudflare || { echo "no ACTIVE Cloudflare connection in {{ inputs.org }}: console → Integrations → Cloudflare → Connect (paste an Account API token per the in-console recipe)" >&2; exit 1; } - active supabase || { echo "no ACTIVE Supabase connection in {{ inputs.org }}: console → Integrations → Supabase → Connect (OAuth; pick the organization that should own this product's projects)" >&2; exit 1; } - timeout: 2m + deadline=$(( $(date +%s) + 600 )) + while :; do + missing="" + active cloudflare || missing="cloudflare" + active supabase || missing="${missing:+$missing }supabase" + [ -z "$missing" ] && break + if [ "$(date +%s)" -ge "$deadline" ]; then + echo "still missing ACTIVE connection(s) after 10m: $missing — connect at https://app.orun.dev/orgs/{{ inputs.org }}/integrations (Cloudflare: paste an Account API token per the in-console recipe; Supabase: OAuth, pick the organization that should own this product's projects)" >&2 + exit 1 + fi + echo "waiting for connection(s): $missing → https://app.orun.dev/orgs/{{ inputs.org }}/integrations" + sleep 20 + done + echo "preflight ok" + timeout: 12m + # Brokered provider secrets (idempotent: self-heals orphans against the + # CURRENT active connections — the create is skipped for healthy keys). - name: create-secrets needs: [preflight] run: ["/bin/sh", "-c", "flows/create-secrets.sh {{ inputs.org }}"] timeout: 5m - # ── Deploy batches (dependency order; each waits for PR checks AND the - # merge's main convergence run — the deploy — to be green). ── - - name: batch-infra-foundation + # ── Single-run deploy ──────────────────────────────────────────────────── + # One main push un-parks the whole fleet (cloudflare-domain stays parked — + # its zone must exist first) with the service-binding feedback edges + # stripped (tooling/bootstrap/cycle-break.mjs), so first-boot workers can + # deploy in DAG order without referencing not-yet-existing services. The + # merge's convergence run IS the deploy: terraform applies lease-publish + # their outputs (SUPABASE_*, WIRING_*) and downstream lanes resolve them at + # claim time, inside the same run. + - name: deploy-all needs: [create-secrets] - run: ["/bin/sh", "-c", "flows/batch.sh infra-foundation cloudflare-kv"] - timeout: 45m - # Split data batches: supabase must APPLY (its secretOutputs lease-publish - # SUPABASE_PROJECT_REF/DB_PASSWORD/DB_URL) before db-migrate and hyperdrive - # can even PLAN — their secretEnv refs resolve at job start. - - name: batch-data-a - needs: [batch-infra-foundation] - run: ["/bin/sh", "-c", "flows/batch.sh data-a supabase"] - timeout: 45m - - name: batch-data-b - needs: [batch-data-a] - run: ["/bin/sh", "-c", "flows/batch.sh data-b db-migrate cloudflare-hyperdrive"] - timeout: 60m - - name: batch-workers-a - needs: [batch-data-b] - run: ["/bin/sh", "-c", "flows/batch.sh workers-a policy-worker membership-worker events-worker projects-worker"] - timeout: 60m - - name: batch-workers-b - needs: [batch-workers-a] - run: ["/bin/sh", "-c", "flows/batch.sh workers-b identity-worker config-worker webhooks-worker notifications-worker metering-worker admin-worker"] - timeout: 90m - - name: batch-workers-c - needs: [batch-workers-b] - run: ["/bin/sh", "-c", "flows/batch.sh workers-c billing-worker integrations-worker"] + run: + - /bin/sh + - -c + - | + set -e + git checkout main -q && git pull -q + node flows/park.mjs unpark --all + node tooling/bootstrap/cycle-break.mjs --strip + if git diff --quiet && git diff --cached --quiet; then + echo "deploy-all: fleet already unparked — nothing to push" + exit 0 + fi + git add -A + git commit -q -m "bootstrap: enable full fleet (single-run deploy, feedback edges stripped)" \ + -m "Un-parks every deployable component except cloudflare-domain and strips the service-binding feedback edges; this push's main convergence run deploys the entire platform in dependency order." + git push -q origin main + timeout: 5m + + - name: converge + needs: [deploy-all] + run: ["/bin/sh", "-c", "flows/converge.sh '' 3"] + timeout: 120m + + # Second (final) push: put the stripped service bindings back — every worker + # they point at now exists — and require that convergence green too. + - name: restore-bindings + needs: [converge] + run: + - /bin/sh + - -c + - | + set -e + git checkout main -q && git pull -q + node tooling/bootstrap/cycle-break.mjs --restore + if git diff --quiet; then + echo "restore-bindings: nothing stripped — already restored" + exit 0 + fi + git add -A + git commit -qm "bootstrap: restore service-binding feedback edges (final wiring)" + git push -q origin main + flows/converge.sh '' 2 timeout: 60m - - name: batch-edge - needs: [batch-workers-c] - run: ["/bin/sh", "-c", "flows/batch.sh edge api-edge"] - timeout: 45m - - name: batch-console - needs: [batch-edge] - run: ["/bin/sh", "-c", "flows/batch.sh console web-console-next"] - timeout: 45m - # cloudflare-domain stays parked: its zone (lumen.app) must exist in the - # Cloudflare account first — see the restore note in its component.yaml. - name: verify-live - needs: [batch-console] + needs: [restore-bindings] run: - /bin/sh - -c diff --git a/flows/converge.sh b/flows/converge.sh new file mode 100755 index 0000000..137652d --- /dev/null +++ b/flows/converge.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Wait for a main convergence run and require it green — RESUMING it through +# transient failures instead of giving up. The CI is resume-capable (exec-id = +# run id, `orun run --retry`): `gh run rerun --failed` re-opens exactly the +# failed lanes of the SAME orun execution, memoized jobs stay done, and +# dependents wait for their upstreams' retry claims. So a convergence that +# trips on something transient (propagation, a rate-limited resolve, a runner +# eviction) heals in place — a real regression still fails every resume and +# surfaces after the budget. +# +# flows/converge.sh [run-id] [max-resumes] +# +# With no run-id, waits for the newest run on main. Requires: gh authenticated. +set -euo pipefail + +run_id="${1:-}" +max_resumes="${2:-3}" + +if [ -z "${run_id}" ]; then + # The caller just pushed; give GitHub a beat to materialize the run. + sleep 20 + run_id="$(gh run list --branch main --limit 1 --json databaseId --jq '.[0].databaseId')" +fi +echo "convergence run: ${run_id} (resume budget: ${max_resumes})" + +attempt=0 +while :; do + until st="$(gh run view "${run_id}" --json status --jq .status 2>/dev/null)" \ + && [ "${st}" = "completed" ]; do + sleep 40 + done + conclusion="$(gh run view "${run_id}" --json conclusion --jq .conclusion)" + if [ "${conclusion}" = "success" ]; then + echo "✓ convergence green (run ${run_id}, resumes used: ${attempt})" + exit 0 + fi + if [ "${attempt}" -ge "${max_resumes}" ]; then + echo "✕ convergence ${conclusion} after ${attempt} resume(s) (run ${run_id}); failed lanes:" >&2 + gh run view "${run_id}" --json jobs --jq '.jobs[]|select(.conclusion=="failure")|.name' >&2 + exit 1 + fi + attempt=$((attempt + 1)) + echo "↻ convergence ${conclusion} — resuming failed lanes (${attempt}/${max_resumes})" + gh run rerun "${run_id}" --failed + sleep 30 +done diff --git a/flows/park.mjs b/flows/park.mjs index c91bd3f..7bf5ea9 100644 --- a/flows/park.mjs +++ b/flows/park.mjs @@ -82,11 +82,30 @@ if (mode === "park") { } console.log(`${parked} component(s) parked`); } else if (mode === "unpark") { - const names = process.argv.slice(3); + let names = process.argv.slice(3); if (names.length === 0) { - console.error("unpark: name at least one component"); + console.error("unpark: name at least one component (or --all)"); process.exit(2); } + // `unpark --all`: everything stashed, except components parked by design. + // cloudflare-domain stays parked until its zone exists in the Cloudflare + // account (see the restore note in its component.yaml) — the single-run + // bootstrap must not trip over an absent zone. + const KEEP_PARKED = new Set(["cloudflare-domain"]); + if (names.length === 1 && names[0] === "--all") { + names = fs.existsSync(STASH_DIR) + ? fs + .readdirSync(STASH_DIR) + .filter((f) => f.endsWith(".yaml")) + .map((f) => f.replace(/\.yaml$/, "")) + .filter((nm) => !KEEP_PARKED.has(nm)) + .sort() + : []; + if (names.length === 0) { + console.log("unpark --all: nothing stashed (already unparked)"); + process.exit(0); + } + } for (const nm of names) { const stash = path.join(STASH_DIR, `${nm}.yaml`); if (!fs.existsSync(stash)) { @@ -116,6 +135,6 @@ if (mode === "park") { console.log(`${parked ? "parked" : "live "} ${name}`); } } else { - console.error("usage: park.mjs park | unpark … | status"); + console.error("usage: park.mjs park | unpark …|--all | status"); process.exit(2); } diff --git a/infra/terraform/cloudflare-hyperdrive/terraform/.terraform.lock.hcl b/infra/terraform/cloudflare-hyperdrive/terraform/.terraform.lock.hcl index 39479b2..c133371 100644 --- a/infra/terraform/cloudflare-hyperdrive/terraform/.terraform.lock.hcl +++ b/infra/terraform/cloudflare-hyperdrive/terraform/.terraform.lock.hcl @@ -5,7 +5,9 @@ provider "registry.terraform.io/cloudflare/cloudflare" { version = "4.52.7" constraints = "~> 4.30" hashes = [ + "h1:pPItIWii5oymR+geZB219ROSPuSODPLTlM4S/u8xLvM=", "h1:uUUa9dY0XQOycI8pxg16PFFtL0WCTi9uEJz8trTQ7pU=", + "h1:y3rV8KF2q6GEMANNlf5EkKJurlfbKlIKpjGcdxoy7pQ=", "zh:0c904ce31a4c6c4a5b3bf7ff1560e77c0cc7e2450c8553ded8e8c90398e1418b", "zh:36183d310c36373fe4cb936b83c595c6fd3b0a94bc7827f28e5789ccbf59752e", "zh:556a568a6f0235e8f41647de9e4d3a1e7b1d6502df8b19b54ec441f1c653ea10", @@ -24,3 +26,25 @@ provider "registry.terraform.io/cloudflare/cloudflare" { ] } +provider "registry.terraform.io/hashicorp/external" { + version = "2.4.0" + constraints = "~> 2.3" + hashes = [ + "h1:AmY6ZeIvqoTT5ZjzD+P49PeQH6Va1QLMkX+7MUQfYoA=", + "h1:K0eLC86zbhVoyS4THmY00KJZKAQORuz6dt9Ro3xo/wA=", + "h1:gXyK3ZkweDqkwEV9waEDWpljUY4yZXi/nRUSEuJn83k=", + "zh:0772afb42b658468ac5e15df33bf2080456f8f0b8ab163bfe9c50d2b2ea02135", + "zh:0ac31a9aaa43dfcff5944b791596cdc94e153348e4bb4642282d034dff548134", + "zh:32d8492b1bdcc956ca3c6d00c6392d0a83942ff11d4820c7ee63ca6796e06950", + "zh:3c0482e894429f528ce6655a76ab0d8a9f7c0dacc6c828865e1515d4a7dbb852", + "zh:61e68100b4db2f930b31491f23c602126382fd5e51252be1b551f0e17f8ddbee", + "zh:6d60f615a0ad85eb962c9eb94f25e3eba7a72684ce276ba5dfb23f36b295a8f8", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:9ced2745eb5f1346203027d2dd7bf856ad1d279a25730ff7dbc6eec187aaca0c", + "zh:a8378558a177d43f55aa0d79d4fae91a704695122a1b109668c1daa8fb76f09d", + "zh:aadd98086133d3ebea67437d56512fdcc6dfb3bd34dfc23f276c0db9272e27b4", + "zh:beff701b653841e70441978137768f54e7dc6c27e7bf12a4589087f01f5bbcee", + "zh:c91c2223b29fdbc0044d20e1936ccc051d010727a13f2ff1e75e51f09bff33a3", + "zh:d491f9c2d32a39dc4031628469ae7c8aec0074312a7c1f0286b173cdcf854a54", + ] +} diff --git a/infra/terraform/cloudflare-hyperdrive/terraform/adopt.tf b/infra/terraform/cloudflare-hyperdrive/terraform/adopt.tf new file mode 100644 index 0000000..1c58837 --- /dev/null +++ b/infra/terraform/cloudflare-hyperdrive/terraform/adopt.tf @@ -0,0 +1,40 @@ +# --- Self-healing adoption (AWS-free state seeding) --- +# +# Same pattern as cloudflare-kv/terraform/adopt.tf: when the platform state +# does not yet track the Hyperdrive config but Cloudflare already has one +# under this name, import it at plan time instead of creating a duplicate. +# Fresh products resolve to id = "" and create normally; a resource already in +# state short-circuits the lookup. Note the origin password still comes from +# config — after adoption the first apply re-asserts the origin credentials +# from SUPABASE_DB_PASSWORD, which is exactly the re-sync the cutover needs. + +data "external" "adopt_hyperdrive_config" { + program = ["bash", "-c", <<-EOT + set -euo pipefail + name="$(jq -r .name)" + state_file="$(mktemp)" + trap 'rm -f "$state_file"' EXIT + code="$(curl -s -o "$state_file" -w '%%{http_code}' \ + -u "$TF_HTTP_USERNAME:$TF_HTTP_PASSWORD" "$TF_HTTP_ADDRESS" || echo 000)" + if [ "$code" = "200" ] && jq -e \ + '[.resources[]? | select(.type == "cloudflare_hyperdrive_config" and .name == "postgres")] | length > 0' \ + "$state_file" >/dev/null 2>&1; then + jq -n '{id: ""}' + exit 0 + fi + resp="$(curl -fsS --retry 3 -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/hyperdrive/configs")" + printf '%s' "$resp" | jq -c --arg n "$name" \ + '{id: ([.result[] | select(.name == $n) | .id] | first // "")}' + EOT + ] + query = { + name = local.hyperdrive_name + } +} + +import { + for_each = toset(compact([data.external.adopt_hyperdrive_config.result.id])) + to = cloudflare_hyperdrive_config.postgres + id = "${var.cloudflare_account_id}/${each.value}" +} diff --git a/infra/terraform/cloudflare-hyperdrive/terraform/main.tf b/infra/terraform/cloudflare-hyperdrive/terraform/main.tf index f974af9..cb5d5db 100644 --- a/infra/terraform/cloudflare-hyperdrive/terraform/main.tf +++ b/infra/terraform/cloudflare-hyperdrive/terraform/main.tf @@ -10,6 +10,10 @@ terraform { source = "cloudflare/cloudflare" version = "~> 4.30" } + external = { + source = "hashicorp/external" + version = "~> 2.3" + } } } diff --git a/infra/terraform/cloudflare-kv/terraform/.terraform.lock.hcl b/infra/terraform/cloudflare-kv/terraform/.terraform.lock.hcl index 39479b2..c133371 100644 --- a/infra/terraform/cloudflare-kv/terraform/.terraform.lock.hcl +++ b/infra/terraform/cloudflare-kv/terraform/.terraform.lock.hcl @@ -5,7 +5,9 @@ provider "registry.terraform.io/cloudflare/cloudflare" { version = "4.52.7" constraints = "~> 4.30" hashes = [ + "h1:pPItIWii5oymR+geZB219ROSPuSODPLTlM4S/u8xLvM=", "h1:uUUa9dY0XQOycI8pxg16PFFtL0WCTi9uEJz8trTQ7pU=", + "h1:y3rV8KF2q6GEMANNlf5EkKJurlfbKlIKpjGcdxoy7pQ=", "zh:0c904ce31a4c6c4a5b3bf7ff1560e77c0cc7e2450c8553ded8e8c90398e1418b", "zh:36183d310c36373fe4cb936b83c595c6fd3b0a94bc7827f28e5789ccbf59752e", "zh:556a568a6f0235e8f41647de9e4d3a1e7b1d6502df8b19b54ec441f1c653ea10", @@ -24,3 +26,25 @@ provider "registry.terraform.io/cloudflare/cloudflare" { ] } +provider "registry.terraform.io/hashicorp/external" { + version = "2.4.0" + constraints = "~> 2.3" + hashes = [ + "h1:AmY6ZeIvqoTT5ZjzD+P49PeQH6Va1QLMkX+7MUQfYoA=", + "h1:K0eLC86zbhVoyS4THmY00KJZKAQORuz6dt9Ro3xo/wA=", + "h1:gXyK3ZkweDqkwEV9waEDWpljUY4yZXi/nRUSEuJn83k=", + "zh:0772afb42b658468ac5e15df33bf2080456f8f0b8ab163bfe9c50d2b2ea02135", + "zh:0ac31a9aaa43dfcff5944b791596cdc94e153348e4bb4642282d034dff548134", + "zh:32d8492b1bdcc956ca3c6d00c6392d0a83942ff11d4820c7ee63ca6796e06950", + "zh:3c0482e894429f528ce6655a76ab0d8a9f7c0dacc6c828865e1515d4a7dbb852", + "zh:61e68100b4db2f930b31491f23c602126382fd5e51252be1b551f0e17f8ddbee", + "zh:6d60f615a0ad85eb962c9eb94f25e3eba7a72684ce276ba5dfb23f36b295a8f8", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:9ced2745eb5f1346203027d2dd7bf856ad1d279a25730ff7dbc6eec187aaca0c", + "zh:a8378558a177d43f55aa0d79d4fae91a704695122a1b109668c1daa8fb76f09d", + "zh:aadd98086133d3ebea67437d56512fdcc6dfb3bd34dfc23f276c0db9272e27b4", + "zh:beff701b653841e70441978137768f54e7dc6c27e7bf12a4589087f01f5bbcee", + "zh:c91c2223b29fdbc0044d20e1936ccc051d010727a13f2ff1e75e51f09bff33a3", + "zh:d491f9c2d32a39dc4031628469ae7c8aec0074312a7c1f0286b173cdcf854a54", + ] +} diff --git a/infra/terraform/cloudflare-kv/terraform/adopt.tf b/infra/terraform/cloudflare-kv/terraform/adopt.tf new file mode 100644 index 0000000..54882dc --- /dev/null +++ b/infra/terraform/cloudflare-kv/terraform/adopt.tf @@ -0,0 +1,43 @@ +# --- Self-healing adoption (AWS-free state seeding) --- +# +# When the platform state does not yet track the namespace but Cloudflare +# already has one under this title (a baseline whose state predates the +# platform backend, or a recovered workspace), the create would collide with +# the duplicate-title guard (error 10014). Instead: look the namespace up at +# plan time with the job's brokered credentials and import it. Fresh products +# resolve to id = "" and create normally, and a resource already tracked in +# state short-circuits the lookup — so this block is inert everywhere except +# the one case it exists for. Both lookups run inside the job: process env +# carries the brokered CLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID and the +# TF_HTTP_* state credentials, so no extra secrets and no AWS access. + +data "external" "adopt_idempotency_namespace" { + program = ["bash", "-c", <<-EOT + set -euo pipefail + title="$(jq -r .title)" + state_file="$(mktemp)" + trap 'rm -f "$state_file"' EXIT + code="$(curl -s -o "$state_file" -w '%%{http_code}' \ + -u "$TF_HTTP_USERNAME:$TF_HTTP_PASSWORD" "$TF_HTTP_ADDRESS" || echo 000)" + if [ "$code" = "200" ] && jq -e \ + '[.resources[]? | select(.type == "cloudflare_workers_kv_namespace" and .name == "api_edge_idempotency")] | length > 0' \ + "$state_file" >/dev/null 2>&1; then + jq -n '{id: ""}' + exit 0 + fi + resp="$(curl -fsS --retry 3 -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/storage/kv/namespaces?per_page=100")" + printf '%s' "$resp" | jq -c --arg t "$title" \ + '{id: ([.result[] | select(.title == $t) | .id] | first // "")}' + EOT + ] + query = { + title = local.idempotency_namespace_title + } +} + +import { + for_each = toset(compact([data.external.adopt_idempotency_namespace.result.id])) + to = cloudflare_workers_kv_namespace.api_edge_idempotency + id = "${var.cloudflare_account_id}/${each.value}" +} diff --git a/infra/terraform/cloudflare-kv/terraform/main.tf b/infra/terraform/cloudflare-kv/terraform/main.tf index 1dba000..9be8b64 100644 --- a/infra/terraform/cloudflare-kv/terraform/main.tf +++ b/infra/terraform/cloudflare-kv/terraform/main.tf @@ -10,6 +10,10 @@ terraform { source = "cloudflare/cloudflare" version = "~> 4.30" } + external = { + source = "hashicorp/external" + version = "~> 2.3" + } } } diff --git a/infra/terraform/supabase/terraform/.terraform.lock.hcl b/infra/terraform/supabase/terraform/.terraform.lock.hcl index 36d0ff4..5b4468d 100644 --- a/infra/terraform/supabase/terraform/.terraform.lock.hcl +++ b/infra/terraform/supabase/terraform/.terraform.lock.hcl @@ -1,11 +1,36 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. +provider "registry.terraform.io/hashicorp/external" { + version = "2.4.0" + constraints = "~> 2.3" + hashes = [ + "h1:AmY6ZeIvqoTT5ZjzD+P49PeQH6Va1QLMkX+7MUQfYoA=", + "h1:K0eLC86zbhVoyS4THmY00KJZKAQORuz6dt9Ro3xo/wA=", + "h1:gXyK3ZkweDqkwEV9waEDWpljUY4yZXi/nRUSEuJn83k=", + "zh:0772afb42b658468ac5e15df33bf2080456f8f0b8ab163bfe9c50d2b2ea02135", + "zh:0ac31a9aaa43dfcff5944b791596cdc94e153348e4bb4642282d034dff548134", + "zh:32d8492b1bdcc956ca3c6d00c6392d0a83942ff11d4820c7ee63ca6796e06950", + "zh:3c0482e894429f528ce6655a76ab0d8a9f7c0dacc6c828865e1515d4a7dbb852", + "zh:61e68100b4db2f930b31491f23c602126382fd5e51252be1b551f0e17f8ddbee", + "zh:6d60f615a0ad85eb962c9eb94f25e3eba7a72684ce276ba5dfb23f36b295a8f8", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:9ced2745eb5f1346203027d2dd7bf856ad1d279a25730ff7dbc6eec187aaca0c", + "zh:a8378558a177d43f55aa0d79d4fae91a704695122a1b109668c1daa8fb76f09d", + "zh:aadd98086133d3ebea67437d56512fdcc6dfb3bd34dfc23f276c0db9272e27b4", + "zh:beff701b653841e70441978137768f54e7dc6c27e7bf12a4589087f01f5bbcee", + "zh:c91c2223b29fdbc0044d20e1936ccc051d010727a13f2ff1e75e51f09bff33a3", + "zh:d491f9c2d32a39dc4031628469ae7c8aec0074312a7c1f0286b173cdcf854a54", + ] +} + provider "registry.terraform.io/hashicorp/random" { version = "3.9.0" constraints = "~> 3.0" hashes = [ "h1:OO+IuvQJSPmWdN8AyyIEvPJbLvDQpgX/zbktoa9KsJE=", + "h1:UlBuNVuCGJ39tTv2c5gz2NRZnQbXfbIWbTzWcth5o74=", + "h1:lVDv+0AjDjrLfpmaJbWqUmIw/k3/AHXLc3N4m55SNdo=", "zh:161ad0bd9a75768c82f53fb6e7172a9d8be2d4889b012645a34795031aaf1bf1", "zh:19dc9a5b17729725ccfc4f45b0500af0ee5bc6b6b160c7adb8f2bf617d2c80ea", "zh:269eda8fe42daa7974d5a34d166c3ba9defe80cde86c01e4dadcfdf2e1f05e5f", @@ -23,23 +48,26 @@ provider "registry.terraform.io/hashicorp/random" { } provider "registry.terraform.io/supabase/supabase" { - version = "1.9.1" - constraints = "~> 1.0" + version = "1.5.1" + constraints = "~> 1.5.1" hashes = [ - "h1:ZTmVkODWeBvyPqaAGTHgUayfnL9gsZ/cXKtTT1ZemAo=", - "zh:0e4bedace67d4688bfdf677c71fdd93029c6393820af921121aa9d86d3f371c2", - "zh:0ec2d76a30b2d72ed6670c35897bec6a511b8ad129ec9e9c6a2f341345972aeb", - "zh:168d40688eb60e770c24b992f56d698acaf7f5675dc984d020f699a0cdb3edbd", - "zh:3e08bee9d3f3f8e7216acd4a32dcdd7005635d59f029cb5e73aa9a8cf3e41559", - "zh:4ba28495302c905b9f76c1a0c9bc021d26fbfaea2e015ed0983b394152041b35", - "zh:5e3e09f145b5799bf6ba5217660370127265d1ef93be6c8aeb45e189180a7d65", - "zh:61638e29fca95fa472e870c0b58a6ebe8e067800aadbb98e4ed8f09a5189ffdb", + "h1:A4kqrLbrPeyfOXuk2eN8L15ue7JSRtkV/FhqFyY9Dzg=", + "h1:X1mvSyjaWyaJmhijgpsXMP7UMIE5kuwbq4wfjpfcxBA=", + "h1:rTxTmQ7IGlQNi5H1oS8e2+AgmiXeWM+jnJN5TNS69vU=", + "zh:1834f1cfbab811ca53eae9bdb6485032a674aef5d84fa7fe65342f72e50e3880", + "zh:1d53f3c0c6d82c50a7a29d658f77f3e44db0c0196714f0891ec2cadfdeb58764", + "zh:1f4dda08ccb39790f3c11fb6b4006827f09bfb8fb85082886eb46803f44b1722", + "zh:38dcad29e57c4d06374f4b557108d0877bb3ba628878c6648508110ff34f3d0f", + "zh:63782085e8da25d78de2a080072e7cc6a35c781c2bdb04f5ca46f65a6d6988d6", + "zh:79d7e5fe9d1571aa5357f98b97e3f12e61f68500e4270e855c1bc5e4cc772a56", "zh:890df766e9b839623b1f0437355032a3c006226a6c200cd911e15ee1a9014e9f", - "zh:aa37f6b5b33a6cf098e25d27f2f16f2efae50ed3e59e678a0c1fb9710bd22e6b", - "zh:b89e4e52055e826bbca37eaa1bba60d6a52cdefb6ad34e008dafa49988fb745a", - "zh:c3a819ff921f00ed46b826b1fb773ca9d29a6f2b14906cd27eddcb6304da8bae", - "zh:c3d4c661f1c55688501aa0384a1f3c3bf9be659f0291729e603794486a1ee080", - "zh:fc08601bf928df6c9561e2bcc69dae9ebc85e9f4e8a316d31cc2e0f313dc83b8", - "zh:fd9d56093feb8a66eb40aa0a8f9821974797364cf99f971eba4e4c4db253ad3a", + "zh:8c8560f8df33c087ab9133fc32b68c4c16c8c1bc32b546c91dc98c2b39f80c3a", + "zh:ab4189d0c843166a1b4eaefe817192c8cee954c441a3a86ef5118931ce0e9d71", + "zh:c9037e7cfadc468ac961786af7e3004c08196543416842746f95b929e6118fd6", + "zh:ca9546b9ca3a27634a6eb37e069e58a44a26fe8c3c6539a17dc4b628ad6e7ae0", + "zh:d0301164210ea4ed0567c9c1c751d1e250ab163a8b0edd8cf256d25d54e4d1e5", + "zh:f048d76cca0083a2b91bef304949d182b3395b3bc013cc8aa1505219538953a1", + "zh:f85b905aa8f049a8769bac933a56ae0ca9c5bb74a6c2376cf9ee4ac8ecf50126", + "zh:fd26c6f338bfab77b145e0755dc39d9873aec8219b3b53909da418250d013973", ] } diff --git a/infra/terraform/supabase/terraform/adopt.tf b/infra/terraform/supabase/terraform/adopt.tf new file mode 100644 index 0000000..38a1ee0 --- /dev/null +++ b/infra/terraform/supabase/terraform/adopt.tf @@ -0,0 +1,44 @@ +# --- Self-healing adoption (AWS-free state seeding) --- +# +# Same pattern as cloudflare-kv/terraform/adopt.tf: when the platform state +# does not yet track the Supabase project but the organization already has one +# under this name, import it by ref at plan time instead of colliding with the +# duplicate-name guard. Fresh products resolve to id = "" and create normally; +# a resource already in state short-circuits the lookup. +# +# Cutover caveat: database_password is config-driven (random_password). After +# adoption the first apply RESETS the database password to the newly generated +# one and publishes it through the job-output secrets — db-migrate, hyperdrive +# and the worker fleet re-wire from those in the same run, but anything still +# consuming the pre-adoption credentials breaks until that run converges. + +data "external" "adopt_project" { + program = ["bash", "-c", <<-EOT + set -euo pipefail + name="$(jq -r .name)" + state_file="$(mktemp)" + trap 'rm -f "$state_file"' EXIT + code="$(curl -s -o "$state_file" -w '%%{http_code}' \ + -u "$TF_HTTP_USERNAME:$TF_HTTP_PASSWORD" "$TF_HTTP_ADDRESS" || echo 000)" + if [ "$code" = "200" ] && jq -e \ + '[.resources[]? | select(.type == "supabase_project" and .name == "this")] | length > 0' \ + "$state_file" >/dev/null 2>&1; then + jq -n '{id: ""}' + exit 0 + fi + resp="$(curl -fsS --retry 3 -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \ + "https://api.supabase.com/v1/projects")" + printf '%s' "$resp" | jq -c --arg n "$name" --arg org "$SUPABASE_ORG_ID" \ + '{id: ([.[] | select(.name == $n and .organization_id == $org) | .id] | first // "")}' + EOT + ] + query = { + name = local.project_name + } +} + +import { + for_each = toset(compact([data.external.adopt_project.result.id])) + to = supabase_project.this + id = each.value +} diff --git a/infra/terraform/supabase/terraform/main.tf b/infra/terraform/supabase/terraform/main.tf index 0903f89..13bf094 100644 --- a/infra/terraform/supabase/terraform/main.tf +++ b/infra/terraform/supabase/terraform/main.tf @@ -20,6 +20,10 @@ terraform { source = "hashicorp/random" version = "~> 3.0" } + external = { + source = "hashicorp/external" + version = "~> 2.3" + } } } diff --git a/intent.yaml b/intent.yaml index 994f283..d7e76be 100644 --- a/intent.yaml +++ b/intent.yaml @@ -31,7 +31,7 @@ compositions: # a commit here. Bumping the tag is the deliberate upgrade step. - name: stack-tectonic kind: oci - ref: oci://ghcr.io/sourceplane/stack-tectonic:0.18.0 + ref: oci://ghcr.io/sourceplane/stack-tectonic:0.18.1 resolution: precedence: - stack-tectonic diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index d8d0ef5..e6411ee 100644 Binary files a/tooling/rebrand/rebrand.mjs and b/tooling/rebrand/rebrand.mjs differ