diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 1db44f5..274acc5 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -20,6 +20,10 @@ jobs: with: fetch-depth: 0 - uses: sourceplane/orun-action@v1.2.0 + with: + # Match the orun pinned in kiox.lock. The action defaults to `latest`, + # which drifted to v2.38.0 and fails remote-state OIDC exchange with 403. + version: v1.26.0 - run: | orun plan \ --changed \ @@ -56,6 +60,8 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - uses: sourceplane/orun-action@v1.1.0 + with: + version: v1.26.0 - run: | orun run \ --plan plan.json \ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9db4b1 --- /dev/null +++ b/README.md @@ -0,0 +1,183 @@ +# stack-tectonic-flare + +Reusable [Orun](https://github.com/sourceplane/orun) compositions for shipping a multi-tenant SaaS +on Cloudflare — Pages sites, Workers, Turborepo packages, and the Terraform that backs them. + +This repository is both: + +1. **A composition catalog.** Nine compositions under [`stacks/stack-tectonic-flare/`](stacks/stack-tectonic-flare) + describe how a class of component is built, verified, and deployed. +2. **A stack that publishes itself.** Its own CI uses the `publish-stack` composition to package the + catalog and push it to + [`ghcr.io/sourceplane/saas-stack-tectonic-flare`](https://github.com/sourceplane/stack-tectonic-flare/pkgs/container/saas-stack-tectonic-flare), + so consumer repos can pin a version instead of copying YAML. + +## Repository layout + +``` +intent.yaml # environments, trigger bindings, composition sources +kiox.yaml / kiox.lock # pinned orun provider for the kiox workspace +.github/workflows/verify.yml # plan job -> matrix of orun jobs +stacks/stack-tectonic-flare/ + stack.yaml # package identity: name, version, OCI registry target + component.yaml # the one component in this repo: publish this stack + compositions// + composition.yaml # what the composition is: schema, jobs, profiles + schema.yaml # JSON Schema for a component of this type + jobs/*.yaml # JobTemplate: the full ordered step list + profiles/*.yaml # ExecutionProfile: which capabilities run in which lane + README.md # generated-by-hand docs for consumers +``` + +## The catalog + +| Composition | Use it for | Deploy mechanism | Docs | +|---|---|---|---| +| [`cloudflare-pages`](stacks/stack-tectonic-flare/compositions/cloudflare-pages) | A standalone static site in its own directory | Wrangler direct upload | [README](stacks/stack-tectonic-flare/compositions/cloudflare-pages/README.md) | +| [`cloudflare-pages-turbo`](stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo) | A Pages app inside a pnpm + Turborepo monorepo | Wrangler direct upload | [README](stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo/README.md) | +| [`cloudflare-pages-terraform`](stacks/stack-tectonic-flare/compositions/cloudflare-pages-terraform) | A standalone site whose Pages project is Git-connected | Terraform apply | [README](stacks/stack-tectonic-flare/compositions/cloudflare-pages-terraform/README.md) | +| [`cloudflare-pages-turbo-terraform`](stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo-terraform) | A monorepo Pages app whose project is Git-connected | Terraform apply | [README](stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo-terraform/README.md) | +| [`cloudflare-worker`](stacks/stack-tectonic-flare/compositions/cloudflare-worker) | A standalone Worker with its own install/build commands | `wrangler deploy` | [README](stacks/stack-tectonic-flare/compositions/cloudflare-worker/README.md) | +| [`cloudflare-worker-turbo`](stacks/stack-tectonic-flare/compositions/cloudflare-worker-turbo) | A Worker inside a pnpm + Turborepo monorepo | `wrangler deploy` | [README](stacks/stack-tectonic-flare/compositions/cloudflare-worker-turbo/README.md) | +| [`turbo-package`](stacks/stack-tectonic-flare/compositions/turbo-package) | A shared library package — verification only | none | [README](stacks/stack-tectonic-flare/compositions/turbo-package/README.md) | +| [`terraform`](stacks/stack-tectonic-flare/compositions/terraform) | Standalone infrastructure — fmt, init, validate, plan | none | [README](stacks/stack-tectonic-flare/compositions/terraform/README.md) | +| [`publish-stack`](stacks/stack-tectonic-flare/compositions/publish-stack) | Publishing an Orun stack to an OCI registry | `orun publish` | [README](stacks/stack-tectonic-flare/compositions/publish-stack/README.md) | + +Picking between the variants: + +- **`-turbo` or not?** Use a `-turbo` variant when the component lives in a pnpm workspace and is built + through `turbo run`. Those compositions run `pnpm install` at the repo root and target the component + with a Turbo filter. The plain variants take explicit `installCommand` / `buildCommand` strings and + run them inside `siteDir`. +- **`-terraform` or not?** Use a `-terraform` variant when the Cloudflare Pages project is **Git-connected** + (Cloudflare builds on push, and Terraform owns the project resource). Use the plain variant when CI + builds the assets and **direct-uploads** them with Wrangler. + +Full stack-level conventions — the capability model, the shared profile lanes, and how the pieces +resolve — are in [`stacks/stack-tectonic-flare/README.md`](stacks/stack-tectonic-flare/README.md). + +## How a run is produced + +```mermaid +flowchart LR + E[GitHub event] --> T[trigger binding
intent.yaml] + T --> V[environment
dev / staging / production] + V --> P[profile per component
component.yaml subscribe] + P --> C[capability filter] + C --> J[job steps that actually run] +``` + +1. **Trigger binding** — `intent.yaml` maps a GitHub event to a planning scope. A pull request plans only + changed components (`base..head`); a `v*` tag plans everything. +2. **Environment** — each binding activates one environment, which carries a default lane, a namespace + prefix, and approval policy. +3. **Profile** — a component's `subscribe.environments[].profile` picks the execution profile for that + environment; the environment's `defaults.lane` is the fallback for components that don't pin one. +4. **Capabilities** — the profile lists `includeCapabilities`. Steps in the job template whose + `capability` is not in that list are dropped from the plan. One job template therefore serves the + PR lane, the verify lane, and the deploy lane without branching inside the steps. + +| Trigger | Event | Environment | Plan scope | Approval | +|---|---|---|---|---| +| `github-pull-request` | PR opened / synchronize / reopened / ready_for_review against `main` | `dev` (`dev-`) | changed only | no | +| `github-push-main` | push to `main` | `staging` (`stg-`) | changed only | yes | +| `github-tag-release` | push tag `v*` | `production` (`prod-`) | full | yes | + +## CI + +[`.github/workflows/verify.yml`](.github/workflows/verify.yml) has two jobs: + +- **`plan`** runs `orun plan --changed --from-ci github --event-file "$GITHUB_EVENT_PATH"` and uploads + `plan.json`, exposing the planned jobs as a matrix. +- **`run`** fans out over that matrix, one runner per planned job, and executes + `orun run --plan plan.json --job --remote-state`. Check names look like + `stack-tectonic · staging · Publish`. + +If a change touches no component, the matrix is empty and the `run` job is skipped — that is a pass, +not a failure. + +The workflow listens on `push: branches: [main]` and `pull_request` only, so the `github-pull-request` +and `github-push-main` bindings are the two that fire in this repo today. `github-tag-release` is +declared for consumers (and for a future tag-triggered workflow); pushing a `v*` tag here does not +start a run on its own. + +Secrets consumed by the `run` job: `ORUN_BACKEND_URL`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN`, +`SUPABASE_API_KEY`, plus the workflow's `GITHUB_TOKEN` for GHCR login. + +## Consuming the catalog + +Point a consumer repo's `intent.yaml` at the published package instead of a local directory: + +```yaml +compositions: + sources: + - name: stack-tectonic-flare + kind: oci + ref: ghcr.io/sourceplane/saas-stack-tectonic-flare:2.1.0 +``` + +Then declare components against the composition types: + +```yaml +# apps/docs/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: docs-site +spec: + type: cloudflare-pages + subscribe: + environments: + - name: dev + profile: pull-request + - name: production + profile: deploy + inputs: + siteDir: apps/docs + installCommand: npm ci + buildCommand: npm run build + outputDir: dist + projectName: tectonic-docs + nodeVersion: "20" + productionBranch: main +``` + +To read a published package without wiring an intent, download it: + +```bash +orun fetch ghcr.io/sourceplane/saas-stack-tectonic-flare:2.1.0 --output ./tectonic-flare +``` + +## Local development + +```bash +orun compositions list # what this catalog exports +orun composition cloudflare-worker -e # one composition, with every step expanded +orun plan --intent intent.yaml # what would run right now +cd stacks/stack-tectonic-flare && orun publish --dry-run +``` + +`orun publish` resolves the package name, version, and registry from +[`stacks/stack-tectonic-flare/stack.yaml`](stacks/stack-tectonic-flare/stack.yaml), so it must be run +from that directory (or with `--root` pointed at it). + +## Releasing + +The version lives in `stacks/stack-tectonic-flare/stack.yaml`. Publishing happens from CI when a change +to the stack lands on `main`: the `stack-tectonic` component subscribes to `staging` with the `release` +profile, which runs `orun publish --dry-run` and then the real `orun publish`. + +1. Bump `metadata.version` in `stacks/stack-tectonic-flare/stack.yaml`. +2. Merge to `main`. The `stack-tectonic · staging · Publish` check performs the upload. +3. Verify the tag exists in the registry: + + ```bash + TOKEN=$(curl -s "https://ghcr.io/token?scope=repository:sourceplane/saas-stack-tectonic-flare:pull&service=ghcr.io" | jq -r .token) + curl -s -H "Authorization: Bearer $TOKEN" \ + https://ghcr.io/v2/sourceplane/saas-stack-tectonic-flare/tags/list | jq + ``` + +4. Tag the commit `vX.Y.Z` to keep the git history aligned with the published versions. + +Re-publishing an existing version is not meaningful — bump the version in the same PR that changes the +catalog, so every merge to `main` either publishes something new or publishes nothing. diff --git a/stacks/stack-tectonic-flare/README.md b/stacks/stack-tectonic-flare/README.md new file mode 100644 index 0000000..78ece1e --- /dev/null +++ b/stacks/stack-tectonic-flare/README.md @@ -0,0 +1,142 @@ +# Tectonic Flare Platform Stack + +Package identity, from [`stack.yaml`](stack.yaml): + +| | | +|---|---| +| Stack name | `tectonic-flare` | +| Version | `2.1.0` | +| Owner | `sourceplane` | +| Registry | `ghcr.io/sourceplane/saas-stack-tectonic-flare` (public) | +| Compositions | 9 | + +This directory is the publishable unit. `orun publish` reads `stack.yaml` from here, archives the +tree, and pushes it to the registry above under the tag in `metadata.version`. + +## Anatomy of a composition + +Every composition is four files that answer four separate questions: + +| File | Kind | Question it answers | +|---|---|---| +| `composition.yaml` | `Composition` | What is this type called, which schema validates it, which jobs and profiles exist, and what are the defaults? | +| `schema.yaml` | `ComponentSchema` | What inputs may a component of this type set, and which are required? | +| `jobs/*.yaml` | `JobTemplate` | What is the complete, ordered list of steps — every step any profile could run? | +| `profiles/*.yaml` | `ExecutionProfile` | For a given lane, which of those steps actually run, and under what policy? | + +The split matters: **the job template is written once, with every step**, and profiles subtract from it. +There is no `if PR then skip` logic in the step list. A step is selected purely by whether its +`capability` appears in the profile's `includeCapabilities`. + +```yaml +# jobs/cloudflare-worker-verify-deploy.yaml (excerpt) +steps: + - id: build-worker + capability: cloudflare-worker.build # <- selector + run: "{{.buildCommand}}" + +# profiles/cloudflare-worker-pull-request.yaml (excerpt) +jobs: + verify-deploy: + includeCapabilities: + - cloudflare-worker.build # <- included, so the step runs + # cloudflare-worker.deploy omitted, so deploy is not planned at all +``` + +Capabilities are namespaced by composition type (`cloudflare-worker.build`, not `build`), so two +compositions in the same plan never collide. + +## Profile lanes + +Names are consistent across the catalog so a component can subscribe to the same lane everywhere: + +| Lane | Present in | Meaning | +|---|---|---| +| `pull-request` | all deploy-capable compositions | Cheapest useful signal on a PR: set up, install, build, verify. Never mutates a remote. | +| `verify` | all | Full non-mutating verification. Same shape as `pull-request` plus anything slow but safe (Terraform `init` / `validate`). | +| `quick-check` | `turbo-package` | Structure-only smoke: install and check the package exists, skipping build and typecheck. | +| `deploy` | direct-upload compositions | `verify` plus provision and deploy. | +| `release` | Terraform-backed compositions, `publish-stack` | `verify` plus the mutating apply/publish, gated by profile policies. | +| `dry-run` | `publish-stack` | Validation-only publish (`orun publish --dry-run`). | + +`release` profiles carry policies that the runner enforces before the mutating step: +`requireCleanGitTree`, `requirePinnedTerraformVersion`, `requireApproval`. + +## Two layers of gating + +Profiles decide **whether a mutating step is planned**. The steps themselves add a second guard, so a +misrouted plan still cannot deploy from the wrong place. Every deploy and apply step in this catalog +starts with: + +```bash +if [ "{{.Environment}}" != "production" ] || [ "${GITHUB_REF:-}" != "refs/heads/{{.productionBranch}}" ]; then + echo "Skipping ..."; exit 0 +fi +``` + +So a live deploy requires **all** of: a profile that includes the deploy capability, the `production` +environment, and `GITHUB_REF` on the component's `productionBranch`. Anywhere else the step exits 0 +with a skip notice. The Worker compositions add one more case: in the `dev` environment they run +`wrangler deploy --dry-run` instead of skipping outright, so PRs get real Wrangler validation. + +Credentials are asserted only after that gate passes (`: "${CLOUDFLARE_API_TOKEN:?...}"`), which is why +the verify lanes run fine on forks and locally with no Cloudflare secrets present. + +## Template context + +Step `run` blocks are Go templates. Available keys: + +| Key | Source | +|---|---| +| `{{.Environment}}` | The environment the job was planned into — `dev`, `staging`, `production` | +| `{{.Component}}` | The component's name, used in the log notices | +| `{{.anyInput}}` | Any input the component set, validated against `schema.yaml` | + +Optional inputs are guarded with `{{if .foo}}…{{else}}…{{end}}` so an unset input degrades to a +documented default or an explicit skip, never to an empty command. + +## Conventions to keep when adding a composition + +1. **One job template per composition.** Add capabilities, not job templates, when a lane needs more. +2. **Name capabilities `.`** and list every one of them in the template's `capabilities:` + block as well as on the step. +3. **Required vs optional inputs.** Anything a step interpolates unconditionally belongs in the schema's + `required:` list. Anything wrapped in `{{if}}` must not be required. +4. **`additionalProperties: false`** on `inputs` — a typo in a consumer's `component.yaml` should fail + validation, not silently disappear. +5. **`onFailure: stop`** on every step that gates correctness. +6. **Gate mutating steps** on `{{.Environment}}` and `productionBranch` as shown above, even though the + profile already excludes them from non-deploy lanes. +7. **Update the composition's `README.md`** in the same change — the profile/capability tables there are + the consumer-facing contract. + +## Versioning and publishing + +`metadata.version` in `stack.yaml` is the published OCI tag. Bump it in the same PR that changes any +composition: + +| Change | Bump | +|---|---| +| Docs, comments, descriptions | patch | +| New composition, new profile, new optional input | minor | +| Removed or renamed input/profile/capability, or a required input added | major | + +Merging to `main` runs the `stack-tectonic · staging · Publish` check, which dry-runs and then publishes. +See the [repository README](../../README.md#releasing) for the full release and verification steps. + +## Component contract for this repo + +[`component.yaml`](component.yaml) declares the single component that publishes this catalog: + +```yaml +spec: + type: publish-stack + subscribe: + environments: + - name: dev + profile: dry-run # PRs validate the package + - name: staging + profile: release # merge to main publishes + - name: production + profile: release +``` diff --git a/stacks/stack-tectonic-flare/compositions/cloudflare-pages-terraform/README.md b/stacks/stack-tectonic-flare/compositions/cloudflare-pages-terraform/README.md index 8c03a29..30ff51d 100644 --- a/stacks/stack-tectonic-flare/compositions/cloudflare-pages-terraform/README.md +++ b/stacks/stack-tectonic-flare/compositions/cloudflare-pages-terraform/README.md @@ -1,27 +1,130 @@ # cloudflare-pages-terraform -`cloudflare-pages-terraform` is an exported Orun composition in the Stack Tectonic catalog. +Build a static site locally for verification, then reconcile a **Git-connected** Cloudflare Pages +project with Terraform. -## Purpose +The difference from [`cloudflare-pages`](../cloudflare-pages): CI never uploads assets. It proves the +site still builds, then hands the Pages project — repo connection, build command, output directory — +to Terraform. Cloudflare does the real build on push. For a monorepo app, use +[`cloudflare-pages-turbo-terraform`](../cloudflare-pages-turbo-terraform). -Verify static site builds locally and reconcile a Git-backed Cloudflare Pages project with Terraform +| | | +|---|---| +| Composition type | `cloudflare-pages-terraform` | +| Schema | `cloudflare-pages-terraform-component` | +| Job | `verify-reconcile` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `30m`, no retries | +| Scope label | `infra` | -## Contract +## Steps and profiles -- **Type:** `cloudflare-pages-terraform` -- **Path:** `compositions/cloudflare-pages-terraform` -- **Definition:** `compositions.yaml` +| # | Step | Capability (`cloudflare-pages-terraform.`) | What it runs | `pull-request` | `verify` | `release` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-node` | `setup-node` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | ✅ | +| 2 | `install-site-dependencies` | `install` | `cd siteDir && ` | ✅ | ✅ | ✅ | +| 3 | `build-site` | `build` | `cd siteDir && ` | ✅ | ✅ | ✅ | +| 4 | `verify-build-output` | `verify` | asserts `outputDir` exists under `siteDir` | ✅ | ✅ | ✅ | +| 5 | `setup-terraform` | `setup-terraform` | `hashicorp/setup-terraform@v4` at `terraformVersion`, wrapper off | ✅ | ✅ | ✅ | +| 6 | `terraform-context` | `terraform-context` | prints `terraform version` and the reconcile target | ✅ | ✅ | ✅ | +| 7 | `terraform-fmt-check` | `terraform-fmt` | `terraform -chdir= fmt -check` | ✅ | ✅ | ✅ | +| 8 | `terraform-init` | `terraform-init` | `terraform init -input=false` (real backend) | — | ✅ | ✅ | +| 9 | `terraform-validate` | `terraform-validate` | `terraform validate -no-color` | — | ✅ | ✅ | +| 10 | `terraform-plan-or-apply` | `terraform-apply` | `plan` off the production branch, `apply -auto-approve` on it | — | — | ✅ | -## Example fixtures +`pull-request` deliberately stops before `init`, so PRs need no backend credentials and stay fast. +Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +## Inputs -- `examples/docs-site-git` +All thirteen inputs are required, and `additionalProperties: false`. -## Test fixtures +| Input | Description | +|---|---| +| `siteDir` | Directory containing the site; steps 2–4 `cd` here. | +| `installCommand` | Install command run in `siteDir`, e.g. `npm ci`. | +| `buildCommand` | Local verification build, e.g. `npm run build`. | +| `cloudflareBuildCommand` | Build command Cloudflare runs for the Git-connected project. Passed to Terraform as `build_command`. Often differs from `buildCommand` — it runs from `rootDir`, not `siteDir`. | +| `outputDir` | Build output directory. Verified locally under `siteDir` **and** passed to Terraform as `destination_dir`. | +| `rootDir` | Project root Cloudflare builds from, passed as `root_dir` (e.g. `apps/docs`, or `/` for repo root). | +| `nodeVersion` | Node version for `actions/setup-node`. Quote it. | +| `terraformDir` | Directory holding the Terraform configuration for this project. | +| `terraformVersion` | Exact Terraform version for `setup-terraform`. | +| `projectName` | Cloudflare Pages project name, passed as `project_name`. | +| `productionBranch` | Production branch, passed as `production_branch`; also the apply gate. | +| `repoOwner` | GitHub owner for the Pages Git connection, passed as `repo_owner`. | +| `repoName` | GitHub repository name, passed as `repo_name`. | -- `tests/smoke` +## Terraform contract -## Verification +Step 10 always passes the same variables, so the configuration in `terraformDir` must declare: -`./scripts/verify-composition.sh cloudflare-pages-terraform` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +```hcl +variable "account_id" {} # from CLOUDFLARE_ACCOUNT_ID +variable "project_name" {} # projectName +variable "production_branch" {} # productionBranch +variable "repo_owner" {} # repoOwner +variable "repo_name" {} # repoName +variable "build_command" {} # cloudflareBuildCommand +variable "destination_dir" {} # outputDir +variable "root_dir" {} # rootDir +``` + +Backend configuration is the component's own concern — step 8 runs a plain `init -input=false`, so put +the backend block in `terraformDir`. + +## Apply gating + +Step 10 has three outcomes: + +| Condition | Behaviour | +|---|---| +| `{{.Environment}}` is `production` **and** `GITHUB_REF` is `refs/heads/` | Asserts both Cloudflare variables, then `terraform apply -auto-approve`. | +| Otherwise, with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` both set | `terraform plan -lock=false -no-color` — a speculative plan that never takes state locks. | +| Otherwise | Prints a skip notice and exits 0. | + +When plan runs without an account id, `account_id` falls back to a 32-zero placeholder so the plan can +render; it is never used on the apply path, where `CLOUDFLARE_ACCOUNT_ID` is required. + +| Variable | Needed by | +|---|---| +| `CLOUDFLARE_ACCOUNT_ID` | apply (required), plan (optional — absent ⇒ skip) | +| `CLOUDFLARE_API_TOKEN` | apply (required), plan (optional — absent ⇒ skip). Also read by the Cloudflare Terraform provider. | + +## Usage + +```yaml +# apps/docs/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: docs-site +spec: + type: cloudflare-pages-terraform + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: release + inputs: + siteDir: apps/docs + installCommand: npm ci + buildCommand: npm run build + cloudflareBuildCommand: npm run build + outputDir: dist + rootDir: apps/docs + nodeVersion: "20" + terraformDir: infra/docs-site + terraformVersion: 1.9.8 + projectName: tectonic-docs + productionBranch: main + repoOwner: sourceplane + repoName: example-platform-repo +``` + +```bash +orun composition cloudflare-pages-terraform -e +``` diff --git a/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo-terraform/README.md b/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo-terraform/README.md index 2b1f832..3357753 100644 --- a/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo-terraform/README.md +++ b/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo-terraform/README.md @@ -1,27 +1,124 @@ # cloudflare-pages-turbo-terraform -`cloudflare-pages-turbo-terraform` is an exported Orun composition in the Stack Tectonic catalog. +Verify a **pnpm + Turborepo** Pages app locally, then reconcile its **Git-connected** Cloudflare Pages +project with Terraform. -## Purpose +The union of [`cloudflare-pages-turbo`](../cloudflare-pages-turbo) (workspace install, Turbo build) and +[`cloudflare-pages-terraform`](../cloudflare-pages-terraform) (Terraform owns the project, Cloudflare +runs the real build). CI never uploads assets. -Verify a static app with Turbo locally and reconcile a Git-backed Cloudflare Pages project with Terraform +| | | +|---|---| +| Composition type | `cloudflare-pages-turbo-terraform` | +| Schema | `cloudflare-pages-turbo-terraform-component` | +| Job | `verify-reconcile` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `35m`, no retries | +| Scope label | `infra` | -## Contract +## Steps and profiles -- **Type:** `cloudflare-pages-turbo-terraform` -- **Path:** `compositions/cloudflare-pages-turbo-terraform` -- **Definition:** `compositions.yaml` +| # | Step | Capability (`cloudflare-pages-turbo-terraform.`) | What it runs | `pull-request` | `verify` | `release` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-node` | `setup-node` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | ✅ | +| 2 | `setup-pnpm` | `setup-pnpm` | `pnpm/action-setup@v4` at `pnpmVersion` | ✅ | ✅ | ✅ | +| 3 | `install-workspace-dependencies` | `install` | `pnpm install --no-frozen-lockfile` | ✅ | ✅ | ✅ | +| 4 | `pre-build` | `pre-build` | `preBuildCommand`, or prints a skip notice | ✅ | ✅ | ✅ | +| 5 | `verify-pages-app-structure` | `verify-structure` | `test -f package.json` | ✅ | ✅ | ✅ | +| 6 | `build-pages-app` | `build` | `buildCommand`, default `pnpm exec turbo run build --filter=./` | ✅ | ✅ | ✅ | +| 7 | `verify-build-output` | `verify-output` | asserts `outputDir` exists, lists the first 20 files | ✅ | ✅ | ✅ | +| 8 | `setup-terraform` | `setup-terraform` | `hashicorp/setup-terraform@v4` at `terraformVersion`, wrapper off | ✅ | ✅ | ✅ | +| 9 | `terraform-context` | `terraform-context` | prints `terraform version` and the reconcile target | ✅ | ✅ | ✅ | +| 10 | `terraform-fmt-check` | `terraform-fmt` | `terraform -chdir= fmt -check` | ✅ | ✅ | ✅ | +| 11 | `terraform-init` | `terraform-init` | `terraform init -input=false` (real backend) | — | ✅ | ✅ | +| 12 | `terraform-validate` | `terraform-validate` | `terraform validate -no-color` | — | ✅ | ✅ | +| 13 | `terraform-plan-or-apply` | `terraform-apply` | `plan` off the production branch, `apply -auto-approve` on it | — | — | ✅ | -## Example fixtures +`pull-request` stops before `init`, so PRs need no backend credentials. Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +## Inputs -- `examples/admin-console-git` +`additionalProperties: false` — an unrecognised key fails validation. -## Test fixtures +| Input | Required | Description | +|---|:--:|---| +| `cloudflareBuildCommand` | ✅ | Build command **Cloudflare** runs for the Git-connected project. Passed as `build_command`. | +| `outputDir` | ✅ | Local build output, asserted by step 7. Verification only — not passed to Terraform. | +| `destinationDir` | ✅ | Output directory **Cloudflare** publishes, passed as `destination_dir`. Usually the same path expressed relative to `rootDir`. | +| `rootDir` | ✅ | Project root Cloudflare builds from, passed as `root_dir` (e.g. `apps/admin`). | +| `nodeVersion` | ✅ | Node version for `actions/setup-node`. Quote it. | +| `pnpmVersion` | ✅ | pnpm version for `pnpm/action-setup`. Quote it. | +| `terraformDir` | ✅ | Directory holding the Terraform configuration. | +| `terraformVersion` | ✅ | Exact Terraform version for `setup-terraform`. | +| `projectName` | ✅ | Cloudflare Pages project name, passed as `project_name`. | +| `productionBranch` | ✅ | Production branch, passed as `production_branch`; also the apply gate. | +| `repoOwner` | ✅ | GitHub owner for the Pages Git connection, passed as `repo_owner`. | +| `repoName` | ✅ | GitHub repository name, passed as `repo_name`. | +| `preBuildCommand` | | Runs before the structure check. Omitted ⇒ step prints `Skipping pre-build.` | +| `buildCommand` | | Overrides the default Turbo build used for local verification. | -- `tests/smoke` +`outputDir` vs `destinationDir` is the one input pair that trips people up: `outputDir` is what CI +checks after building in the workspace, `destinationDir` is what Cloudflare is told to publish relative +to `rootDir`. In a monorepo they are typically `apps/admin/dist` and `dist`. -## Verification +## Terraform contract -`./scripts/verify-composition.sh cloudflare-pages-turbo-terraform` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +The configuration in `terraformDir` must declare: + +```hcl +variable "account_id" {} # from CLOUDFLARE_ACCOUNT_ID +variable "project_name" {} # projectName +variable "production_branch" {} # productionBranch +variable "repo_owner" {} # repoOwner +variable "repo_name" {} # repoName +variable "build_command" {} # cloudflareBuildCommand +variable "destination_dir" {} # destinationDir +variable "root_dir" {} # rootDir +``` + +## Apply gating + +| Condition | Behaviour | +|---|---| +| `{{.Environment}}` is `production` **and** `GITHUB_REF` is `refs/heads/` | Asserts both Cloudflare variables, then `terraform apply -auto-approve`. | +| Otherwise, with `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` both set | `terraform plan -lock=false -no-color`. | +| Otherwise | Prints a skip notice and exits 0. | + +`account_id` falls back to a 32-zero placeholder on the plan path only. + +## Usage + +```yaml +# apps/admin/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: admin-console +spec: + type: cloudflare-pages-turbo-terraform + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: release + inputs: + cloudflareBuildCommand: pnpm install && pnpm exec turbo run build --filter=admin-console + outputDir: dist + destinationDir: dist + rootDir: apps/admin + nodeVersion: "20" + pnpmVersion: "9" + terraformDir: infra/admin-console + terraformVersion: 1.9.8 + projectName: tectonic-admin + productionBranch: main + repoOwner: sourceplane + repoName: example-platform-repo +``` + +```bash +orun composition cloudflare-pages-turbo-terraform -e +``` diff --git a/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo/README.md b/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo/README.md index d173e7d..88d3314 100644 --- a/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo/README.md +++ b/stacks/stack-tectonic-flare/compositions/cloudflare-pages-turbo/README.md @@ -1,27 +1,96 @@ # cloudflare-pages-turbo -`cloudflare-pages-turbo` is an exported Orun composition in the Stack Tectonic catalog. +Build a Pages app inside a **pnpm + Turborepo** workspace and direct-upload it to Cloudflare Pages. -## Purpose +The Turbo variant of [`cloudflare-pages`](../cloudflare-pages): dependencies are installed once at the +workspace root with pnpm, and the build runs through `turbo` rather than a per-site install command. +If the Pages project is Git-connected, use +[`cloudflare-pages-turbo-terraform`](../cloudflare-pages-turbo-terraform) instead. -Build a static app with Turbo and direct-upload it to Cloudflare Pages +| | | +|---|---| +| Composition type | `cloudflare-pages-turbo` | +| Schema | `cloudflare-pages-turbo-component` | +| Job | `verify-deploy` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `30m`, no retries | +| Scope label | `delivery` | -## Contract +## Steps and profiles -- **Type:** `cloudflare-pages-turbo` -- **Path:** `compositions/cloudflare-pages-turbo` -- **Definition:** `compositions.yaml` +| # | Step | Capability (`cloudflare-pages-turbo.`) | What it runs | `pull-request` | `verify` | `deploy` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-node` | `setup-node` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | ✅ | +| 2 | `setup-pnpm` | `setup-pnpm` | `pnpm/action-setup@v4` at `pnpmVersion` | ✅ | ✅ | ✅ | +| 3 | `install-workspace-dependencies` | `install` | `pnpm install --no-frozen-lockfile` | ✅ | ✅ | ✅ | +| 4 | `pre-build` | `pre-build` | `preBuildCommand`, or prints a skip notice | ✅ | ✅ | ✅ | +| 5 | `verify-pages-app-structure` | `verify-structure` | `test -f package.json` | ✅ | ✅ | ✅ | +| 6 | `build-pages-app` | `build` | `buildCommand`, default `pnpm exec turbo run build --filter=./` | ✅ | ✅ | ✅ | +| 7 | `verify-build-output` | `verify-output` | asserts `outputDir` exists, lists the first 20 files | ✅ | ✅ | ✅ | +| 8 | `ensure-pages-project` | `provision` | creates or reconciles the Pages project over the Cloudflare API | — | — | ✅ | +| 9 | `deploy-pages-artifact` | `deploy` | `pnpm exec wrangler pages deploy`, then `smokeCommand` | — | — | ✅ | -## Example fixtures +Steps run with the component directory as the working directory, so the default `--filter=./` targets +this package and `outputDir` is resolved relative to it. Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +## Inputs -- `examples/web-console` +`additionalProperties: false` — an unrecognised key fails validation. -## Test fixtures +| Input | Required | Description | +|---|:--:|---| +| `outputDir` | ✅ | Build output directory relative to the component, e.g. `dist`. Verified in step 7, uploaded in step 9. | +| `projectName` | ✅ | Cloudflare Pages project name. Created during `provision` if missing. | +| `nodeVersion` | ✅ | Node version for `actions/setup-node`, e.g. `"20"`. Quote it. | +| `pnpmVersion` | ✅ | pnpm version for `pnpm/action-setup`, e.g. `"9"`. Quote it. | +| `productionBranch` | ✅ | Branch allowed to deploy, and the project's production branch. | +| `preBuildCommand` | | Runs before the structure check — codegen, schema generation, prisma, etc. Omitted ⇒ step prints `Skipping pre-build.` | +| `buildCommand` | | Overrides the default Turbo build. | +| `smokeCommand` | | Post-deploy check, run inside the deploy step after a successful upload. A failure here fails the job. | -- `tests/smoke` +## Deployment gating -## Verification +Steps 8 and 9 exit 0 with a `::notice::SKIPPED:` annotation unless **both** hold: -`./scripts/verify-composition.sh cloudflare-pages-turbo` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +- `{{.Environment}}` is `production`, and +- `GITHUB_REF` is `refs/heads/`. + +A live upload emits `::notice::LIVE DEPLOY:` before and `::notice::DEPLOY SUCCESS:` after, so the +GitHub Actions summary shows exactly which components deployed. + +| Variable | Needed by | Notes | +|---|---|---| +| `CLOUDFLARE_ACCOUNT_ID` | `provision`, `deploy` | Asserted after the gate; step fails fast if unset. | +| `CLOUDFLARE_API_TOKEN` | `provision`, `deploy` | Needs Pages edit permission. | + +## Usage + +```yaml +# apps/web-console/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: web-console +spec: + type: cloudflare-pages-turbo + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: deploy + inputs: + outputDir: dist + projectName: tectonic-web-console + nodeVersion: "20" + pnpmVersion: "9" + productionBranch: main + preBuildCommand: pnpm exec turbo run codegen --filter=./ + smokeCommand: curl -fsS https://tectonic-web-console.pages.dev/healthz +``` + +```bash +orun composition cloudflare-pages-turbo -e +``` diff --git a/stacks/stack-tectonic-flare/compositions/cloudflare-pages/README.md b/stacks/stack-tectonic-flare/compositions/cloudflare-pages/README.md index da7b056..48ea1e8 100644 --- a/stacks/stack-tectonic-flare/compositions/cloudflare-pages/README.md +++ b/stacks/stack-tectonic-flare/compositions/cloudflare-pages/README.md @@ -1,27 +1,99 @@ # cloudflare-pages -`cloudflare-pages` is an exported Orun composition in the Stack Tectonic catalog. +Build a static site from its own directory and **direct-upload** it to Cloudflare Pages with Wrangler. -## Purpose +Use this when CI owns the build. If the Pages project is Git-connected and Cloudflare runs the build, +use [`cloudflare-pages-terraform`](../cloudflare-pages-terraform). If the site is an app inside a +pnpm + Turborepo workspace, use [`cloudflare-pages-turbo`](../cloudflare-pages-turbo). -Build static site assets and direct-upload them to Cloudflare Pages with Wrangler +| | | +|---|---| +| Composition type | `cloudflare-pages` | +| Schema | `cloudflare-pages-component` | +| Job | `verify-deploy` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `25m`, no retries | +| Scope label | `delivery` | -## Contract +## Steps and profiles -- **Type:** `cloudflare-pages` -- **Path:** `compositions/cloudflare-pages` -- **Definition:** `compositions.yaml` +Steps run in this order. A step is planned only when its capability is in the profile's +`includeCapabilities`. -## Example fixtures +| # | Step | Capability (`cloudflare-pages.`) | What it runs | `pull-request` | `verify` | `deploy` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-node` | `setup` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | ✅ | +| 2 | `install-site-dependencies` | `install` | `cd siteDir && ` | ✅ | ✅ | ✅ | +| 3 | `build-site` | `build` | `cd siteDir && ` | ✅ | ✅ | ✅ | +| 4 | `verify-build-output` | `verify` | asserts `outputDir` exists, lists the first 20 files | ✅ | ✅ | ✅ | +| 5 | `ensure-pages-project` | `provision` | creates or reconciles the Pages project over the Cloudflare API | — | — | ✅ | +| 6 | `deploy-pages-artifact` | `deploy` | `npx wrangler pages deploy` | — | — | ✅ | -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +`pull-request` and `verify` cover the same steps today; they stay separate so PR-lane tuning can land +without touching the branch lane. Every step is `onFailure: stop`. -- `examples/docs-site` +## Inputs -## Test fixtures +All seven inputs are required, and `additionalProperties: false` — an unrecognised key fails validation. -- `tests/smoke` +| Input | Description | +|---|---| +| `siteDir` | Directory containing the site. Steps 2, 3, 4 and 6 `cd` here first. | +| `installCommand` | Dependency install, e.g. `npm ci`. | +| `buildCommand` | Build command, e.g. `npm run build`. | +| `outputDir` | Build output directory, **relative to `siteDir`** (e.g. `dist`). Verified in step 4, uploaded in step 6. | +| `projectName` | Cloudflare Pages project name. Created during `provision` if it does not exist. | +| `nodeVersion` | Node version for `actions/setup-node`, e.g. `"20"`. Quote it — `20.11` unquoted is a float. | +| `productionBranch` | Branch allowed to deploy, and the project's production branch, e.g. `main`. | -## Verification +## Deployment gating -`./scripts/verify-composition.sh cloudflare-pages` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +Steps 5 and 6 exit 0 with a skip message unless **both** hold: + +- `{{.Environment}}` is `production`, and +- `GITHUB_REF` is `refs/heads/`. + +Credentials are asserted only after that gate passes, so verify lanes run with no Cloudflare secrets. + +| Variable | Needed by | Notes | +|---|---|---| +| `CLOUDFLARE_ACCOUNT_ID` | `provision`, `deploy` | Step fails fast if unset once the gate passes. | +| `CLOUDFLARE_API_TOKEN` | `provision`, `deploy` | Needs Pages edit permission on the account. | + +`ensure-pages-project` is idempotent: it `GET`s the project, `POST`s it when the API returns 404, then +`PATCH`es `production_branch` either way. Any other status code prints the response body and fails. + +## Usage + +```yaml +# apps/docs/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: docs-site +spec: + type: cloudflare-pages + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: deploy + inputs: + siteDir: apps/docs + installCommand: npm ci + buildCommand: npm run build + outputDir: dist + projectName: tectonic-docs + nodeVersion: "20" + productionBranch: main +``` + +Inspect the resolved job before committing: + +```bash +orun composition cloudflare-pages -e +orun plan --intent intent.yaml +``` diff --git a/stacks/stack-tectonic-flare/compositions/cloudflare-worker-turbo/README.md b/stacks/stack-tectonic-flare/compositions/cloudflare-worker-turbo/README.md index b6b5e5d..123f5b9 100644 --- a/stacks/stack-tectonic-flare/compositions/cloudflare-worker-turbo/README.md +++ b/stacks/stack-tectonic-flare/compositions/cloudflare-worker-turbo/README.md @@ -1,27 +1,99 @@ # cloudflare-worker-turbo -`cloudflare-worker-turbo` is an exported Orun composition in the Stack Tectonic catalog. +Verify a Cloudflare Worker inside a **pnpm + Turborepo** workspace and deploy it from the production +branch. -## Purpose +The Turbo variant of [`cloudflare-worker`](../cloudflare-worker): dependencies install once at the +workspace root, and build, typecheck, and deploy all have Turbo/pnpm defaults, so a component can +declare almost no inputs. -Verify a Cloudflare Worker app and deploy it from the production branch +| | | +|---|---| +| Composition type | `cloudflare-worker-turbo` | +| Schema | `cloudflare-worker-turbo-component` | +| Job | `verify-deploy` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `30m`, no retries | +| Scope label | `delivery` | -## Contract +## Steps and profiles -- **Type:** `cloudflare-worker-turbo` -- **Path:** `compositions/cloudflare-worker-turbo` -- **Definition:** `compositions.yaml` +| # | Step | Capability (`cloudflare-worker-turbo.`) | What it runs | `pull-request` | `verify` | `deploy` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-node` | `setup-node` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | ✅ | +| 2 | `setup-pnpm` | `setup-pnpm` | `pnpm/action-setup@v4` at `pnpmVersion` | ✅ | ✅ | ✅ | +| 3 | `install-workspace-dependencies` | `install` | `pnpm install --no-frozen-lockfile` | ✅ | ✅ | ✅ | +| 4 | `pre-build` | `pre-build` | `preBuildCommand`, or prints a skip notice | ✅ | ✅ | ✅ | +| 5 | `verify-worker-structure` | `verify-structure` | `test -f package.json` plus the Wrangler config check | ✅ | ✅ | ✅ | +| 6 | `build-worker` | `build` | `buildCommand`, default `pnpm exec turbo run build --filter=./` | ✅ | ✅ | ✅ | +| 7 | `typecheck-worker` | `typecheck` | `typecheckCommand`, default `pnpm exec turbo run typecheck --filter=./` | ✅ | ✅ | ✅ | +| 8 | `deploy-worker` | `deploy` | dry-run in `dev`, real deploy on the production branch | — | — | ✅ | -## Example fixtures +The structure check asserts `wranglerConfig` when set, otherwise requires `wrangler.jsonc` **or** +`wrangler.toml`. Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +Unlike [`cloudflare-worker`](../cloudflare-worker), typecheck is **not** optional here: with no +`typecheckCommand` it falls back to `turbo run typecheck --filter=./`, which fails if the package has no +`typecheck` task. Give the package the task, or set `typecheckCommand` to something harmless. -- `examples/api-edge` +## Inputs -## Test fixtures +`additionalProperties: false` — an unrecognised key fails validation. -- `tests/smoke` +| Input | Required | Description | +|---|:--:|---| +| `nodeVersion` | ✅ | Node version for `actions/setup-node`. Quote it. | +| `pnpmVersion` | ✅ | pnpm version for `pnpm/action-setup`. Quote it. | +| `productionBranch` | ✅ | Branch allowed to deploy, e.g. `main`. | +| `wranglerConfig` | | Explicit path to the Wrangler config; otherwise `wrangler.jsonc` or `wrangler.toml` must exist. | +| `preBuildCommand` | | Codegen and similar, before the structure check. Omitted ⇒ `Skipping pre-build.` | +| `buildCommand` | | Overrides the default Turbo build. | +| `typecheckCommand` | | Overrides the default Turbo typecheck. | +| `preDeployCommand` | | Runs inside the deploy step, before migrations. | +| `migrationCommand` | | Migrations, after `preDeployCommand`. | +| `deployCommand` | | Overrides the default `pnpm run deploy`. | +| `smokeCommand` | | Post-deploy check; a failure fails the job. | -## Verification +## Deployment behaviour -`./scripts/verify-composition.sh cloudflare-worker-turbo` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +| Condition | Behaviour | +|---|---| +| `{{.Environment}}` is `dev` | `::notice::DRY-RUN:` then `pnpm exec wrangler deploy --dry-run`. | +| Not `production`, or `GITHUB_REF` is not `refs/heads/` | `::notice::SKIPPED:` and exit 0. | +| `production` on the production branch | Asserts credentials, then `preDeployCommand` → `migrationCommand` → `deployCommand` (default `pnpm run deploy`) → `smokeCommand`, bracketed by `::notice::LIVE DEPLOY:` and `::notice::DEPLOY SUCCESS:`. | + +| Variable | Needed by | Notes | +|---|---|---| +| `CLOUDFLARE_ACCOUNT_ID` | live deploy | Asserted after the gate; not needed for the `dev` dry-run. | +| `CLOUDFLARE_API_TOKEN` | live deploy | Needs Workers Scripts edit permission. | + +## Usage + +```yaml +# apps/api-edge/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: api-edge +spec: + type: cloudflare-worker-turbo + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: deploy + inputs: + nodeVersion: "20" + pnpmVersion: "9" + productionBranch: main + preBuildCommand: pnpm exec turbo run codegen --filter=./ + migrationCommand: pnpm run db:migrate + smokeCommand: curl -fsS https://api.example.com/healthz +``` + +```bash +orun composition cloudflare-worker-turbo -e +``` diff --git a/stacks/stack-tectonic-flare/compositions/cloudflare-worker/README.md b/stacks/stack-tectonic-flare/compositions/cloudflare-worker/README.md index 8408509..a8c9290 100644 --- a/stacks/stack-tectonic-flare/compositions/cloudflare-worker/README.md +++ b/stacks/stack-tectonic-flare/compositions/cloudflare-worker/README.md @@ -1,27 +1,104 @@ # cloudflare-worker -`cloudflare-worker` is an exported Orun composition in the Stack Tectonic catalog. +Verify a Cloudflare Worker and deploy it from the production branch with your own deploy command. -## Purpose +Use this for a Worker that owns its install and build commands. For a Worker inside a pnpm + Turborepo +workspace, use [`cloudflare-worker-turbo`](../cloudflare-worker-turbo), which installs at the workspace +root and defaults its build and typecheck to Turbo. -Verify a Cloudflare Worker app and deploy it from the production branch +| | | +|---|---| +| Composition type | `cloudflare-worker` | +| Schema | `cloudflare-worker-component` | +| Job | `verify-deploy` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `30m`, no retries | +| Scope label | `delivery` | -## Contract +## Steps and profiles -- **Type:** `cloudflare-worker` -- **Path:** `compositions/cloudflare-worker` -- **Definition:** `compositions.yaml` +| # | Step | Capability (`cloudflare-worker.`) | What it runs | `pull-request` | `verify` | `deploy` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-node` | `setup` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | ✅ | +| 2 | `install-dependencies` | `install` | installs pnpm globally when `pnpmVersion` is set, then `installCommand` | ✅ | ✅ | ✅ | +| 3 | `verify-worker-structure` | `verify-structure` | `test -f package.json` plus the Wrangler config check below | ✅ | ✅ | ✅ | +| 4 | `build-worker` | `build` | `buildCommand` | ✅ | ✅ | ✅ | +| 5 | `typecheck-worker` | `typecheck` | `typecheckCommand`, or prints a skip notice | ✅ | ✅ | ✅ | +| 6 | `deploy-worker` | `deploy` | dry-run in `dev`, real deploy on the production branch | — | — | ✅ | -## Example fixtures +The structure check asserts `wranglerConfig` when set, otherwise requires `wrangler.jsonc` **or** +`wrangler.toml`. Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +## Inputs -- `examples/identity-worker` +`additionalProperties: false` — an unrecognised key fails validation. -## Test fixtures +| Input | Required | Description | +|---|:--:|---| +| `installCommand` | ✅ | e.g. `npm ci` or `pnpm install --frozen-lockfile`. | +| `buildCommand` | ✅ | e.g. `npm run build`. Interpolated unconditionally, so it must be set even if it is a no-op. | +| `deployCommand` | ✅ | The real deploy, e.g. `npx wrangler deploy`. Runs only after the production gate. | +| `nodeVersion` | ✅ | Node version for `actions/setup-node`. Quote it. | +| `productionBranch` | ✅ | Branch allowed to deploy, e.g. `main`. | +| `pnpmVersion` | | When set, the install step runs `npm install -g pnpm@` first. | +| `typecheckCommand` | | Omitted ⇒ step prints `Skipping typecheck (not configured).` | +| `wranglerConfig` | | Explicit path to the Wrangler config, e.g. `wrangler.production.jsonc`. | +| `preDeployCommand` | | Runs inside the deploy step, before migrations, in a `::group::Pre-deploy` block. | +| `migrationCommand` | | Database or D1 migrations, run after `preDeployCommand` in a `::group::Run migrations` block. | +| `smokeCommand` | | Post-deploy check; a failure fails the job. | -- `tests/smoke` +## Deployment behaviour -## Verification +Step 6 branches three ways: -`./scripts/verify-composition.sh cloudflare-worker` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +| Condition | Behaviour | +|---|---| +| `{{.Environment}}` is `dev` | `::notice::DRY-RUN:` then `pnpm exec wrangler deploy --dry-run` — real Wrangler validation with no upload. | +| Not `production`, or `GITHUB_REF` is not `refs/heads/` | `::notice::SKIPPED:` and exit 0. | +| `production` on the production branch | Asserts credentials, then `preDeployCommand` → `migrationCommand` → `deployCommand` → `smokeCommand`, bracketed by `::notice::LIVE DEPLOY:` and `::notice::DEPLOY SUCCESS:`. | + +The `dev` dry-run path invokes `pnpm exec wrangler`, so a component that subscribes `dev` to a profile +containing `deploy` needs pnpm on the runner — set `pnpmVersion` or keep `dev` on `pull-request`, which +excludes the deploy capability entirely. The default `dev` wiring in this stack uses `pull-request`. + +| Variable | Needed by | Notes | +|---|---|---| +| `CLOUDFLARE_ACCOUNT_ID` | live deploy | Asserted after the gate; not needed for the `dev` dry-run. | +| `CLOUDFLARE_API_TOKEN` | live deploy | Needs Workers Scripts edit permission. | + +Anything `migrationCommand` needs (for example `SUPABASE_API_KEY`) must be present in the runner +environment — see the workflow's `env:` block. + +## Usage + +```yaml +# services/identity/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: identity-worker +spec: + type: cloudflare-worker + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: deploy + inputs: + installCommand: npm ci + buildCommand: npm run build + typecheckCommand: npm run typecheck + deployCommand: npx wrangler deploy + nodeVersion: "20" + productionBranch: main + wranglerConfig: wrangler.jsonc + migrationCommand: npm run db:migrate + smokeCommand: curl -fsS https://identity.example.com/healthz +``` + +```bash +orun composition cloudflare-worker -e +``` diff --git a/stacks/stack-tectonic-flare/compositions/publish-stack/README.md b/stacks/stack-tectonic-flare/compositions/publish-stack/README.md index 8f30510..9d9a0fe 100644 --- a/stacks/stack-tectonic-flare/compositions/publish-stack/README.md +++ b/stacks/stack-tectonic-flare/compositions/publish-stack/README.md @@ -1,37 +1,125 @@ # publish-stack -`publish-stack` is an exported Orun composition in the Stack Tectonic catalog. +Package an Orun stack and publish it to an OCI registry, with an always-on dry-run in front of the +real upload. -## Purpose +This is the composition this repository uses on itself: the `stack-tectonic` component +([`../../component.yaml`](../../component.yaml)) is of type `publish-stack`, which is how +`ghcr.io/sourceplane/saas-stack-tectonic-flare` gets its tags. -Publish an Orun stack to an OCI registry. Runs `orun publish --dry-run` on every pull request and performs the real publish on release. +| | | +|---|---| +| Composition type | `publish-stack` | +| Schema | `publish-stack-component` | +| Job | `publish` (default) | +| Default profile | `dry-run` | +| Runner | `ubuntu-22.04`, timeout `20m`, no retries | +| Scope label | `delivery` | -## Contract +## Steps and profiles -- **Type:** `publish-stack` -- **Path:** `compositions/publish-stack` -- **Definition:** `composition.yaml` +| # | Step | Capability (`publish-stack.`) | What it runs | `dry-run` | `verify` | `release` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-orun` | `setup` | `sourceplane/orun-action@v1.1.0` | ✅ | ✅ | ✅ | +| 2 | `publish-dry-run` | `dry-run` | `orun publish --dry-run` — resolves the target and builds the archive, uploads nothing | ✅ | ✅ | ✅ | +| 3 | `publish` | `publish` | `orun publish` — builds and uploads | — | — | ✅ | -## Profiles +`dry-run` and `verify` are identical step sets with different intent: `dry-run` is the PR lane, +`verify` the staging lane. `release` adds the upload and carries `requireCleanGitTree: true`, so an +uncommitted working tree fails the profile policy before anything is pushed. -| Profile | Description | -|-----------|--------------------------------------------------| -| `dry-run` | PR validation — runs `orun publish --dry-run` | -| `verify` | Staging validation — dry-run without publishing | -| `release` | Production — dry-run + real publish to registry | +Both steps are `onFailure: stop`, so a packaging error in step 2 prevents the upload in step 3. + +## What `orun publish` resolves + +The steps take no arguments; everything comes from the stack manifest in the job's working directory +(the component's `path`). For this repo that is +[`stacks/stack-tectonic-flare/stack.yaml`](../../stack.yaml): + +| Value | Source | +|---|---| +| Package name | `metadata.name` | +| Version / OCI tag | The matching git tag if the checkout is on one, otherwise `metadata.version` | +| Registry target | The `registry` block — `host`/`namespace`/`repository` | + +``` +$ orun publish --dry-run + package tectonic-flare + version 2.1.0 + files 64 + registry ghcr.io/sourceplane/saas-stack-tectonic-flare + source inferred from stack.yaml registry block + ✓ dry run: no files uploaded + → would push to ghcr.io/sourceplane/saas-stack-tectonic-flare:2.1.0 +``` + +A `stack.yaml` (or `orun.yaml`) must sit in that directory — running from a repo root that has none +fails with `no stack.yaml or orun.yaml found`. ## Inputs -| Input | Required | Description | -|------------|----------|-----------------------------------------------------------| -| `registry` | yes | OCI registry base URL, e.g. `ghcr.io/org/stack-name` | -| `version` | yes | Default version; overridden at runtime by `STACK_VERSION` | -| `root` | no | Root directory of the stack (default `.`) | +The schema accepts three optional inputs and sets `additionalProperties: true` on `inputs`: + +| Input | Required | Status | +|---|:--:|---| +| `registry` | | Declared for forward compatibility. **Not read by the current job template** — the registry comes from `stack.yaml`. | +| `version` | | Declared for forward compatibility. **Not read by the current job template** — the version comes from the git tag or `stack.yaml`. | +| `root` | | Declared for forward compatibility. **Not read by the current job template** — `orun publish` runs in the component directory. | + +To publish somewhere else or under a different version today, change `stack.yaml` (or tag the commit) +rather than setting these inputs. + +## Registry credentials + +The publish step needs a registry login in the runner environment before it runs. This repo's workflow +does that with `docker/login-action` against `ghcr.io` using the workflow `GITHUB_TOKEN`, and grants +`permissions: packages: write`: + +```yaml +permissions: + contents: read + packages: write +- name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} +``` + +Without it, the upload fails with `oras push failed: ... 403: denied`. The dry-run lane needs no +credentials. + +## Usage -## Example fixtures +```yaml +# stacks//component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: stack-tectonic +spec: + type: publish-stack + domain: platform-stack + subscribe: + environments: + - name: dev + profile: dry-run # PRs validate packaging only + - name: staging + profile: release # merging to main publishes + - name: production + profile: release + inputs: + name: stack-tectonic-flare +``` -- `examples/` +Verify a published tag: -## Test fixtures +```bash +TOKEN=$(curl -s "https://ghcr.io/token?scope=repository:sourceplane/saas-stack-tectonic-flare:pull&service=ghcr.io" | jq -r .token) +curl -s -H "Authorization: Bearer $TOKEN" \ + https://ghcr.io/v2/sourceplane/saas-stack-tectonic-flare/tags/list | jq +``` -- `tests/smoke` +Publishing a version that already exists in the registry re-pushes the same tag; bump +`metadata.version` with the change instead. See the [release process](../../README.md#versioning-and-publishing). diff --git a/stacks/stack-tectonic-flare/compositions/terraform/README.md b/stacks/stack-tectonic-flare/compositions/terraform/README.md index 4a77832..014ce59 100644 --- a/stacks/stack-tectonic-flare/compositions/terraform/README.md +++ b/stacks/stack-tectonic-flare/compositions/terraform/README.md @@ -1,27 +1,103 @@ # terraform -`terraform` is an exported Orun composition in the Stack Tectonic catalog. +Validate a Terraform stack: `fmt`, `init`, `validate`, `plan`. This composition is **validation-only** — +no shipped profile applies. -## Purpose +Use it for infrastructure that is reconciled by a separate apply workflow, or for modules you want +checked on every PR. Cloudflare Pages projects that Terraform owns end to end are covered by +[`cloudflare-pages-terraform`](../cloudflare-pages-terraform) and +[`cloudflare-pages-turbo-terraform`](../cloudflare-pages-turbo-terraform), which do apply on the +production branch. -Terraform validation jobs for infra components +| | | +|---|---| +| Composition type | `terraform` | +| Schema | `terraform-component` | +| Job | `terraform` (default), template `terraform-validate` | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `20m`, no retries | +| Scope label | `infra` | -## Contract +## Steps and profiles -- **Type:** `terraform` -- **Path:** `compositions/terraform` -- **Definition:** `compositions.yaml` +| # | Step (`id`) | Capability (`terraform.`) | What it runs | `pull-request` | `verify` | `release` | +|---|---|---|---|:--:|:--:|:--:| +| 1 | `setup-terraform` | `setup` | `hashicorp/setup-terraform@v4` at `terraformVersion`, wrapper off | ✅ | ✅ | ✅ | +| 2 | `terraform-context` | `context` | prints `terraform version` | ✅ | ✅ | ✅ | +| 3 | `terraform-fmt-check` | `fmt` | `terraform fmt -check` | ✅ | ✅ | ✅ | +| 4 | `terraform-init` | `init` | `terraform init` | ✅ | ✅ | ✅ | +| 5 | `terraform-validate` | `validate` | `terraform validate -no-color` | ✅ | ✅ | ✅ | +| 6 | `terraform-plan` | `plan` | `terraform plan -no-color` | ✅ | ✅ | ✅ | +| 7 | `terraform-apply` | `apply` | `terraform apply -no-color -auto-approve` | — | — | — | -## Example fixtures +Steps 3–7 prefix themselves with `cd "" &&` when `terraformDir` is set, and run in the +component directory otherwise. Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +Step 7 is declared but selected by no shipped profile, so it never runs. It is kept so an apply-capable +profile can be added without changing the job template. -- `examples/network-foundation` +> **Changed in 2.1.0** — `verify` used to include `terraform.apply`, so a profile documented as +> "full non-mutating verification" planned `terraform apply -auto-approve`. `terraform.apply` was +> removed from that profile. If you were relying on `verify` to apply infrastructure, move that work to +> a dedicated apply workflow. -## Test fixtures +### Profile differences -- `tests/smoke` +| Profile | Purpose | Notable behaviour | +|---|---|---| +| `pull-request` | Fast PR signal | Overrides `terraform-init` to `terraform -chdir= init -backend=false -input=false` (no backend credentials needed) and `terraform-plan` to `terraform -chdir= plan -no-color -lock=false` (speculative, takes no state lock). | +| `verify` | Full non-mutating verification | Real `init` against the configured backend, then `validate` and `plan`. | +| `release` | Release-grade validation before an apply-capable workflow | Same steps as `verify`, plus policies: `requireCleanGitTree`, `requirePinnedTerraformVersion`, `requireApproval`. | -## Verification +`pull-request` uses `stepOverrides`, which replace a step's `run` while keeping its position and +capability — the mechanism for lane-specific flags without duplicating the job template. -`./scripts/verify-composition.sh terraform` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +## Inputs + +`additionalProperties: false` — an unrecognised key fails validation. The schema marks none of the +inner input fields as required, but in practice set at least `terraformDir` and `terraformVersion`. + +| Input | Used by | Description | +|---|---|---| +| `terraformDir` | steps 3–7 | Directory holding the Terraform configuration, relative to the component. Unset ⇒ commands run in the component directory. | +| `terraformVersion` | step 1 | Version for `setup-terraform`. Pin it exactly — `release` policy requires a pinned version. | +| `stackName` | — | Free-form label for the stack. Accepted by the schema; not referenced by any step today. | +| `varFile` | — | Accepted by the schema; not referenced by any step today. Pass var files through the configuration or backend config instead. | +| `backendKey` | — | Accepted by the schema; not referenced by any step today. | + +Backend configuration belongs in `terraformDir`: `verify` and `release` run a plain `terraform init`, +so whatever the backend block declares is what gets used. + +## Credentials + +This composition asserts no provider credentials of its own. `verify` and `release` run a real `init` +and `plan`, so the runner needs whatever the backend and providers require (for the Cloudflare +provider, `CLOUDFLARE_API_TOKEN`). `pull-request` runs `init -backend=false`, so it needs none. + +## Usage + +```yaml +# infra/network/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: network-foundation +spec: + type: terraform + subscribe: + environments: + - name: dev + profile: pull-request + - name: staging + profile: verify + - name: production + profile: release + inputs: + stackName: network-foundation + terraformDir: infra/network + terraformVersion: 1.9.8 +``` + +```bash +orun composition terraform -e +``` diff --git a/stacks/stack-tectonic-flare/compositions/terraform/jobs/terraform-validate.yaml b/stacks/stack-tectonic-flare/compositions/terraform/jobs/terraform-validate.yaml index b220a36..dbf2097 100644 --- a/stacks/stack-tectonic-flare/compositions/terraform/jobs/terraform-validate.yaml +++ b/stacks/stack-tectonic-flare/compositions/terraform/jobs/terraform-validate.yaml @@ -18,6 +18,7 @@ spec: - terraform.init - terraform.validate - terraform.plan + - terraform.apply steps: - id: setup-terraform diff --git a/stacks/stack-tectonic-flare/compositions/terraform/profiles/terraform-verify.yaml b/stacks/stack-tectonic-flare/compositions/terraform/profiles/terraform-verify.yaml index bc097c1..ede907c 100644 --- a/stacks/stack-tectonic-flare/compositions/terraform/profiles/terraform-verify.yaml +++ b/stacks/stack-tectonic-flare/compositions/terraform/profiles/terraform-verify.yaml @@ -14,4 +14,3 @@ spec: - terraform.init - terraform.validate - terraform.plan - - terraform.apply diff --git a/stacks/stack-tectonic-flare/compositions/turbo-package/README.md b/stacks/stack-tectonic-flare/compositions/turbo-package/README.md index 9f7a252..8b5923a 100644 --- a/stacks/stack-tectonic-flare/compositions/turbo-package/README.md +++ b/stacks/stack-tectonic-flare/compositions/turbo-package/README.md @@ -1,27 +1,72 @@ # turbo-package -`turbo-package` is an exported Orun composition in the Stack Tectonic catalog. +Verify a shared package in a **pnpm + Turborepo** workspace: install, build, typecheck. Nothing is +deployed and nothing is published. -## Purpose +Use this for libraries and SDKs that other components depend on — the composition exists so a change to +a shared package gets its own check in the plan instead of only being exercised through consumers. -Verify a shared package in a pnpm and Turbo monorepo +| | | +|---|---| +| Composition type | `turbo-package` | +| Schema | `turbo-package-component` | +| Job | `verify` (default) | +| Default profile | `verify` | +| Runner | `ubuntu-22.04`, timeout `25m`, no retries | +| Scope label | `verify` | -## Contract +## Steps and profiles -- **Type:** `turbo-package` -- **Path:** `compositions/turbo-package` -- **Definition:** `compositions.yaml` +| # | Step | Capability (`turbo-package.`) | What it runs | `quick-check` | `verify` | +|---|---|---|---|:--:|:--:| +| 1 | `setup-node` | `setup-node` | `actions/setup-node@v4` at `nodeVersion` | ✅ | ✅ | +| 2 | `setup-pnpm` | `setup-pnpm` | `pnpm/action-setup@v4` at `pnpmVersion` | ✅ | ✅ | +| 3 | `install-workspace-dependencies` | `install` | `pnpm install --no-frozen-lockfile` | ✅ | ✅ | +| 4 | `pre-build` | `pre-build` | `preBuildCommand`, or prints a skip notice | — | ✅ | +| 5 | `verify-package-structure` | `verify-structure` | `test -f package.json` | ✅ | ✅ | +| 6 | `build-package` | `build` | `buildCommand`, default `pnpm exec turbo run build --filter=./` | — | ✅ | +| 7 | `typecheck-package` | `typecheck` | `typecheckCommand`, default `pnpm exec turbo run typecheck --filter=./` | — | ✅ | -## Example fixtures +There is no `pull-request` profile here — PRs normally use `verify`, and `quick-check` exists for +components where the full build is too slow to run on every push. Every step is `onFailure: stop`. -These sample assets are excerpted or adapted from `example-platform-repo` so the contract is documented with realistic consumer-repo shapes. +This composition has no deploy capability in any profile, so it needs no Cloudflare credentials and +has nothing to gate on `productionBranch`. -- `examples/platform-sdk` +## Inputs -## Test fixtures +`additionalProperties: false` — an unrecognised key fails validation. -- `tests/smoke` +| Input | Required | Description | +|---|:--:|---| +| `nodeVersion` | ✅ | Node version for `actions/setup-node`, e.g. `"20"`. Quote it. | +| `pnpmVersion` | ✅ | pnpm version for `pnpm/action-setup`, e.g. `"9"`. Quote it. | +| `preBuildCommand` | | Codegen or schema generation, before the structure check. Omitted ⇒ `Skipping pre-build.` | +| `buildCommand` | | Overrides the default Turbo build. | +| `typecheckCommand` | | Overrides the default Turbo typecheck. Note the default fails if the package has no `typecheck` task — add the task or set this input. | -## Verification +## Usage -`./scripts/verify-composition.sh turbo-package` checks that this composition keeps its contract, fixture, and generated-doc scaffolding intact. +```yaml +# packages/platform-sdk/component.yaml +apiVersion: sourceplane.io/v1 +kind: Component +metadata: + name: platform-sdk +spec: + type: turbo-package + subscribe: + environments: + - name: dev + profile: verify + - name: staging + profile: verify + inputs: + nodeVersion: "20" + pnpmVersion: "9" + preBuildCommand: pnpm exec turbo run codegen --filter=./ +``` + +```bash +orun composition turbo-package -e +``` diff --git a/stacks/stack-tectonic-flare/stack.yaml b/stacks/stack-tectonic-flare/stack.yaml index 0dd9a52..9a00c74 100644 --- a/stacks/stack-tectonic-flare/stack.yaml +++ b/stacks/stack-tectonic-flare/stack.yaml @@ -3,7 +3,7 @@ kind: Stack metadata: name: tectonic-flare title: Tectonic Flare Platform Stack - version: 2.0.1 + version: 2.1.0 description: Flare edition of full-lifecycle platform stack with profiles, triggers, and override policy. owner: sourceplane tags: