Commit 25d7d67
authored
feat(cloudflare): inject build-time secrets into wrangler image_vars (#61)
Adds scripts/cloudflare-build.sh — a deploy wrapper that:
1. Reads R2 + Turbo secrets from the Cloudflare Workers Build env
(the dashboard's 'Build configuration → Variables and Secrets').
2. Renders a wrangler.deploy.jsonc by overlaying those secrets onto
wrangler.jsonc's image_vars block.
3. Hands off to 'npx wrangler deploy --config wrangler.deploy.jsonc'.
4. Cleans up the rendered file in an EXIT trap so secrets don't outlive
the build.
Why this is needed:
- wrangler image_vars passes string values literally — there is no
${VAR} interpolation against the build env.
- Cloudflare Workers Builds does NOT auto-forward dashboard env vars
to docker --build-arg. They're only available to the build script
itself ('npx wrangler deploy').
- So the only way to surface dashboard secrets to the docker build is
to compose a wrangler config at build time that has the values
inlined into image_vars.
Setup needed in Cloudflare dashboard:
- Workers & Pages → primalprinting → Settings → Build configuration:
Build command: pnpm install --frozen-lockfile && bash scripts/cloudflare-build.sh
Deploy command: (leave empty — script handles the deploy)
- Variables and Secrets — keep the existing Secrets:
R2_S3_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, TURBO_TOKEN
The rendered wrangler.deploy.jsonc is gitignored (would contain plaintext
secrets if accidentally committed).
Locally verified:
- Missing required vars → script exits 1 with a clear error message.
- All vars set → image_vars correctly merged, secrets masked in logs.1 parent bd4710d commit 25d7d67
3 files changed
Lines changed: 59 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 55 | + | |
53 | 56 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 57 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
0 commit comments