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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compositions/cloudflare-worker-turbo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`. Set it
where Terraform components own every resource the bindings name.

## Profiles

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions compositions/cloudflare-worker-turbo/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
11 changes: 10 additions & 1 deletion docs/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOT
apiVersion: sourceplane.io/v1
kind: Intent
metadata:
name: stack-tectonic-render-workers
execution:
state:
workspace: ws_rendercheck
project: render-check
compositions:
sources:
- name: stack-tectonic
kind: archive
path: $work_dir/stack.tgz
discovery:
roots:
- apps/
environments:
stage: {}
EOT
for worker in opted-in default; do
{
echo "apiVersion: sourceplane.io/v1"
echo "kind: Component"
echo "metadata:"
echo " name: $worker"
echo "spec:"
echo " type: cloudflare-worker-turbo"
echo " subscribe:"
echo " environments:"
echo " - name: stage"
echo " profile: deploy"
echo " parameters:"
echo " nodeVersion: \"20\""
echo " pnpmVersion: \"10.12.1\""
echo " workspaceDir: ../.."
echo " appDir: ."
echo " turboFilter: $worker"
echo " wranglerConfig: wrangler.jsonc"
[ "$worker" = opted-in ] && echo " skipResourceProvisioning: true"
} > "$workers/apps/$worker/component.yaml"
done
(cd "$workers" && orun plan --no-catalog-refresh --format json --output plan.json >/dev/null)
deploy_run() { # <component>
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"
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading