From 1d33e4ff102615f964f2b4752e45a4022a0b1433 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 23:44:23 +0000 Subject: [PATCH] BA2: D1, KV and R2 from Terraform, the schema through db-migrate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The three bindings the example asked its owner to create by hand, as Terraform roots Orun applies per environment: turso-starter's cloudflare-d1, kv-redis-starter's cloudflare-kv and blob-starter's cloudflare-r2 (as ai-emoji-generator combined them), each lease-publishing the wiring document the Worker's config renders from. infra/db-migrate runs packages/db's runner over D1's REST API after the database's apply — better-auth's tables and the generated auth secret — so the auth app never meets a database without its schema. apps/web now waits on all four on a merge to main (enforced; advisory on a pull request) and renders stage and prod from their wiring documents, dev from the fixture; the product's own plan orders the roots, then the migrations, then the Worker. Every root passes terraform validate. This also restores the packages/db, tests/db and tests/web component manifests in full: BA1 landed them cut short by a faulty edit, unnoticed because CI plans nothing while the workspace is the placeholder. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn --- README.md | 22 ++- apps/web/component.yaml | 53 ++++++- apps/web/wrangler.template.jsonc | 6 +- infra/db-migrate/component.yaml | 69 +++++++++ infra/terraform/cloudflare-d1/component.yaml | 53 +++++++ .../cloudflare-d1/terraform/adopt.tf | 43 ++++++ .../cloudflare-d1/terraform/backend.tf | 5 + .../terraform/cloudflare-d1/terraform/main.tf | 138 ++++++++++++++++++ .../cloudflare-d1/terraform/outputs.tf | 2 + .../cloudflare-d1/terraform/variables.tf | 2 + infra/terraform/cloudflare-kv/component.yaml | 51 +++++++ .../cloudflare-kv/terraform/adopt.tf | 43 ++++++ .../cloudflare-kv/terraform/backend.tf | 5 + .../terraform/cloudflare-kv/terraform/main.tf | 138 ++++++++++++++++++ .../cloudflare-kv/terraform/outputs.tf | 2 + .../cloudflare-kv/terraform/variables.tf | 2 + infra/terraform/cloudflare-r2/component.yaml | 54 +++++++ .../cloudflare-r2/terraform/adopt.tf | 38 +++++ .../cloudflare-r2/terraform/backend.tf | 5 + .../terraform/cloudflare-r2/terraform/main.tf | 124 ++++++++++++++++ .../cloudflare-r2/terraform/outputs.tf | 2 + .../cloudflare-r2/terraform/variables.tf | 2 + packages/db/component.yaml | 16 ++ specs/epics/README.md | 2 +- .../IMPLEMENTATION-STATUS.md | 5 +- specs/epics/better-auth-starter/README.md | 2 +- tests/db/component.yaml | 14 ++ tests/web/component.yaml | 14 ++ 28 files changed, 900 insertions(+), 12 deletions(-) create mode 100644 infra/db-migrate/component.yaml create mode 100644 infra/terraform/cloudflare-d1/component.yaml create mode 100644 infra/terraform/cloudflare-d1/terraform/adopt.tf create mode 100644 infra/terraform/cloudflare-d1/terraform/backend.tf create mode 100644 infra/terraform/cloudflare-d1/terraform/main.tf create mode 100644 infra/terraform/cloudflare-d1/terraform/outputs.tf create mode 100644 infra/terraform/cloudflare-d1/terraform/variables.tf create mode 100644 infra/terraform/cloudflare-kv/component.yaml create mode 100644 infra/terraform/cloudflare-kv/terraform/adopt.tf create mode 100644 infra/terraform/cloudflare-kv/terraform/backend.tf create mode 100644 infra/terraform/cloudflare-kv/terraform/main.tf create mode 100644 infra/terraform/cloudflare-kv/terraform/outputs.tf create mode 100644 infra/terraform/cloudflare-kv/terraform/variables.tf create mode 100644 infra/terraform/cloudflare-r2/component.yaml create mode 100644 infra/terraform/cloudflare-r2/terraform/adopt.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/backend.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/main.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/outputs.tf create mode 100644 infra/terraform/cloudflare-r2/terraform/variables.tf diff --git a/README.md b/README.md index 1e5709d..6222793 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ MIT, © 2025 Zach Grimaldi (`apps/web/LICENSE`). | The site's name and source link | `apps/web/src/lib/site.ts` | | The health route the deploy's smoke reads | `apps/web/src/app/api/health/route.ts` | | Workers build, bindings and deploy contract | `apps/web/next.config.mjs`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ the committed `wrangler.jsonc`), `component.yaml` | -| The schema (migrations) and the runner that applies them over the D1 REST API | `packages/db` | +| The D1 database, the KV namespace and the R2 bucket (stage, prod) | `infra/terraform/cloudflare-d1`, `cloudflare-kv`, `cloudflare-r2` | +| The schema (migrations) and the runner that applies them over the D1 REST API | `packages/db`, run by `infra/db-migrate` | | Tests | `tests/web` (the providers, the generated secret, the health route, the redirects), `tests/db` (the migrations through the runner, into real SQLite) | ## Getting started @@ -60,10 +61,27 @@ No mail sender is configured, so email addresses are not verified. |---|---| | `wrangler.toml` with placeholder database, namespace and bucket ids | `wrangler.template.jsonc` → `wrangler.jsonc`, rendered per environment from wiring documents (`tooling/wire`); the binding names (`DATABASE`, `KV`, `R2_BUCKET`) are the example's | | `better-auth-cloudflare: file:../../` (the repository's own build) | `better-auth-cloudflare@0.4.1` from npm, exact, with `better-auth` and the Drizzle adapter at `1.7.3` | -| drizzle-kit migrations, `wrangler d1 migrations apply` | `packages/db` migrations — `010_auth` (the three drizzle files' end state), `020_app_secrets` — applied locally by `db:migrate:local` | +| drizzle-kit migrations, `wrangler d1 migrations apply` | `packages/db` migrations — `010_auth` (the three drizzle files' end state), `020_app_secrets` — applied by `infra/db-migrate` before the Worker deploys, and locally by `db:migrate:local` | +| a database, a namespace and a bucket created by hand in the dashboard | `infra/terraform/cloudflare-{d1,kv,r2}`, applied by Orun before the migrations and the Worker | | `BETTER_AUTH_SECRET` typed into `.dev.vars` | generated once per database by `020_app_secrets`; a `BETTER_AUTH_SECRET` secret wins | | `BETTER_AUTH_URL` / `BETTER_AUTH_TRUSTED_ORIGINS` vars | optional; unset, the base URL and the trusted origin are the origin the request came to | | anonymous sign-in only | anonymous, email and password, and GitHub/Google when their keys are stored | | Next.js 15 `middleware.ts` | Next.js 16 `proxy.ts`, the same self-request to `/api/auth/get-session` | | `next build` ignoring lint and type errors | `pnpm lint` and `pnpm typecheck` clean; the build checks types | | `[placement] mode = "smart"` | not set: D1, KV and R2 are in the Worker's own account | + +## How the data reaches the Worker + +``` +infra/terraform/cloudflare-d1 ──apply──► WIRING_CLOUDFLARE_D1 ─┬─► infra/db-migrate apply: packages/db's runner → POST …/d1/database//query +infra/terraform/cloudflare-kv ──apply──► WIRING_CLOUDFLARE_KV ─┤ (better-auth's tables, the generated auth secret) +infra/terraform/cloudflare-r2 ──apply──► WIRING_CLOUDFLARE_R2 ─┴─► apps/web build: tooling/wire/live.mjs → wrangler.jsonc with the ids + (dev, verify-only, renders the fixture) → next build → OpenNext → deploy +``` + +Each reader declares an enforced `dependsOn` on what it reads on a push to +`main` (advisory on a pull request), so one convergence per environment runs +the three roots, then the migrations, then the Worker. `wrangler.jsonc` is +committed as the fixture render of `wrangler.template.jsonc`, because the +deploy lane's `verify-app-structure` step checks the config exists before it +builds. diff --git a/apps/web/component.yaml b/apps/web/component.yaml index 687b44e..8224b85 100644 --- a/apps/web/component.yaml +++ b/apps/web/component.yaml @@ -14,6 +14,47 @@ spec: # Its own lane per environment: the Next.js build is the longest job in the # plan, and a shared lane would wait on it. lane: isolated + # INFRA BEFORE APP. The Worker binds the D1 database by id, the KV namespace + # by id and the R2 bucket by name, each rendered into its config during the + # build from the wiring document its root lease-publishes after its apply; + # and better-auth reads its tables and the generated auth secret, which + # db-migrate creates in that database. A job resolves its secrets when it + # STARTS, so on a merge to main this deploy waits for all four (enforced) — + # one convergence runs cloudflare-d1 → db-migrate, cloudflare-kv and + # cloudflare-r2 → web per environment, and the documents and the schema are + # there. A pull request deploys nothing, so nothing on one waits (advisory). + dependsOn: + - component: cloudflare-d1 + mode: enforced + modeRules: + - mode: advisory + when: + triggerRef: github-pull-request + - component: cloudflare-kv + mode: enforced + modeRules: + - mode: advisory + when: + triggerRef: github-pull-request + - component: cloudflare-r2 + mode: enforced + modeRules: + - mode: advisory + when: + triggerRef: github-pull-request + - component: db-migrate + mode: enforced + modeRules: + - mode: advisory + when: + triggerRef: github-pull-request + secretEnv: + WIRING_CLOUDFLARE_D1_STAGE: "secret://better-auth-starter/better-auth-starter/stage/WIRING_CLOUDFLARE_D1" + WIRING_CLOUDFLARE_D1_PROD: "secret://better-auth-starter/better-auth-starter/prod/WIRING_CLOUDFLARE_D1" + WIRING_CLOUDFLARE_KV_STAGE: "secret://better-auth-starter/better-auth-starter/stage/WIRING_CLOUDFLARE_KV" + WIRING_CLOUDFLARE_KV_PROD: "secret://better-auth-starter/better-auth-starter/prod/WIRING_CLOUDFLARE_KV" + WIRING_CLOUDFLARE_R2_STAGE: "secret://better-auth-starter/better-auth-starter/stage/WIRING_CLOUDFLARE_R2" + WIRING_CLOUDFLARE_R2_PROD: "secret://better-auth-starter/better-auth-starter/prod/WIRING_CLOUDFLARE_R2" # The OAuth providers' client ids and secrets, stored per environment as the # product's secrets (README → Sign-in providers). BEST-EFFORT, # wire-now-seed-later: a key nobody has stored is skipped when the job @@ -67,16 +108,20 @@ spec: workersDevSubdomain: your-workers-subdomain installCommand: pnpm install --frozen-lockfile - # Render this environment's wrangler config, then build. Until the D1, KV - # and R2 roots land (BA2) every environment renders from the committed - # fixture. The OAuth secrets never reach the build (`env -u`): the Worker + # Render this environment's wrangler config, then build. stage and prod + # render from the wiring documents their cloudflare-d1, cloudflare-kv and + # cloudflare-r2 applies published (secretEnv above, resolved before the + # job's first step); dev, which no root applies to and which only + # verifies, renders from the committed fixture. The committed + # wrangler.jsonc (the fixture render) is what the composition's + # verify-app-structure step finds before this runs. The OAuth secrets never reach the build (`env -u`): the Worker # reads them at request time, so neither a bundle nor the bundler's cache # holds them. Then each one the environment has goes to the Worker as a # SECRET (tooling/wire/worker-secrets.mjs: `wrangler secret bulk`, the # values over stdin) before the composition deploys it. Only the deploy # lane holds a Cloudflare credential, so a verify lane builds the same and # pushes nothing. - buildCommand: node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components cloudflare-d1,cloudflare-kv,cloudflare-r2 --env "${ORUN_ENVIRONMENT}" --fixture wiring.fixture.json --fixture-envs dev,stage,prod && env -u GITHUB_CLIENT_ID -u GITHUB_CLIENT_SECRET -u GOOGLE_CLIENT_ID -u GOOGLE_CLIENT_SECRET -u BETTER_AUTH_SECRET pnpm exec turbo run build --filter=@app/web && node ../../tooling/wire/worker-secrets.mjs --secret GITHUB_CLIENT_ID --secret GITHUB_CLIENT_SECRET --secret GOOGLE_CLIENT_ID --secret GOOGLE_CLIENT_SECRET --secret BETTER_AUTH_SECRET --worker "better-auth-starter-web-${ORUN_ENVIRONMENT}" --config wrangler.jsonc + buildCommand: node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components cloudflare-d1,cloudflare-kv,cloudflare-r2 --env "${ORUN_ENVIRONMENT}" --fixture wiring.fixture.json --fixture-envs dev && env -u GITHUB_CLIENT_ID -u GITHUB_CLIENT_SECRET -u GOOGLE_CLIENT_ID -u GOOGLE_CLIENT_SECRET -u BETTER_AUTH_SECRET pnpm exec turbo run build --filter=@app/web && node ../../tooling/wire/worker-secrets.mjs --secret GITHUB_CLIENT_ID --secret GITHUB_CLIENT_SECRET --secret GOOGLE_CLIENT_ID --secret GOOGLE_CLIENT_SECRET --secret BETTER_AUTH_SECRET --worker "better-auth-starter-web-${ORUN_ENVIRONMENT}" --config wrangler.jsonc # Smoke: the sign-in page renders to its end (`` — a render that # throws partway through a streamed page still sent a 200), and diff --git a/apps/web/wrangler.template.jsonc b/apps/web/wrangler.template.jsonc index 221c243..0f3e2e6 100644 --- a/apps/web/wrangler.template.jsonc +++ b/apps/web/wrangler.template.jsonc @@ -1,7 +1,9 @@ // The source of wrangler.jsonc, which tooling/wire renders from it: from // wiring.fixture.json for local work (`pnpm run wire:fixture`, committed as -// that render) — and on every Orun lane, once the Terraform roots exist, from -// the wiring documents they lease-publish. Edit this file, never +// that render), and on every Orun lane from the wiring documents the +// `cloudflare-d1`, `cloudflare-kv` and `cloudflare-r2` Terraform roots +// lease-publish (WIRING_CLOUDFLARE_{D1,KV,R2}_) — dev, which no root +// applies to, from the fixture (component.yaml's buildCommand). Edit this file, never // wrangler.jsonc. The workers-assets composition deploys one environment per // job with no wrangler `--env`, so `__ENV__` names the environment this is // rendered for. diff --git a/infra/db-migrate/component.yaml b/infra/db-migrate/component.yaml new file mode 100644 index 0000000..cf7122c --- /dev/null +++ b/infra/db-migrate/component.yaml @@ -0,0 +1,69 @@ +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: db-migrate + description: Applies better-auth's schema and the generated auth secret (packages/db's migrations) to the stage and prod Cloudflare D1 databases + labels: + domain: infra + scope: database + team: platform + layer: data + +spec: + type: db-migrate + lifecycle: production + owner: platform + domain: infra + + # THE SCHEMA BETWEEN THE DATABASE AND THE APP. Migrations target the + # database the `cloudflare-d1` component creates, and find it through the + # wiring document that component lease-publishes after its apply — and a + # job resolves its secrets when it STARTS, so on a merge to main this waits + # for that environment's apply (enforced). apps/web waits on this the same + # way, so one convergence runs cloudflare-d1 → db-migrate → web per + # environment. A pull request applies nothing (this plans offline there), so + # nothing on one waits (advisory). `db` is the package this builds and runs; + # a change to it re-plans this. + dependsOn: + - component: db + - component: cloudflare-d1 + mode: enforced + modeRules: + - mode: advisory + when: + triggerRef: github-pull-request + + path: packages/db/src/migrations + + parameters: + nodeVersion: "22" + pnpmVersion: "10.12.1" + owner: sourceplane + repo: better-auth-starter + + # Everything the runner needs to reach D1 over the REST API, all resolved + # from orun secrets: the provider credential is minted fresh per run from the + # Cloudflare integration's d1-edit template (the workers-deploy token cannot + # touch D1), the account id is a non-secret connection fact, and the + # database id arrives in the wiring document the cloudflare-d1 component + # lease-publishes. + secretEnv: + CLOUDFLARE_API_TOKEN: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_D1_TOKEN" + CLOUDFLARE_ACCOUNT_ID: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + WIRING_CLOUDFLARE_D1: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/WIRING_CLOUDFLARE_D1" + + subscribe: + environments: + - name: stage + profile: plan + profileRules: + - profile: apply + when: + triggerRef: github-push-main + + - name: prod + profile: plan + profileRules: + - profile: apply + when: + triggerRef: github-push-main diff --git a/infra/terraform/cloudflare-d1/component.yaml b/infra/terraform/cloudflare-d1/component.yaml new file mode 100644 index 0000000..369faa7 --- /dev/null +++ b/infra/terraform/cloudflare-d1/component.yaml @@ -0,0 +1,53 @@ +apiVersion: sourceplane.io/v1 +kind: Component + +metadata: + name: cloudflare-d1 + description: Provisions the Cloudflare D1 database for stage and prod — better-auth's users, sessions, accounts and files, and the generated auth secret + labels: + domain: infra + scope: runtime-database + +spec: + type: terraform + lifecycle: production + owner: platform + domain: infra + + parameters: + orgName: sourceplane + stackName: cloudflare-d1 + terraformDir: terraform + terraformVersion: "1.15.3" + repo: better-auth-starter + # SEC-JOB: the wiring document (database id/name) is lease-published + # post-apply; worker deploys read it back as WIRING_CLOUDFLARE_D1_, + # and db-migrate reads it to find the database it migrates. + secretOutputs: "WIRING_CLOUDFLARE_D1=wiring" + + # The Cloudflare Terraform provider authenticates via the CLOUDFLARE_API_TOKEN + # env var, resolved by orun from the project-rung brokered secret — minted + # fresh per run from the d1-edit template (D1 Write; the workers-deploy token + # deliberately cannot touch D1). Declared at component level because + # plan-only lanes refresh against the live Cloudflare API too, not just apply. + secretEnv: + CLOUDFLARE_API_TOKEN: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_D1_TOKEN" + # Non-secret connection fact (account-id template). + CLOUDFLARE_ACCOUNT_ID: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + TF_VAR_cloudflare_account_id: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + + subscribe: + environments: + - name: stage + profile: plan-only + profileRules: + - profile: apply + when: + triggerRef: github-push-main + + - name: prod + profile: plan-only + profileRules: + - profile: apply + when: + triggerRef: github-push-main diff --git a/infra/terraform/cloudflare-d1/terraform/adopt.tf b/infra/terraform/cloudflare-d1/terraform/adopt.tf new file mode 100644 index 0000000..08407cd --- /dev/null +++ b/infra/terraform/cloudflare-d1/terraform/adopt.tf @@ -0,0 +1,43 @@ +# --- Self-healing adoption --- +# +# When the platform state does not yet track the database but Cloudflare +# already has one under this name (a re-bootstrap after a torn-down workspace, +# or state recovered onto a fresh backend), the create would collide with the +# duplicate-name guard. Instead: look the database 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 are needed. + +data "external" "adopt_platform_database" { + 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_d1_database" and .name == "platform")] | 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/d1/database?per_page=100")" + printf '%s' "$resp" | jq -c --arg n "$name" \ + '{id: ([.result[] | select(.name == $n) | .uuid] | first // "")}' + EOT + ] + query = { + name = local.database_name + } +} + +import { + for_each = toset(compact([data.external.adopt_platform_database.result.id])) + to = cloudflare_d1_database.platform + id = "${var.cloudflare_account_id}/${each.value}" +} diff --git a/infra/terraform/cloudflare-d1/terraform/backend.tf b/infra/terraform/cloudflare-d1/terraform/backend.tf new file mode 100644 index 0000000..ff89f5f --- /dev/null +++ b/infra/terraform/cloudflare-d1/terraform/backend.tf @@ -0,0 +1,5 @@ +# Terraform backend configuration is provided by Orun at runtime +# through environment variables and automatic backend initialization. +# +# S3 backend details are set via CLI args in the Orun runner. +# Local placeholder file for clarity. diff --git a/infra/terraform/cloudflare-d1/terraform/main.tf b/infra/terraform/cloudflare-d1/terraform/main.tf new file mode 100644 index 0000000..53b644d --- /dev/null +++ b/infra/terraform/cloudflare-d1/terraform/main.tf @@ -0,0 +1,138 @@ +terraform { + required_version = ">= 1.15.0" + + # State lives on the platform (SB1): the runner exports TF_HTTP_* per job, so + # this block stays empty — no S3 bucket, no AWS role, no workspaces. + backend "http" {} + + required_providers { + cloudflare = { + source = "cloudflare/cloudflare" + version = "~> 4.30" + } + external = { + source = "hashicorp/external" + version = "~> 2.3" + } + } +} + +# --- Providers --- + +# Authenticates via the CLOUDFLARE_API_TOKEN env var (provider-native): the +# token is an orun-managed secret resolved into the job env at run time, so it +# never transits Terraform variables. +provider "cloudflare" {} + +# --- Variables (standard Orun parameters) --- + +variable "cloudflare_account_id" { + type = string + sensitive = true + default = "" + description = "Cloudflare account ID (from CLOUDFLARE_ACCOUNT_ID env var)" +} + +variable "orgName" { + type = string + default = "sourceplane" +} + +variable "owner" { + type = string + default = "sourceplane" +} + +variable "repo" { + type = string + default = "better-auth-starter" +} + +variable "namespace" { + type = string + default = "sourceplane" +} + +variable "namespacePrefix" { + type = string + default = "" +} + +variable "lane" { + type = string + default = "verify" +} + +variable "environment" { + type = string + default = "stage" +} + +variable "component" { + type = string + default = "cloudflare-d1" +} + +variable "stackName" { + type = string + default = "cloudflare-d1" +} + +variable "terraformDir" { + type = string + default = "terraform" +} + +variable "terraformVersion" { + type = string + default = "1.15.3" +} + +# --- The site's database --- +# +# One D1 database per deployed environment (stage, prod), bound by apps/web as +# DATABASE. Its schema is not Terraform's: packages/db's migrations create +# better-auth's tables and the generated auth secret, applied by the +# db-migrate component after this apply and before the Worker deploys. + +locals { + # Built on var.repo (the product's repository slug) so the name is unique per + # product. D1 database names are unique per account, and two products may + # share an account. The Worker binds this database by ID through the wiring + # secret, so the name is free to change. + database_name = "${var.namespacePrefix}${var.repo}-${var.environment}" +} + +resource "cloudflare_d1_database" "platform" { + account_id = var.cloudflare_account_id + name = local.database_name +} + +# --- Wiring manifest (BF5, via orun secrets) --- +# +# The consumable outputs are published by the composition's wire-secrets step +# as the WIRING_CLOUDFLARE_D1 secret on the project/{{env}} rung; worker +# deploys read it back as WIRING_CLOUDFLARE_D1_ secretEnv and render the +# committed @@wiring(...)@@ tokens from it (BF6). The `db-migrate` component +# reads the same document (WIRING_CLOUDFLARE_D1) to find the database it +# migrates. + +output "wiring" { + description = "Wiring document for downstream deploy-time binding resolution (pushed to orun secrets)" + value = jsonencode({ + d1_database_id = cloudflare_d1_database.platform.id + d1_database_name = cloudflare_d1_database.platform.name + }) +} + +# --- Outputs (non-secret) --- + +output "d1_database_id" { + description = "Cloudflare D1 database ID (the Workers binding's database_id)" + value = cloudflare_d1_database.platform.id +} + +output "d1_database_name" { + description = "Cloudflare D1 database name (human-readable identifier)" + value = cloudflare_d1_database.platform.name +} diff --git a/infra/terraform/cloudflare-d1/terraform/outputs.tf b/infra/terraform/cloudflare-d1/terraform/outputs.tf new file mode 100644 index 0000000..9653334 --- /dev/null +++ b/infra/terraform/cloudflare-d1/terraform/outputs.tf @@ -0,0 +1,2 @@ +# Output definitions are in main.tf for simplicity. +# This file is a placeholder for consistency with the Orun Terraform pattern. diff --git a/infra/terraform/cloudflare-d1/terraform/variables.tf b/infra/terraform/cloudflare-d1/terraform/variables.tf new file mode 100644 index 0000000..9c92c69 --- /dev/null +++ b/infra/terraform/cloudflare-d1/terraform/variables.tf @@ -0,0 +1,2 @@ +# Variable definitions are in main.tf for simplicity. +# This file is a placeholder for consistency with the Orun Terraform pattern. diff --git a/infra/terraform/cloudflare-kv/component.yaml b/infra/terraform/cloudflare-kv/component.yaml new file mode 100644 index 0000000..a0d42c2 --- /dev/null +++ b/infra/terraform/cloudflare-kv/component.yaml @@ -0,0 +1,51 @@ +apiVersion: sourceplane.io/v1 +kind: Component + +metadata: + name: cloudflare-kv + description: Provisions the Cloudflare KV namespace better-auth keeps its sessions in (stage and prod) + labels: + domain: infra + scope: app-kv + +spec: + type: terraform + lifecycle: production + owner: platform + domain: infra + + parameters: + orgName: sourceplane + stackName: cloudflare-kv + terraformDir: terraform + terraformVersion: "1.15.3" + # SEC-JOB: the wiring document (KV namespace id/title) is lease-published + # post-apply; app deploys read it back as WIRING_CLOUDFLARE_KV_. + secretOutputs: "WIRING_CLOUDFLARE_KV=wiring" + + # The Cloudflare Terraform provider authenticates via the CLOUDFLARE_API_TOKEN + # env var, resolved by orun from the project-rung brokered secret (fresh per + # run, Deploy Workers scope). Declared at component level because plan-only + # lanes refresh against the live Cloudflare API too, not just apply. + secretEnv: + CLOUDFLARE_API_TOKEN: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_API_TOKEN" + # Non-secret connection fact (account-id template) — replaces the ambient + # CLOUDFLARE_ACCOUNT_ID / TF_VAR_cloudflare_account_id CI values. + CLOUDFLARE_ACCOUNT_ID: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + TF_VAR_cloudflare_account_id: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + + subscribe: + environments: + - name: stage + profile: plan-only + profileRules: + - profile: apply + when: + triggerRef: github-push-main + + - name: prod + profile: plan-only + profileRules: + - profile: apply + when: + triggerRef: github-push-main diff --git a/infra/terraform/cloudflare-kv/terraform/adopt.tf b/infra/terraform/cloudflare-kv/terraform/adopt.tf new file mode 100644 index 0000000..7c1fbba --- /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_app_kv" { + 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 == "app_kv")] | 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.app_kv_title + } +} + +import { + for_each = toset(compact([data.external.adopt_app_kv.result.id])) + to = cloudflare_workers_kv_namespace.app_kv + id = "${var.cloudflare_account_id}/${each.value}" +} diff --git a/infra/terraform/cloudflare-kv/terraform/backend.tf b/infra/terraform/cloudflare-kv/terraform/backend.tf new file mode 100644 index 0000000..ff89f5f --- /dev/null +++ b/infra/terraform/cloudflare-kv/terraform/backend.tf @@ -0,0 +1,5 @@ +# Terraform backend configuration is provided by Orun at runtime +# through environment variables and automatic backend initialization. +# +# S3 backend details are set via CLI args in the Orun runner. +# Local placeholder file for clarity. diff --git a/infra/terraform/cloudflare-kv/terraform/main.tf b/infra/terraform/cloudflare-kv/terraform/main.tf new file mode 100644 index 0000000..343efe4 --- /dev/null +++ b/infra/terraform/cloudflare-kv/terraform/main.tf @@ -0,0 +1,138 @@ +terraform { + required_version = ">= 1.15.0" + + # State lives on the platform (SB1): the runner exports TF_HTTP_* per job, so + # this block stays empty — no S3 bucket, no AWS role, no workspaces. + backend "http" {} + + required_providers { + cloudflare = { + source = "cloudflare/cloudflare" + version = "~> 4.30" + } + external = { + source = "hashicorp/external" + version = "~> 2.3" + } + } +} + +# --- Providers --- + +# Authenticates via the CLOUDFLARE_API_TOKEN env var (provider-native): the +# token is an orun-managed secret resolved into the job env at run time, so it +# never transits Terraform variables. +provider "cloudflare" {} + +# --- Variables (standard Orun parameters) --- + +variable "cloudflare_account_id" { + type = string + sensitive = true + default = "" + description = "Cloudflare account ID (from CLOUDFLARE_ACCOUNT_ID env var)" +} + +variable "orgName" { + type = string + default = "sourceplane" +} + +variable "owner" { + type = string + default = "sourceplane" +} + +variable "repo" { + type = string + default = "better-auth-starter" +} + +variable "namespace" { + type = string + default = "sourceplane" +} + +variable "namespacePrefix" { + type = string + default = "" +} + +variable "lane" { + type = string + default = "verify" +} + +variable "environment" { + type = string + default = "stage" +} + +variable "component" { + type = string + default = "cloudflare-kv" +} + +variable "stackName" { + type = string + default = "cloudflare-kv" +} + +variable "terraformDir" { + type = string + default = "terraform" +} + +variable "terraformVersion" { + type = string + default = "1.15.3" +} + +# --- The KV namespace the sessions live in --- +# +# Bound by apps/web as KV: better-auth's secondary storage, through +# better-auth-cloudflare. Keys are the session tokens (and the active-session +# lists per user), each PUT with the session's own `expirationTtl` by +# better-auth — no Terraform-side TTL knob exists for KV namespaces +# themselves. + +locals { + # Built on var.repo (the product's repository slug) so the title is unique per + # product. Cloudflare KV namespace titles must be unique per account, and two + # products may share an account — without the slug the second create fails + # with "a namespace with this account ID and title already exists" (10014). + # The Worker binds this namespace by ID via the wiring secret, so the title is + # free to change. + app_kv_title = "${var.namespacePrefix}${var.repo}-app-kv-${var.environment}" +} + +resource "cloudflare_workers_kv_namespace" "app_kv" { + account_id = var.cloudflare_account_id + title = local.app_kv_title +} + +# --- Wiring manifest (BF5, via orun secrets) --- +# The consumable outputs are published by the composition's wire-secrets step +# as the WIRING_CLOUDFLARE_KV secret on the project/{{env}} rung; worker +# deploys read it back as WIRING_CLOUDFLARE_KV_ secretEnv (BF6). Same +# document shape the Secrets Manager path carried. + +output "wiring" { + description = "Wiring document for downstream deploy-time binding resolution (pushed to orun secrets)" + value = jsonencode({ + app_kv_id = cloudflare_workers_kv_namespace.app_kv.id + app_kv_title = cloudflare_workers_kv_namespace.app_kv.title + }) +} + +# --- Outputs (non-secret) --- + +output "app_kv_id" { + description = "Cloudflare Workers KV namespace ID the storefront's route cache lives in" + value = cloudflare_workers_kv_namespace.app_kv.id +} + +output "app_kv_title" { + description = "Cloudflare Workers KV namespace title (human-readable identifier)" + value = cloudflare_workers_kv_namespace.app_kv.title +} diff --git a/infra/terraform/cloudflare-kv/terraform/outputs.tf b/infra/terraform/cloudflare-kv/terraform/outputs.tf new file mode 100644 index 0000000..9653334 --- /dev/null +++ b/infra/terraform/cloudflare-kv/terraform/outputs.tf @@ -0,0 +1,2 @@ +# Output definitions are in main.tf for simplicity. +# This file is a placeholder for consistency with the Orun Terraform pattern. diff --git a/infra/terraform/cloudflare-kv/terraform/variables.tf b/infra/terraform/cloudflare-kv/terraform/variables.tf new file mode 100644 index 0000000..9c92c69 --- /dev/null +++ b/infra/terraform/cloudflare-kv/terraform/variables.tf @@ -0,0 +1,2 @@ +# Variable definitions are in main.tf for simplicity. +# This file is a placeholder for consistency with the Orun Terraform pattern. diff --git a/infra/terraform/cloudflare-r2/component.yaml b/infra/terraform/cloudflare-r2/component.yaml new file mode 100644 index 0000000..8dbdb27 --- /dev/null +++ b/infra/terraform/cloudflare-r2/component.yaml @@ -0,0 +1,54 @@ +apiVersion: sourceplane.io/v1 +kind: Component + +metadata: + name: cloudflare-r2 + description: Provisions the Cloudflare R2 bucket signed-in users' uploads are kept in (stage and prod) + labels: + domain: infra + scope: app-object-store + +spec: + type: terraform + lifecycle: production + owner: platform + domain: infra + + parameters: + orgName: sourceplane + stackName: cloudflare-r2 + terraformDir: terraform + terraformVersion: "1.15.3" + # SEC-JOB: the wiring document (R2 bucket name) is lease-published + # post-apply; app deploys read it back as WIRING_CLOUDFLARE_R2_. + secretOutputs: "WIRING_CLOUDFLARE_R2=wiring" + + # The Cloudflare Terraform provider authenticates via the CLOUDFLARE_API_TOKEN + # env var, resolved by orun from the project-rung brokered secret — minted + # fresh per run from the r2-data template (Workers R2 Storage Write; the + # workers-deploy token the app deploys with deliberately cannot touch R2). + # adopt.tf's bucket lookup reads the same variable. Declared at component + # level because plan-only lanes refresh against the live Cloudflare API + # too, not just apply. + secretEnv: + CLOUDFLARE_API_TOKEN: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_R2_TOKEN" + # Non-secret connection fact (account-id template) — replaces the ambient + # CLOUDFLARE_ACCOUNT_ID / TF_VAR_cloudflare_account_id CI values. + CLOUDFLARE_ACCOUNT_ID: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + TF_VAR_cloudflare_account_id: "secret://better-auth-starter/better-auth-starter/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID" + + subscribe: + environments: + - name: stage + profile: plan-only + profileRules: + - profile: apply + when: + triggerRef: github-push-main + + - name: prod + profile: plan-only + profileRules: + - profile: apply + when: + triggerRef: github-push-main diff --git a/infra/terraform/cloudflare-r2/terraform/adopt.tf b/infra/terraform/cloudflare-r2/terraform/adopt.tf new file mode 100644 index 0000000..cc3b2ec --- /dev/null +++ b/infra/terraform/cloudflare-r2/terraform/adopt.tf @@ -0,0 +1,38 @@ +# --- Self-healing adoption --- +# +# When the platform state does not yet track the bucket but Cloudflare already +# has one under this name (a re-bootstrap over a torn-down workspace), import +# it 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. + +data "external" "adopt_app_bucket" { + 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_r2_bucket" and .name == "app")] | 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/r2/buckets?per_page=1000")" + printf '%s' "$resp" | jq -c --arg n "$name" \ + '{id: ([.result.buckets[]? | select(.name == $n) | .name] | first // "")}' + EOT + ] + query = { + name = local.bucket_name + } +} + +import { + for_each = toset(compact([data.external.adopt_app_bucket.result.id])) + to = cloudflare_r2_bucket.app + id = "${var.cloudflare_account_id}/${each.value}" +} diff --git a/infra/terraform/cloudflare-r2/terraform/backend.tf b/infra/terraform/cloudflare-r2/terraform/backend.tf new file mode 100644 index 0000000..ff89f5f --- /dev/null +++ b/infra/terraform/cloudflare-r2/terraform/backend.tf @@ -0,0 +1,5 @@ +# Terraform backend configuration is provided by Orun at runtime +# through environment variables and automatic backend initialization. +# +# S3 backend details are set via CLI args in the Orun runner. +# Local placeholder file for clarity. diff --git a/infra/terraform/cloudflare-r2/terraform/main.tf b/infra/terraform/cloudflare-r2/terraform/main.tf new file mode 100644 index 0000000..3a73da9 --- /dev/null +++ b/infra/terraform/cloudflare-r2/terraform/main.tf @@ -0,0 +1,124 @@ +terraform { + required_version = ">= 1.15.0" + + # State lives on the platform: the runner exports TF_HTTP_* per job, so this + # block stays empty — no S3 bucket, no AWS role, no workspaces. + backend "http" {} + + required_providers { + cloudflare = { + source = "cloudflare/cloudflare" + version = "~> 4.30" + } + external = { + source = "hashicorp/external" + version = "~> 2.3" + } + } +} + +# Authenticates via the CLOUDFLARE_API_TOKEN env var (provider-native): the +# token is an orun-managed secret resolved into the job env at run time — +# CLOUDFLARE_R2_TOKEN, minted from the r2-data template (component.yaml). +provider "cloudflare" {} + +variable "cloudflare_account_id" { + type = string + sensitive = true + default = "" + description = "Cloudflare account ID (from CLOUDFLARE_ACCOUNT_ID env var)" +} + +variable "orgName" { + type = string + default = "sourceplane" +} + +variable "owner" { + type = string + default = "sourceplane" +} + +variable "repo" { + type = string + default = "better-auth-starter" +} + +variable "namespace" { + type = string + default = "sourceplane" +} + +variable "namespacePrefix" { + type = string + default = "" +} + +variable "lane" { + type = string + default = "verify" +} + +variable "environment" { + type = string + default = "stage" +} + +variable "component" { + type = string + default = "cloudflare-r2" +} + +variable "stackName" { + type = string + default = "cloudflare-r2" +} + +variable "terraformDir" { + type = string + default = "terraform" +} + +variable "terraformVersion" { + type = string + default = "1.15.3" +} + +# --- The bucket signed-in users' uploads live in --- +# +# One R2 bucket per environment, bound by apps/web as R2_BUCKET: the wrapper's +# R2 plugin writes each upload under `user-files//` and records it in +# D1's user_files; its download endpoint streams it back after the download +# hook allows it. The bucket is private — nothing is served from it but +# through the Worker. + +locals { + # Built on var.repo (the product's repository slug) so the name is unique per + # product. R2 bucket names are unique per account, and two products may + # share an account — without the slug the second product's create would + # find the name taken. The Worker binds the bucket by this name, via the + # wiring secret. + bucket_name = "${var.namespacePrefix}${var.repo}-${var.environment}" +} + +resource "cloudflare_r2_bucket" "app" { + account_id = var.cloudflare_account_id + name = local.bucket_name +} + +# --- Wiring manifest (via orun secrets) --- +# Published post-apply as the WIRING_CLOUDFLARE_R2 secret on the project/{{env}} +# rung; the app's deploy reads it back as WIRING_CLOUDFLARE_R2_ and +# renders its wrangler template from it. + +output "wiring" { + description = "Wiring document for downstream deploy-time binding resolution (pushed to orun secrets)" + value = jsonencode({ + r2_bucket_name = cloudflare_r2_bucket.app.name + }) +} + +output "r2_bucket_name" { + description = "Cloudflare R2 bucket name (the Workers binding's bucket_name)" + value = cloudflare_r2_bucket.app.name +} diff --git a/infra/terraform/cloudflare-r2/terraform/outputs.tf b/infra/terraform/cloudflare-r2/terraform/outputs.tf new file mode 100644 index 0000000..9653334 --- /dev/null +++ b/infra/terraform/cloudflare-r2/terraform/outputs.tf @@ -0,0 +1,2 @@ +# Output definitions are in main.tf for simplicity. +# This file is a placeholder for consistency with the Orun Terraform pattern. diff --git a/infra/terraform/cloudflare-r2/terraform/variables.tf b/infra/terraform/cloudflare-r2/terraform/variables.tf new file mode 100644 index 0000000..9c92c69 --- /dev/null +++ b/infra/terraform/cloudflare-r2/terraform/variables.tf @@ -0,0 +1,2 @@ +# Variable definitions are in main.tf for simplicity. +# This file is a placeholder for consistency with the Orun Terraform pattern. diff --git a/packages/db/component.yaml b/packages/db/component.yaml index 1430a57..d9a7e62 100644 --- a/packages/db/component.yaml +++ b/packages/db/component.yaml @@ -7,3 +7,19 @@ spec: type: turbo-package lifecycle: production owner: platform + domain: data + # Verified where the code is checked — on dev, by every pull request. On a + # merge the db-migrate component builds this package itself in its own job + # before it applies, so stage and prod need no job of their own here. + subscribe: + environments: + - name: dev + profile: quick-check + parameters: + nodeVersion: "22" + pnpmVersion: "10.12.1" + buildCommand: pnpm exec turbo run build --filter=./ + typecheckCommand: pnpm exec turbo run typecheck --filter=./ + labels: + team: platform + layer: data diff --git a/specs/epics/README.md b/specs/epics/README.md index 9944e73..3a84e2f 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`better-auth-starter/`](./better-auth-starter/) | **BA** | In progress (BA1) | zpg6's better-auth-cloudflare OpenNext example — anonymous, email and OAuth sign-in through better-auth, sessions in KV, users in D1, file uploads in R2 — on Cloudflare Workers, and an Orun baseline that instantiates it in one landing | +| [`better-auth-starter/`](./better-auth-starter/) | **BA** | In progress (BA2) | zpg6's better-auth-cloudflare OpenNext example — anonymous, email and OAuth sign-in through better-auth, sessions in KV, users in D1, file uploads in R2 — on Cloudflare Workers, and an Orun baseline that instantiates it in one landing | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/better-auth-starter/IMPLEMENTATION-STATUS.md b/specs/epics/better-auth-starter/IMPLEMENTATION-STATUS.md index 4a79e4d..cb97f34 100644 --- a/specs/epics/better-auth-starter/IMPLEMENTATION-STATUS.md +++ b/specs/epics/better-auth-starter/IMPLEMENTATION-STATUS.md @@ -3,8 +3,8 @@ | Milestone | Status | Shipped in | |---|---|---| | BA0 — the spec | ✅ Shipped | [#1](https://github.com/sourceplane/better-auth-starter/pull/1) | -| BA1 — the auth app on Workers | In progress | | -| BA2 — D1, KV and R2 from Terraform | Not started | | +| BA1 — the auth app on Workers | ✅ Shipped | [#2](https://github.com/sourceplane/better-auth-starter/pull/2) | +| BA2 — D1, KV and R2 from Terraform | In progress | | | BA3 — ready to instantiate | Not started | | | BA4 — a baseline | Not started | | @@ -20,3 +20,4 @@ 8. **The site's name and source link** (`src/lib/site.ts`) head the sign-in page and title the document; the example's "Powered by better-auth-cloudflare" and its GitHub/npm links stay. 9. Small lint fixes in the example's code (an escaped apostrophe, `any` → the file record's type); `debugLogs` and Drizzle's query logger off; `[placement]` not set. 10. **`incremental` off** in `apps/web/tsconfig.json`: its build info prints better-auth's inferred instance type, which overflows the compiler's stack. +11. **Three Terraform roots** — turso-starter's `cloudflare-d1`, kv-redis-starter's `cloudflare-kv`, blob-starter's `cloudflare-r2` (as ai-emoji-generator combined them) — and the `db-migrate` component, in place of the example's hand-made database, namespace and bucket. BA2 also restores the full `packages/db`, `tests/db` and `tests/web` component manifests, which BA1 landed cut short by a faulty edit (CI plans nothing while the workspace is the placeholder, so nothing read them). diff --git a/specs/epics/better-auth-starter/README.md b/specs/epics/better-auth-starter/README.md index 416bf35..656ee28 100644 --- a/specs/epics/better-auth-starter/README.md +++ b/specs/epics/better-auth-starter/README.md @@ -8,7 +8,7 @@ The port keeps the sign-in page, the dashboard (user, geolocation and file-uploa | Field | Value | |-------|-------| -| Status | In progress — BA0 shipped (#1), BA1 | +| Status | In progress — BA0 (#1) and BA1 (#2) shipped, BA2 | | Cluster | **BA** (BA0–BA4) | | Owner(s) | `apps/web` · `tests/web` · `infra/terraform/cloudflare-{d1,kv,r2}` · `packages/db` + `infra/db-migrate` · `tests/db` | | Builds on | `turso-starter`: its scaffolding, its `cloudflare-d1` root and its migrations runner; `kv-redis-starter`'s `cloudflare-kv` root; `blob-starter`'s `cloudflare-r2` root; `saas-starter`'s generated app secret | diff --git a/tests/db/component.yaml b/tests/db/component.yaml index 58706f2..68c8dd1 100644 --- a/tests/db/component.yaml +++ b/tests/db/component.yaml @@ -7,3 +7,17 @@ spec: type: turbo-package lifecycle: production owner: platform + domain: tests + subscribe: + environments: + - name: dev + profile: quick-check + parameters: + nodeVersion: "22" + pnpmVersion: "10.12.1" + buildCommand: pnpm exec turbo run build --filter=./ + typecheckCommand: pnpm exec turbo run typecheck --filter=./ + preBuildCommand: pnpm exec turbo run test --filter=./ + labels: + team: platform + layer: test diff --git a/tests/web/component.yaml b/tests/web/component.yaml index 42d12a1..7bb19df 100644 --- a/tests/web/component.yaml +++ b/tests/web/component.yaml @@ -7,3 +7,17 @@ spec: type: turbo-package lifecycle: production owner: platform + domain: tests + subscribe: + environments: + - name: dev + profile: quick-check + parameters: + nodeVersion: "22" + pnpmVersion: "10.12.1" + buildCommand: pnpm exec turbo run build --filter=./ + typecheckCommand: pnpm exec turbo run typecheck --filter=./ + preBuildCommand: pnpm exec turbo run test --filter=./ + labels: + team: platform + layer: test