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
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the SITE_NAME seam in apps/web/lib/site.ts (the page's heading and <title>); `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in this repository's source link.",
"slug": "postgres-kysely",
"pascal": "PostgresKysely",
"productName": "Postgres on Cloudflare",
"domain": "postgres-kysely.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
134 changes: 134 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# postgres-kysely

Vercel's [Postgres + Kysely Next.js Starter](https://github.com/vercel/examples/tree/main/storage/postgres-kysely)
— a page that reads a `profiles` table through Kysely and seeds it with
three rows the first time it finds it empty — on **Cloudflare Workers +
Static Assets** through [`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare),
with its Postgres a **Supabase** project's database reached through
**Cloudflare Hyperdrive**. Terraform provisions both per environment and
Orun's `db-migrate` applies the schema, all on every merge to `main`.

## Live deployment

<!-- 02-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace, what the database check reports and the secrets the product
uses into
[ai/context/deployment.md](ai/context/deployment.md); how the product deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

## What is here

| Surface | Where |
|---|---|
| The product's name (the page's heading and its title) | `apps/web/lib/site.ts` |
| The page and the table | `apps/web/app/page.tsx`, `apps/web/components/table.tsx` |
| The per-request Kysely client (Hyperdrive first, `POSTGRES_URL` fallback) and its types, the seed | `apps/web/lib/kysely.ts`, `apps/web/lib/seed.ts` |
| The database check the deploy smoke-tests | `apps/web/app/api/health/route.ts` |
| Workers build and deploy contract | `apps/web/next.config.mjs`, `open-next.config.ts`, `wrangler.template.jsonc` → `wrangler.jsonc`, `component.yaml` |
| The schema as migrations, and their runner | `packages/db` (`@saas/db`); `apps/web/scripts/migrate.mjs` applies the same files locally through Kysely's `Migrator` |
| The Supabase project, the Hyperdrive config, the migration step | `infra/terraform/supabase`, `infra/terraform/cloudflare-hyperdrive`, `infra/db-migrate` |
| Tests | `tests/web`, `tests/db` (vitest) |

## Getting started

```bash
pnpm install
pnpm run wire:fixture # re-render apps/web/wrangler.jsonc from its template (it is committed)
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next
```

The build needs no database: the page renders per request.

## Running it locally

You need a Postgres on `localhost:54322` — the Supabase CLI's default
(`supabase start`) — or any Postgres whose URL you put in `POSTGRES_URL`.

1. **Schema.** Kysely's `Migrator` applies the migrations to `POSTGRES_URL`
(default `postgres://postgres:postgres@localhost:54322/postgres`):

```bash
pnpm --filter @app/web db:migrate
```

It applies `packages/db/src/migrations` — the very files CI applies to
the real databases — and records them in its own `kysely` schema. The
page never creates the table; until the migrations have run it says so.

2. **Run.** Either Next's dev server, which gets the Worker's bindings
through `getCloudflareContext()` (the `HYPERDRIVE` binding points at
`localhost:54322` through `wrangler.jsonc`'s `localConnectionString`):

```bash
pnpm --filter @app/web dev # http://localhost:3000
```

or the built Worker under `wrangler dev`:

```bash
pnpm build
pnpm --filter @app/web preview # http://localhost:8787
```

The first page view seeds the three profiles; `/api/health` says whether
the database is reachable and migrated.

## How it deploys

Merges to `main` converge through [Orun](https://github.com/sourceplane/orun):
`.github/workflows/ci.yml` plans the changed components and runs each lane
against the workspace in `intent.yaml`. Per environment the order is
enforced — **the Supabase project, then the Hyperdrive config over its
database, then the migrations, then the Worker** — because each reads what
the one before it published: the project's ref and password, the Hyperdrive
id the Worker binds, the table the page queries. `stage` deploys first and
`prod` once stage has converged on the same commit; `dev` only verifies.
Every deploy is smoke-tested over HTTP: the home page's table, and
`/api/health`, which answers only when the Worker reaches a migrated
database.

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The
Cloudflare tokens and account id and the Supabase access token and org id
are brokered per run from the workspace's connections; the Supabase
project's credentials and the Hyperdrive id are published by the Terraform
applies as orun secrets. Nothing provider-shaped is stored in the repository
or in GitHub, and the app needs no secret of its own.

Every table in `public` has row-level security and no policy, so Supabase's
Data API (which serves `public` to the project's anon key) returns none of
it; the app connects as the table's owner and is not affected.

**Deploy by hand.** Orunbase's **Deploy** button on a component, or **Run
workflow** on the CI workflow in GitHub's Actions tab (on `main`), runs
`ci.yml` for the environment and components you pick, and each one deploys
exactly as a merge would deploy it. Leave the component blank to redeploy
every component in that environment, with nothing changed: after rotating a
secret, say. A component with nothing to run in that environment (a test
suite in `prod`) is left out with a notice.

## Custom domain

The app answers on workers.dev from its first deploy. To serve it on your
own domain, attach the domain to the Worker in Cloudflare (Workers & Pages →
`postgres-kysely-web-prod` → Settings → Domains & Routes), then set
`SITE_URL` under that environment's `env:` in `intent.yaml` — the page's Open
Graph image link is absolute — and merge.

The repository also names the domain in one place, `BASE_DOMAIN` under each
environment's `env:` in `intent.yaml`, which the product was born with as the
reserved placeholder `postgres-kysely.example.com`. Nothing builds a
URL from it — the origin is `SITE_URL` — so replacing it moves nothing by
itself; it records the domain. Replace it with yours in the same pull request
as `SITE_URL`.

## CI

| Workflow | What it runs |
|---|---|
| `ci.yml` | the Orun pipeline, and the only workflow: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes — the app built and dry-deployed for each environment, both Terraform roots checked and planned, the migrations planned and their checksums verified — with nothing applied or deployed. They do not typecheck, lint or run the tests: run `pnpm typecheck`, `pnpm lint` and `pnpm test` before you push (Getting started, above). A merge applies, migrates and deploys stage → prod |
32 changes: 32 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Task contract template for the 01-product landing.
# Unbound to a key on purpose: `orun.task/ensure@v1` seals and attaches it to
# the key the allocator issues. It lives under `.baseline/`, not `tasks/`,
# because `tasks/` is this repository's own work tree (`intent.yaml` `work:`),
# where an unkeyed contract is an error. gates: [] is a DECLARATION — merge
# alone finishes this task; the main convergence is the gate the bootstrap
# watches, not one the plane observes as a PR check.
#
# The whole product in one landing. `affects` names COMPONENTS, by
# metadata.name — every one the bootstrap's convergence plans on stage and
# prod (the two test packages verify on dev, which the bootstrap keeps off
# main until 02-docs, so a marker on them would re-plan nothing): the phase's
# retouch hook reads this list to decide which component.yaml files get the
# redeploy marker, so a re-run after a failed convergence has a diff and
# re-plans exactly these — the deploy set and the task plane's statement of
# the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The product's repository is born and linked, the whole product lands in one pull request, and one convergence provisions Supabase and Hyperdrive, migrates the schema and deploys the app on stage and prod
affects:
- supabase
- cloudflare-hyperdrive
- db
- db-migrate
- web
doneWhen:
- repo pushed, main pinned as default, workspace linked
- SUPABASE_PROJECT_REF, SUPABASE_DB_PASSWORD, SUPABASE_DB_URL and WIRING_CLOUDFLARE_HYPERDRIVE published on stage and prod
- migrations applied and the app deployed and smoke-tested on stage and prod, in the order supabase → cloudflare-hyperdrive → db-migrate → web
- the home page (the table, seeded on its first request) and /api/health answer on both workers.dev URLs
gates: []
14 changes: 14 additions & 0 deletions .baseline/tasks/02-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Task contract template for the 02-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the product's repo, and the bootstrap's deferrals are put back
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
- intent.yaml
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
149 changes: 149 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — this repository tested as a BASELINE: that its
# build document parses with the orun a bootstrap actually runs, that its card
# agrees with it, that every component is placed by exactly one phase, that a
# placed tree comes up branded and carrying nothing of the factory, that the
# product's own push-to-main plan deploys infra before app, and that the
# product installs, builds, migrates, deploys (dry), serves, and reads and
# writes its database through the page's own query path.
#
# ─── WHY THIS IS NOT IN ci.yml ────────────────────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every product built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a product
# they would be steps that cannot pass, red on its very first pull request. This
# file is in the blueprint's `ignore` list, and `testing/coverage.test.sh`
# fails on any workflow that reads `testing/` and is not.

on:
push:
branches: [main]
pull_request:

concurrency:
group: baseline-ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
# Tier 0. bash, python3 and git; node for the tools. No workspace install,
# no network, no credential — the job that most certainly fails a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v5
with:
node-version: 22
# setup-node v5 turns on the pnpm cache by itself when package.json
# names a packageManager, and then fails on a runner with no pnpm.
# This job installs nothing.
package-manager-cache: false
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer)
run: |
set -euo pipefail
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
for t in manifest phases coverage rebrand retouch bootstrap-defer; do
echo "── $t"
bash "testing/$t.test.sh"
done
# Every component's docs/{overview,architecture,runbook}.md is generated
# from what the component declares (its manifest, Worker config,
# Terraform, migrations, package scripts). A pull request that changes
# one of those facts without regenerating the pages fails here.
- name: Component docs match their manifests
run: python3 tooling/catalog/gen-component-docs.py --check

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at the bootstrap floor (BOOTSTRAP.md), not the product's lane pin:
# every test here reads YAML with PyYAML, which parses anything well-formed;
# only the pinned orun can say whether the document is one a bootstrap can
# run. `--status` parses it, validates every hook against the action
# registry, compiles every `when` and narration template, and writes
# nothing. Then the leak gate (what a product would carry) and the
# placement tier (the offline bootstrap: both phases placed and finished by
# the blueprint's own hooks, then the product's own `orun plan` for the
# 01-product merge — supabase, then cloudflare-hyperdrive, then db-migrate,
# then web, enforced — and a --resume that changes nothing). The floor is
# v2.88.0 (the task set-up in the background, the landings checked in the
# box, the deploy credentials minted in one `secrets` reconcile per
# provider), newer than the product's lane pin (v2.78.4, ci.yml), so the
# product's own plans here read the per-edge `modeRules` as its CI does.
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
# This job installs nothing either: with no lockfile hook the offline
# bootstrap never runs pnpm, so there is no store, and the pnpm cache
# setup-node v5 turns on by itself (package.json names a packageManager)
# fails the job saving a path that does not exist whenever no earlier
# cache exists for the lockfile.
package-manager-cache: false
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
# Required inputs must be supplied for the document to resolve; the
# values are arbitrary and nothing is written.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-postgres \
--set "productname=Acme Cloud" \
--set githuborg=acme-inc
- name: the leak gate — what a product carries
run: bash testing/leak.test.sh
- name: placement — the offline bootstrap, and the product's own plan
run: |
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/placement.test.sh

# Tier 2. THE PRODUCT IT PRODUCES WORKS: the 01-product landing installed,
# its fixture rendered, type-checked, linted, tested and built (its own pull
# request runs `plan` alone, and the landing is checked in the box with
# `orun validate` and `orun plan`); the migrations applied by the product's
# own runner to a local Postgres (through a stand-in for the one Supabase
# Management API endpoint it calls); the stage lane's own structure check,
# build, output check and dry deploy in the job tree orun stages; and the
# built Worker served over that database — its smoke, every route, the
# page's first-request seed raced by concurrent requests, and the Data API's
# roles shut out by row-level security.
# Pinned at the bootstrap floor (v2.88.0): the offline bootstrap reads the
# blueprint, and the floor is newer than the product's lane pin (v2.78.4),
# which is all the lane steps need. The runner image carries PostgreSQL 16
# (not started); the test starts its own on a random port.
product:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: e2e — the bootstrapped product builds, migrates, deploys (dry) and serves
run: |
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/e2e.test.sh
Loading
Loading