Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
107 changes: 107 additions & 0 deletions BOOTSTRAP.md
Original file line number Diff line number Diff line change
@@ -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 `<repo>-stage` / `<repo>-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 <workspace>/<repo> AND allow-lists CI
orun cloud check --org <org> # verifies the OIDC allow-list took
```

## 3. Run the workflow

```bash
orun workflow run flows/bootstrap-flow.yaml --set org=<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 <org>`
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 <KEY> --org <org> --env <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 <org>` 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 `<repo>-<env>` (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 <run-id>` 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.
87 changes: 54 additions & 33 deletions flows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<org>`.
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 `<org>`.

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
Expand All @@ -24,49 +29,65 @@ 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
(`<env>-github-sourceplane-<repo>-plan`) and the Terraform state prefix.
Without them the `bootstrap` Terraform batch fails at its first plan.

## The workflow

```bash
orun workflow run flows/bootstrap-flow.yaml --set org=<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 <org>`, `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 <name> <components…>`
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 <name> <components…>`,
`flows/create-secrets.sh <org>`), 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)

Expand Down
Loading
Loading