diff --git a/compositions/cloudflare-worker-turbo/README.md b/compositions/cloudflare-worker-turbo/README.md index f7e2b1c..5e47511 100644 --- a/compositions/cloudflare-worker-turbo/README.md +++ b/compositions/cloudflare-worker-turbo/README.md @@ -29,6 +29,13 @@ be hydrated from an escrow after deploy. `wiringEnvs` (default `stage,prod`), `wiringFixture` (default `wiring.fixture.json`), `runtimeSecrets` (default `us-east-1`), `orgName`, `owner`, `repo` +- **Optional deploy parameter:** `skipResourceProvisioning` (default `false`). + When `true`, the deploy step passes `--x-provision=false`, so wrangler does + not provision resources or check them over the API. Without it, every R2 + bucket binding is read from the R2 API before the upload, and a deploy + token without R2 permission (the brokered `workers-deploy` template) fails + with `Authentication error [code: 10000]` on `/r2/buckets/`. Set it + where Terraform components own every resource the bindings name. ## Profiles diff --git a/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml b/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml index 0d872d1..787f7ca 100644 --- a/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml +++ b/compositions/cloudflare-worker-turbo/jobs/cloudflare-worker-turbo-verify-deploy.yaml @@ -175,9 +175,18 @@ spec: # "This Worker does not exist on your account" (code 10007). The # deploy is idempotent, so retry it a few times with a short wait # instead of parking the whole convergence on a resume. + # + # skipResourceProvisioning: wrangler's provisioning reads every R2 + # bucket binding over the API before the upload, so the deploy token + # would need R2 permission (the brokered workers-deploy token has + # none). Where Terraform owns the resources, turn it off. + provision_flag="" + {{- if .parameters.skipResourceProvisioning }} + provision_flag="--x-provision=false" + {{- end }} attempts=3 for i in $(seq 1 "$attempts"); do - if pnpm exec wrangler deploy --config {{ .parameters.wranglerConfig }} --env {{ .orun.environment.name }}; then + if pnpm exec wrangler deploy --config {{ .parameters.wranglerConfig }} --env {{ .orun.environment.name }} $provision_flag; then [ "$i" -gt 1 ] && echo "deploy passed on attempt $i/$attempts" exit 0 fi diff --git a/compositions/cloudflare-worker-turbo/schema.yaml b/compositions/cloudflare-worker-turbo/schema.yaml index 5f3cc19..760373b 100644 --- a/compositions/cloudflare-worker-turbo/schema.yaml +++ b/compositions/cloudflare-worker-turbo/schema.yaml @@ -66,6 +66,10 @@ spec: type: string default: wiring.fixture.json description: Committed placeholder wiring map used for offline verify/dry-run rendering + skipResourceProvisioning: + type: boolean + default: false + description: Pass --x-provision=false to wrangler deploy. Wrangler then skips its own resource provisioning, which reads every R2 bucket binding over the API and so needs R2 permission on the deploy token. Set it when Terraform components own every resource the bindings name. runtimeSecrets: type: string default: "" diff --git a/docs/verification.md b/docs/verification.md index 276f463..edc9df9 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -4,7 +4,7 @@ The catalog has one gate, `scripts/verify.sh`, and two workflows that run it. ## `scripts/verify.sh` -The script runs from the repository root and executes six stages in order. Any failure stops the run. +The script runs from the repository root and executes seven stages in order. Any failure stops the run. ### 1. Structural validation of every composition contract @@ -76,6 +76,15 @@ the rendered steps: the first must run its three commands, and the second must s the default `turbo run build` and `turbo run typecheck`. Every structural check passed on the releases that skipped pre-build; this one would have failed them. +### 7. Render `cloudflare-worker-turbo`'s deploy with and without `skipResourceProvisioning` + +The script plans two fixture workers on the `deploy` profile, one setting `skipResourceProvisioning: +true` and one leaving it out. The deploy profile binds secrets, so this fixture's intent declares a +placeholder workspace and project; nothing is resolved at plan time. The first worker's deploy step +must pass `--x-provision=false` to `wrangler deploy`, the second's must not, and both must keep the +same `wrangler deploy --config ... --env ...` command. A consumer that has not opted in therefore +deploys exactly as before. + ## Verify workflow `.github/workflows/verify.yml` runs on every pull request and every push to `main`. It is a single diff --git a/scripts/verify.sh b/scripts/verify.sh index 64db414..46d0013 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -164,3 +164,74 @@ expect defaults pre-build 'echo "Skipping pre-build."' expect defaults build-package "pnpm exec turbo run build --filter=./" expect defaults typecheck-package "pnpm exec turbo run typecheck --filter=./" echo "verify: turbo-package renders declared commands and falls back to its defaults" + +# cloudflare-worker-turbo's deploy step passes --x-provision=false only when a +# component sets skipResourceProvisioning: absent or false keeps wrangler's +# default, so no consumer changes behaviour until it opts in. The deploy +# profile binds secrets, so this fixture declares a placeholder workspace. +workers="$work_dir/workers" +mkdir -p "$workers/apps/opted-in" "$workers/apps/default" +cat > "$workers/intent.yaml" < "$workers/apps/$worker/component.yaml" +done +(cd "$workers" && orun plan --no-catalog-refresh --format json --output plan.json >/dev/null) +deploy_run() { # + jq -r --arg j "$1" \ + '.jobs[] | select(.id | startswith($j + ".")) | .steps[] | select(.id == "deploy") | .run' \ + "$workers/plan.json" +} +opted_in="$(deploy_run opted-in)" +default_run="$(deploy_run default)" +case "$opted_in" in + *'provision_flag="--x-provision=false"'*) ;; + *) echo "verify: cloudflare-worker-turbo deploy ignores skipResourceProvisioning: true" >&2; exit 1 ;; +esac +case "$default_run" in + *"--x-provision=false"*) echo "verify: cloudflare-worker-turbo deploy skips provisioning without being asked to" >&2; exit 1 ;; +esac +for run in "$opted_in" "$default_run"; do + case "$run" in + *'wrangler deploy --config wrangler.jsonc --env stage $provision_flag'*) ;; + *) echo "verify: cloudflare-worker-turbo deploy command changed shape: $run" >&2; exit 1 ;; + esac +done +echo "verify: cloudflare-worker-turbo passes --x-provision=false only when a component opts in" diff --git a/stack.yaml b/stack.yaml index 29faaef..bc35895 100644 --- a/stack.yaml +++ b/stack.yaml @@ -3,7 +3,7 @@ kind: Stack metadata: name: stack-tectonic title: Stack Tectonic - version: 0.20.1 + version: 0.21.0 description: Versioned OCI-hosted catalog of Cloudflare, Terraform and monorepo compositions for Sourceplane repositories. owner: sourceplane tags: