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:** `deployTokenEnv` (default empty). The name
of an env var from the component's own `secretEnv` (for example
`CLOUDFLARE_DEPLOY_TOKEN: "secret://<ws>/<project>/CLOUDFLARE_CONTAINERS_TOKEN"`).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the environment in the token secret URI

When a consumer copies this secretEnv example, the URI omits the environment segment used by the deploy profile and existing component references (secret://<workspace>/<project>/<env>/...). The token lookup will therefore point to the wrong secret path, so the opted-in steps may fail to resolve CLOUDFLARE_DEPLOY_TOKEN; include the environment in the example URI.

Useful? React with 👍 / 👎.

Its pre-deploy, migrate, deploy and secrets-live steps then use that token
instead of the profile's `CLOUDFLARE_API_TOKEN`, so one component (a Worker
with a Container, say) can hold a wider token while every other keeps the
workspace's. Empty keeps the profile's token in every step.
- **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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,38 @@ spec:
name: pre-deploy
capability: cloudflare-worker-turbo.pre-deploy
shell: bash
run: "{{ .parameters.preDeployCommand }}"
run: |
{{- if .parameters.deployTokenEnv }}
# deployTokenEnv: this component's own Cloudflare token for this step (from its secretEnv).
token_var="{{ .parameters.deployTokenEnv }}"
export CLOUDFLARE_API_TOKEN="${!token_var:?$token_var is empty: declare it in this component's secretEnv}"
{{- end }}
{{ .parameters.preDeployCommand }}
onFailure: stop

- id: migrate
name: migrate
capability: cloudflare-worker-turbo.migrate
shell: bash
run: "{{ .parameters.migrationCommand }}"
run: |
{{- if .parameters.deployTokenEnv }}
# deployTokenEnv: this component's own Cloudflare token for this step (from its secretEnv).
token_var="{{ .parameters.deployTokenEnv }}"
export CLOUDFLARE_API_TOKEN="${!token_var:?$token_var is empty: declare it in this component's secretEnv}"
{{- end }}
{{ .parameters.migrationCommand }}
onFailure: stop

- id: deploy
name: deploy
capability: cloudflare-worker-turbo.deploy
shell: bash
run: |
{{- if .parameters.deployTokenEnv }}
# deployTokenEnv: this component's own Cloudflare token for this step (from its secretEnv).
token_var="{{ .parameters.deployTokenEnv }}"
export CLOUDFLARE_API_TOKEN="${!token_var:?$token_var is empty: declare it in this component's secretEnv}"
{{- end }}
: "${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID is required}"
: "${CLOUDFLARE_API_TOKEN:?CLOUDFLARE_API_TOKEN is required}"
# A first deploy of a brand-new worker can lose a race inside
Expand Down Expand Up @@ -205,6 +222,11 @@ spec:
capability: cloudflare-worker-turbo.secrets-live
shell: bash
run: |
{{- if .parameters.deployTokenEnv }}
# deployTokenEnv: this component's own Cloudflare token for this step (from its secretEnv).
token_var="{{ .parameters.deployTokenEnv }}"
export CLOUDFLARE_API_TOKEN="${!token_var:?$token_var is empty: declare it in this component's secretEnv}"
{{- end }}
{{- if .parameters.runtimeSecrets }}
# Runtime worker secrets from orun (wire-now-seed-later): the component
# declares its runtime keys in optionalSecretEnv — resolved best-effort
Expand Down
5 changes: 5 additions & 0 deletions compositions/cloudflare-worker-turbo/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ spec:
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.
deployTokenEnv:
type: string
default: ""
pattern: "^([A-Z_][A-Z0-9_]*)?$"
description: The name of an env var, from this component's own secretEnv, holding the Cloudflare API token its pre-deploy, migrate, deploy and secrets-live steps use instead of the profile's CLOUDFLARE_API_TOKEN. Lets one component deploy with a wider token (for example Containers) while every other keeps the workspace's. Empty = the profile's token, as before.
runtimeSecrets:
type: string
default: ""
Expand Down
9 changes: 8 additions & 1 deletion docs/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ must pass `--x-provision=false` to `wrangler deploy`, the second's must not, and
same `wrangler deploy --config ... --env ...` command. A consumer that has not opted in therefore
deploys exactly as before.

### 8. Render `db-migrate`'s build step with and without `buildFilter`
### 8. Render `cloudflare-worker-turbo`'s Cloudflare steps with and without `deployTokenEnv`

The same two fixture workers: the opted-in one also sets `deployTokenEnv: CF_CONTAINERS_TOKEN`.
Its pre-deploy, migrate, deploy and secrets-live steps must each export `CLOUDFLARE_API_TOKEN` from
that variable (failing loudly when it is empty); none of the default worker's steps may mention a
token switch, so a consumer that has not opted in deploys with the profile's token as before.

### 9. Render `db-migrate`'s build step with and without `buildFilter`

The script plans two migration components through the packed artifact, on stage and prod: the
composition's own smoke fixture, which sets `buildFilter: "@example/db"`, and one that leaves it out.
Expand Down
21 changes: 20 additions & 1 deletion scripts/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ for worker in opted-in default; do
echo " appDir: ."
echo " turboFilter: $worker"
echo " wranglerConfig: wrangler.jsonc"
[ "$worker" = opted-in ] && echo " skipResourceProvisioning: true"
[ "$worker" = opted-in ] && echo " skipResourceProvisioning: true" && echo " deployTokenEnv: CF_CONTAINERS_TOKEN"
} > "$workers/apps/$worker/component.yaml"
done
(cd "$workers" && orun plan --no-catalog-refresh --format json --output plan.json >/dev/null)
Expand All @@ -236,6 +236,25 @@ for run in "$opted_in" "$default_run"; do
done
echo "verify: cloudflare-worker-turbo passes --x-provision=false only when a component opts in"

# deployTokenEnv: an opted-in component's pre-deploy, migrate, deploy and
# secrets-live steps use the token its own secretEnv names; a component that
# leaves it out keeps the profile's CLOUDFLARE_API_TOKEN in every step.
step_run() { # <component> <step>
jq -r --arg j "$1" --arg s "$2" \
'.jobs[] | select(.id | startswith($j + ".")) | .steps[] | select(.id == $s) | .run' \
"$workers/plan.json"
}
for step in pre-deploy migrate deploy secrets-live; do
case "$(step_run opted-in "$step")" in
*'token_var="CF_CONTAINERS_TOKEN"'*'export CLOUDFLARE_API_TOKEN="${!token_var:?'*) ;;
*) echo "verify: cloudflare-worker-turbo $step ignores deployTokenEnv" >&2; exit 1 ;;
esac
case "$(step_run default "$step")" in
*token_var*) echo "verify: cloudflare-worker-turbo $step switches tokens without being asked to" >&2; exit 1 ;;
esac
done
echo "verify: cloudflare-worker-turbo uses a component's own deploy token only when it names one"

# db-migrate builds the package a component's buildFilter names, and @saas/db
# when it names none, byte for byte the 0.21.0 command. orun does not copy
# schema defaults into .parameters, so the template's else branch is the
Expand Down
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.23.1
version: 0.24.0
description: Versioned OCI-hosted catalog of Cloudflare, Terraform and monorepo compositions for Sourceplane repositories.
owner: sourceplane
tags:
Expand Down
Loading