fix(deploy): run Cloudflare deploys from verified artifacts behind pinned targets

Repository code outside .github/ needs no review, but every deploy job held a
Cloudflare token strong enough to write any Worker on the account (the data
sync Workflow PUT has no per-Worker permission). A dev merge could therefore
overwrite production Workers.

Split each service into a build job with no environment, secrets, or OIDC token
that uploads a SHA256SUMS artifact, and a deploy job in dev|production that
checks out only .github/release/, verifies the artifact against the build job's
digest, installs the cf/wrangler CLI pinned here, and runs only deploy-*.sh.

The deploy scripts treat the artifact as data and refuse it unless its resolved
config equals the pinned target in .github/release/targets/ exactly: Worker
names, routes, custom domains, crons, Workflow names, and bindings. For cf
services the pinned config is what cf reads. That is what makes an account-wide
token safe, and it keeps production out of reach of a dev merge.

Adds the cf 1.0.0-beta.12 and wrangler 4.110.0 lockfiles the deploy jobs
install with npm ci --ignore-scripts.
This commit is contained in:
Dax Raad
2026-11-11 04:51:07 -05:00
Unverified
parent e56eff2bc0
commit 7bac5bad02
38 changed files with 3702 additions and 52 deletions
+61
View File
@@ -0,0 +1,61 @@
# Deploy boundary
The deploy workflows (`deploy.yml`, `deploy-site.yml`, `deploy-files.yml`,
`deploy-update.yml`) split every service in two:
- **build** runs repository code (`bun install`, `cf build`, `bun script/build.ts`,
`wrangler deploy --dry-run`) with no environment, no secrets, and no OIDC
token. It uploads the deploy-ready output with a `SHA256SUMS` and reports that
manifest's digest as a job output.
- **deploy** runs in the `dev` or `production` environment, assumes the stage's
AWS role, mints a short-lived Cloudflare token from the token issuer
(`cloudflare-token.sh`), and checks out only `.github/release/`. It verifies
the artifact against the digest the build job reported, installs the pinned
`cf`/`wrangler` CLI (`npm ci --ignore-scripts`), and runs only a
`deploy-*.sh` script here.
Repository code outside `.github/` does not need Dax's review, so the deploy job
must never execute it. The scripts treat the artifact as data: Worker code and
assets may change freely, but names, routes, custom domains, crons, Workflow and
export names, and every binding (including service bindings to other Workers)
come from `targets/`. An artifact whose resolved config is not byte-for-byte one
of those pinned targets is refused before the token is used.
For `cf` services the pinned target is also what `cf` reads: the script copies
the target over the artifact's config after validating it. For `wrangler`
services the artifact is only `index.js`; the complete `wrangler.json` is the
pinned target.
## Why the token can be account-wide
Cloudflare has no per-Worker permission for Workflows. The data sync Worker owns
a Workflow, and `PUT /accounts/<id>/workflows/<name>` needs account-wide
`Workers Scripts Write`, so `Individual Workers Editor` fails that deploy.
Dev and production therefore mint a token that can write any Worker on the
account. That is only safe because the code holding it is this directory: one
reviewed script per service, on a verified artifact, with every destination
pinned in `targets/`. Do not move a deploy back into a job that runs repository
code, and do not widen a script's accepted targets without review.
Production keeps this token only for a Dax-approved fast-forward of `dev`; a
`dev` merge cannot reach the production environment.
## Production promotion notes
Moving `dev` to `production` deploys the same pinned targets with the same
scripts, but production holds an account-wide token and a bad deploy is live.
Before promoting:
1. Confirm every dev deploy job is green on the commit being promoted
(`deploy`, `deploy-site`, `deploy-files`; `deploy-update` runs on production
only).
2. Diff `.github/release/targets/` against `origin/production`. Any change here
is a change to what production may deploy.
3. Rollback is a fast-forward back to the previous `production` commit, which
redeploys the previous Worker code from the same pinned targets. If a target
itself changed and must be reverted, revert it with the deploy commit.
4. The production deploy job runs only `.github/release/` at `github.sha`; it
does not run repo code. The build job still runs repo code, but with no
secrets and no OIDC token.
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
{
"private": true,
"description": "The pinned cf CLI that deploy-site.sh runs; npm ci --ignore-scripts installs exactly package-lock.json.",
"dependencies": {
"cf": "1.0.0-beta.12"
}
}
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
# deploy-data.sh <dev|production> <dir> <secrets.json>: deploys the data site's
# three Workers (og, sync, default) from one verified Build Output artifact
# (services/data/.cloudflare/output) with the cf CLI pinned in
# cf/package-lock.json. Order matches services/data/script/deploy.ts: the OG
# Worker first because the site binds to it, then sync, then the site.
#
# The build job has no secrets, so the Workers' code and assets are untrusted
# by design: the data site can change freely. The configs may not. All three
# must equal targets/data/<mode>/*.json exactly, and the pinned copies are what
# cf reads: another Worker name, route, cron, Workflow name, or binding
# (including the OG service binding) is refused before the token is used.
#
# The sync Worker's Workflow PUT needs account-wide Workers Scripts Write;
# Cloudflare has no per-Worker Workflows permission. That is safe only because
# this script (and the other deploy-*.sh) pin every target.
. "$(dirname "$0")/lib.sh"
mode=$1
src=$(cd "$2" && pwd)
secrets=$(posix "$3")
release=$(cd "$(dirname "$0")" && pwd)
case "$mode" in
dev | production) ;;
*) die "Unknown data mode: $mode" ;;
esac
target="$release/targets/data/$mode"
for file in root default og sync; do
[ -f "$target/$file.json" ] || die "No pinned data target $target/$file.json"
done
: "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN}"
# Pinned in targets/ and in the token issuer's config (anomalyco/secrets).
export CLOUDFLARE_ACCOUNT_ID=15d29c8639fd3733b1b5486a2acfd968
unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256SUMS \
! -path ./v0/config.json \
! -path ./v0/workers/default/worker.config.json \
! -path './v0/workers/default/bundle/*' \
! -path './v0/workers/default/assets/*' \
! -path ./v0/workers/og/worker.config.json \
! -path './v0/workers/og/bundle/*' \
! -path ./v0/workers/sync/worker.config.json \
! -path './v0/workers/sync/bundle/*')
[ -z "$unexpected" ] || die "Unexpected files in the data artifact: $unexpected"
for dir in default og sync; do
[ -f "$src/v0/workers/$dir/bundle/index.mjs" ] || die "The data artifact has no $dir bundle/index.mjs"
done
[ -d "$src/v0/workers/default/assets" ] || die "The data artifact has no default assets directory"
expect_json "$src/v0/config.json" "$target/root.json" "The data root config"
expect_json "$src/v0/workers/default/worker.config.json" "$target/default.json" "The data site's Worker config"
expect_json "$src/v0/workers/og/worker.config.json" "$target/og.json" "The OG Worker's config"
expect_json "$src/v0/workers/sync/worker.config.json" "$target/sync.json" "The sync Worker's config"
jq -e 'keys == ["DATA_DATABASE_HOST", "DATA_DATABASE_PASSWORD", "DATA_DATABASE_USERNAME", "DATA_HIDDEN_MODELS", "R2_SQL_AUTH_TOKEN"]
and all(.[]; type == "string" and length > 0)' "$secrets" > /dev/null ||
die "The secrets file does not hold exactly the data Workers' secrets"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
output="$work/.cloudflare/output/v0"
mkdir -p "$output/workers/default" "$output/workers/og" "$output/workers/sync"
cp "$target/root.json" "$output/config.json"
for dir in default og sync; do
cp "$target/$dir.json" "$output/workers/$dir/worker.config.json"
cp -R "$src/v0/workers/$dir/bundle" "$output/workers/$dir/bundle"
done
cp -R "$src/v0/workers/default/assets" "$output/workers/default/assets"
# Each Worker gets only the secrets its pinned config declares (cf rejects a
# missing one). The files are 0600 in the runner's temp directory and removed
# with the work directory.
umask 077
jq '{DATA_DATABASE_HOST, DATA_DATABASE_USERNAME, DATA_DATABASE_PASSWORD}' "$secrets" > "$work/default-secrets.json"
cp "$secrets" "$work/sync-secrets.json"
cf="$release/cf/node_modules/.bin/cf"
[ -x "$cf" ] || die "Install the pinned cf CLI first: npm ci --ignore-scripts in .github/release/cf"
cd "$work"
"$cf" deploy --prebuilt --mode "$mode" --worker "$(jq -r .name "$target/og.json")"
"$cf" deploy --prebuilt --mode "$mode" --worker "$(jq -r .name "$target/sync.json")" --secrets-file "$work/sync-secrets.json"
"$cf" deploy --prebuilt --mode "$mode" --worker "$(jq -r .name "$target/default.json")" --secrets-file "$work/default-secrets.json"
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# deploy-files.sh <dev|production> <dir>: deploys the files Worker from a
# verified bundle artifact (index.js built by `wrangler deploy --dry-run`)
# with the wrangler CLI pinned in wrangler/package-lock.json.
#
# The build job has no secrets, so the bundle is untrusted by design: its code
# can change freely. The rest of the Worker does not come from the artifact at
# all: the name, route, R2 bucket, and STAGE var are the complete pinned
# wrangler.json in targets/files/<mode>/, which is what wrangler reads. The
# token can write every Worker on the account, so nothing in the artifact can
# name another destination.
. "$(dirname "$0")/lib.sh"
mode=$1
src=$(cd "$2" && pwd)
release=$(cd "$(dirname "$0")" && pwd)
case "$mode" in
dev | production) ;;
*) die "Unknown files mode: $mode" ;;
esac
target="$release/targets/files/$mode/wrangler.json"
[ -f "$target" ] || die "No pinned files target for $mode"
: "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN}"
# Pinned in targets/ and in the token issuer's config (anomalyco/secrets).
export CLOUDFLARE_ACCOUNT_ID=15d29c8639fd3733b1b5486a2acfd968
unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256SUMS ! -path ./index.js)
[ -z "$unexpected" ] || die "Unexpected files in the files artifact: $unexpected"
[ -f "$src/index.js" ] || die "The files artifact has no index.js"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cp "$src/index.js" "$work/index.js"
cp "$target" "$work/wrangler.json"
wrangler="$release/wrangler/node_modules/.bin/wrangler"
[ -x "$wrangler" ] || die "Install the pinned wrangler CLI first: npm ci --ignore-scripts in .github/release/wrangler"
cd "$work"
"$wrangler" deploy --config wrangler.json --no-bundle
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# deploy-legacy.sh <dev|production> <dir> <secrets.json>: deploys the legacy
# Worker from a verified Build Output artifact (services/legacy/.cloudflare/output)
# with the cf CLI pinned in cf/package-lock.json.
#
# The build job has no secrets, so the Worker's code is untrusted by design.
# Its config must equal targets/legacy/<mode>/*.json exactly, and the pinned
# copy is what cf reads: another Worker name, domain, or binding is refused
# before the token is used. The GitHub App secrets are read from AWS by the
# workflow into <secrets.json> and reach cf as a file, never argv.
. "$(dirname "$0")/lib.sh"
mode=$1
src=$(cd "$2" && pwd)
secrets=$(posix "$3")
release=$(cd "$(dirname "$0")" && pwd)
case "$mode" in
dev | production) ;;
*) die "Unknown legacy mode: $mode" ;;
esac
target="$release/targets/legacy/$mode"
[ -f "$target/root.json" ] && [ -f "$target/worker.json" ] || die "No pinned legacy targets for $mode"
: "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN}"
# Pinned in targets/ and in the token issuer's config (anomalyco/secrets).
export CLOUDFLARE_ACCOUNT_ID=15d29c8639fd3733b1b5486a2acfd968
unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256SUMS \
! -path ./v0/config.json \
! -path ./v0/workers/default/worker.config.json \
! -path './v0/workers/default/bundle/*')
[ -z "$unexpected" ] || die "Unexpected files in the legacy artifact: $unexpected"
[ -f "$src/v0/workers/default/bundle/index.js" ] || die "The legacy artifact has no bundle/index.js"
expect_json "$src/v0/config.json" "$target/root.json" "The legacy Worker's root config"
expect_json "$src/v0/workers/default/worker.config.json" "$target/worker.json" "The legacy Worker's config"
jq -e 'keys == ["GITHUB_APP_ID", "GITHUB_APP_PRIVATE_KEY"] and all(.[]; type == "string" and length > 0)' \
"$secrets" > /dev/null || die "The secrets file does not hold exactly GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
output="$work/.cloudflare/output/v0"
mkdir -p "$output/workers/default"
cp "$target/root.json" "$output/config.json"
cp "$target/worker.json" "$output/workers/default/worker.config.json"
cp -R "$src/v0/workers/default/bundle" "$output/workers/default/bundle"
cf="$release/cf/node_modules/.bin/cf"
[ -x "$cf" ] || die "Install the pinned cf CLI first: npm ci --ignore-scripts in .github/release/cf"
cd "$work"
"$cf" deploy --prebuilt --mode "$mode" --secrets-file "$secrets"
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# deploy-site.sh <dev|production> <dir>: deploys the site Worker from a verified
# Build Output artifact (services/site/.cloudflare/output) with the cf CLI
# pinned in cf/package-lock.json, which the workflow installs before the token
# is in reach.
#
# The build job has no secrets, so the Worker's code and assets are untrusted
# by design: the site can change freely. Its config may not. The artifact's
# root config and Worker config must equal targets/site/<mode>/*.json exactly,
# and those pinned copies are what cf reads: another Worker name, route,
# domain, or binding is refused before the token is used.
. "$(dirname "$0")/lib.sh"
mode=$1
src=$(cd "$2" && pwd)
release=$(cd "$(dirname "$0")" && pwd)
case "$mode" in
dev | production) ;;
*) die "Unknown site mode: $mode" ;;
esac
target="$release/targets/site/$mode"
[ -f "$target/root.json" ] && [ -f "$target/worker.json" ] || die "No pinned site targets for $mode"
: "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN}"
# Pinned in targets/ and in the token issuer's config (anomalyco/secrets).
export CLOUDFLARE_ACCOUNT_ID=15d29c8639fd3733b1b5486a2acfd968
unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256SUMS \
! -path ./v0/config.json \
! -path ./v0/workers/default/worker.config.json \
! -path './v0/workers/default/bundle/*' \
! -path './v0/workers/default/assets/*')
[ -z "$unexpected" ] || die "Unexpected files in the site artifact: $unexpected"
[ -f "$src/v0/workers/default/bundle/index.mjs" ] || die "The site artifact has no bundle/index.mjs"
[ -d "$src/v0/workers/default/assets" ] || die "The site artifact has no assets directory"
expect_json "$src/v0/config.json" "$target/root.json" "The site's root config"
expect_json "$src/v0/workers/default/worker.config.json" "$target/worker.json" "The site's Worker config"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
output="$work/.cloudflare/output/v0"
mkdir -p "$output/workers/default"
cp "$target/root.json" "$output/config.json"
cp "$target/worker.json" "$output/workers/default/worker.config.json"
cp -R "$src/v0/workers/default/bundle" "$output/workers/default/bundle"
cp -R "$src/v0/workers/default/assets" "$output/workers/default/assets"
cf="$release/cf/node_modules/.bin/cf"
[ -x "$cf" ] || die "Install the pinned cf CLI first: npm ci --ignore-scripts in .github/release/cf"
cd "$work"
"$cf" deploy --prebuilt --mode "$mode"
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# deploy-update.sh <production> <dir>: deploys the update Worker from a verified
# bundle artifact (index.js built by `wrangler deploy --dry-run`) with the
# wrangler CLI pinned in wrangler/package-lock.json.
#
# The build job has no secrets, so the bundle is untrusted by design: its code
# can change freely. The rest of the Worker does not come from the artifact at
# all: the name, routes, custom domain, D1 database, and Pipelines stream are
# the complete pinned wrangler.json in targets/update/production/, which is what
# wrangler reads. Only production deploys this Worker.
. "$(dirname "$0")/lib.sh"
mode=$1
src=$(cd "$2" && pwd)
release=$(cd "$(dirname "$0")" && pwd)
[ "$mode" = production ] || die "The update Worker deploys only to production, not $mode"
target="$release/targets/update/production/wrangler.json"
[ -f "$target" ] || die "No pinned update target"
: "${CLOUDFLARE_API_TOKEN:?Set CLOUDFLARE_API_TOKEN}"
# Pinned in targets/ and in the token issuer's config (anomalyco/secrets).
export CLOUDFLARE_ACCOUNT_ID=15d29c8639fd3733b1b5486a2acfd968
unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256SUMS ! -path ./index.js)
[ -z "$unexpected" ] || die "Unexpected files in the update artifact: $unexpected"
[ -f "$src/index.js" ] || die "The update artifact has no index.js"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cp "$src/index.js" "$work/index.js"
cp "$target" "$work/wrangler.json"
wrangler="$release/wrangler/node_modules/.bin/wrangler"
[ -x "$wrangler" ] || die "Install the pinned wrangler CLI first: npm ci --ignore-scripts in .github/release/wrangler"
cd "$work"
"$wrangler" deploy --config wrangler.json --no-bundle
+5
View File
@@ -8,6 +8,10 @@ inputs:
description: Space-separated name=digest pairs for artifacts made by sign jobs, from their job outputs
required: false
default: ""
require-digests:
description: Require every artifact to match a reported digest (deploy jobs set this)
required: false
default: "false"
runs:
using: composite
steps:
@@ -19,3 +23,4 @@ runs:
run: bash "${GITHUB_ACTION_PATH//\\//}/../verify-artifacts.sh" "$RUNNER_TEMP/in"
env:
OPENCODE_DIGESTS: ${{ inputs.digests }}
OPENCODE_REQUIRE_DIGESTS: ${{ inputs.require-digests }}
+8
View File
@@ -134,3 +134,11 @@ push_git() {
commit -q -m "$message"
git -C "$dir" push -q origin HEAD:master
}
# expect_json <artifact-file> <pinned-target> <label>: the artifact's resolved
# config must equal the pinned target exactly before anything is deployed.
# Deploy scripts use this with targets/; release scripts do not.
expect_json() {
jq -e --slurp '.[0] == .[1]' "$1" "$2" > /dev/null ||
die "$3 in the artifact is not the pinned target ($2)"
}
+20
View File
@@ -0,0 +1,20 @@
# Pinned deploy targets
These files are the allow-list for the deploy jobs that hold a Cloudflare
token. `deploy-*.sh` refuses an artifact whose resolved config is not exactly
one of these files, then deploys the pinned config (never the artifact's copy).
The deploy token can write every Worker on the account (the data sync Workflow
needs account-wide `Workers Scripts Write`; Cloudflare has no per-Worker
Workflows permission), so changing what a stage can deploy means changing these
files, which CODEOWNERS (`/.github/ @thdxr`) reviews.
- `site/`, `legacy/`, `data/`: expected `v0/config.json` and
`v0/workers/<dir>/worker.config.json` from the `cf` Build Output artifact.
- `files/`, `update/`: the complete `wrangler.json` the deploy script passes to
the pinned wrangler CLI. The artifact is only the bundled `index.js`; these
services have no config in the artifact to trust.
A Worker's own code and assets are expected to change freely. Names, routes,
custom domains, crons, Workflow/export names, and every binding (including
service bindings to other Workers) are pinned here.
@@ -0,0 +1,39 @@
{
"name": "opencode-data-dev",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"triggers": [
{ "type": "fetch", "pattern": "dev.opencode.ai/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/en/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/zh/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/zht/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/ko/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/de/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/es/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/fr/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/it/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/da/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/ja/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/pl/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/ru/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/uk/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/ar/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/no/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/br/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/th/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/tr/data*", "zone": "opencode.ai" }
],
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"ASSETS": { "type": "assets" },
"OG_WORKER": { "type": "worker", "worker": "opencode-data-og-dev" },
"STAGE": { "type": "text", "value": "dev" },
"PUBLIC_URL": { "type": "text", "value": "https://dev.opencode.ai/data" },
"DATA_DATABASE_HOST": { "type": "secret" },
"DATA_DATABASE_USERNAME": { "type": "secret" },
"DATA_DATABASE_PASSWORD": { "type": "secret" }
},
"manifest": { "type": "partial", "mainModule": "index.mjs", "modules": {} }
}
+20
View File
@@ -0,0 +1,20 @@
{
"name": "opencode-data-og-dev",
"compatibilityDate": "2026-07-01",
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"manifest": {
"type": "partial",
"mainModule": "index.mjs",
"modules": {
"harfbuzz.wasm": { "type": "wasm" },
"satori-layout.wasm": { "type": "wasm" },
"resvg.wasm": { "type": "wasm" },
"opentui-mono-regular-rest.bin": { "type": "data" },
"opentui-mono-regular-latin.bin": { "type": "data" },
"opentui-mono-bold-rest.bin": { "type": "data" },
"opentui-mono-bold-latin.bin": { "type": "data" }
}
}
}
@@ -0,0 +1,4 @@
{
"accountId": "15d29c8639fd3733b1b5486a2acfd968",
"buildContext": { "isPreview": false, "mode": "dev" }
}
@@ -0,0 +1,31 @@
{
"name": "opencode-data-sync-dev",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"triggers": [
{ "type": "scheduled", "schedule": "5 * * * *" },
{ "type": "scheduled", "schedule": "20 3 * * *" }
],
"limits": { "cpuMs": 300000 },
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"DataSyncWorkflow": {
"type": "workflow",
"name": "opencode-data-sync-dev",
"worker": "opencode-data-sync-dev",
"exportName": "DataSyncWorkflow"
},
"STAGE": { "type": "text", "value": "dev" },
"DATA_DATABASE_HOST": { "type": "secret" },
"DATA_DATABASE_USERNAME": { "type": "secret" },
"DATA_DATABASE_PASSWORD": { "type": "secret" },
"R2_SQL_AUTH_TOKEN": { "type": "secret" },
"DATA_HIDDEN_MODELS": { "type": "secret" }
},
"exports": {
"DataSyncWorkflow": { "type": "workflow", "name": "opencode-data-sync-dev" }
},
"manifest": { "type": "partial", "mainModule": "index.mjs", "modules": {} }
}
@@ -0,0 +1,39 @@
{
"name": "opencode-data-production",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"triggers": [
{ "type": "fetch", "pattern": "opencode.ai/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/en/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/zh/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/zht/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/ko/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/de/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/es/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/fr/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/it/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/da/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/ja/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/pl/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/ru/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/uk/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/ar/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/no/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/br/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/th/data*", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/tr/data*", "zone": "opencode.ai" }
],
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"ASSETS": { "type": "assets" },
"OG_WORKER": { "type": "worker", "worker": "opencode-data-og-production" },
"STAGE": { "type": "text", "value": "production" },
"PUBLIC_URL": { "type": "text", "value": "https://opencode.ai/data" },
"DATA_DATABASE_HOST": { "type": "secret" },
"DATA_DATABASE_USERNAME": { "type": "secret" },
"DATA_DATABASE_PASSWORD": { "type": "secret" }
},
"manifest": { "type": "partial", "mainModule": "index.mjs", "modules": {} }
}
@@ -0,0 +1,20 @@
{
"name": "opencode-data-og-production",
"compatibilityDate": "2026-07-01",
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"manifest": {
"type": "partial",
"mainModule": "index.mjs",
"modules": {
"harfbuzz.wasm": { "type": "wasm" },
"satori-layout.wasm": { "type": "wasm" },
"resvg.wasm": { "type": "wasm" },
"opentui-mono-regular-rest.bin": { "type": "data" },
"opentui-mono-regular-latin.bin": { "type": "data" },
"opentui-mono-bold-rest.bin": { "type": "data" },
"opentui-mono-bold-latin.bin": { "type": "data" }
}
}
}
@@ -0,0 +1,4 @@
{
"accountId": "15d29c8639fd3733b1b5486a2acfd968",
"buildContext": { "isPreview": false, "mode": "production" }
}
@@ -0,0 +1,31 @@
{
"name": "opencode-data-sync-production",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"triggers": [
{ "type": "scheduled", "schedule": "5 * * * *" },
{ "type": "scheduled", "schedule": "20 3 * * *" }
],
"limits": { "cpuMs": 300000 },
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"DataSyncWorkflow": {
"type": "workflow",
"name": "opencode-data-sync-production",
"worker": "opencode-data-sync-production",
"exportName": "DataSyncWorkflow"
},
"STAGE": { "type": "text", "value": "production" },
"DATA_DATABASE_HOST": { "type": "secret" },
"DATA_DATABASE_USERNAME": { "type": "secret" },
"DATA_DATABASE_PASSWORD": { "type": "secret" },
"R2_SQL_AUTH_TOKEN": { "type": "secret" },
"DATA_HIDDEN_MODELS": { "type": "secret" }
},
"exports": {
"DataSyncWorkflow": { "type": "workflow", "name": "opencode-data-sync-production" }
},
"manifest": { "type": "partial", "mainModule": "index.mjs", "modules": {} }
}
@@ -0,0 +1,11 @@
{
"name": "opencode-dev-files",
"main": "index.js",
"no_bundle": true,
"compatibility_date": "2026-08-01",
"workers_dev": false,
"preview_urls": false,
"vars": { "STAGE": "dev" },
"routes": [{ "pattern": "dev.opencode.ai/files/*", "zone_name": "opencode.ai" }],
"r2_buckets": [{ "binding": "FILES", "bucket_name": "opencode-dev-files" }]
}
@@ -0,0 +1,11 @@
{
"name": "opencode-production-files",
"main": "index.js",
"no_bundle": true,
"compatibility_date": "2026-08-01",
"workers_dev": false,
"preview_urls": false,
"vars": { "STAGE": "production" },
"routes": [{ "pattern": "opencode.ai/files/*", "zone_name": "opencode.ai" }],
"r2_buckets": [{ "binding": "FILES", "bucket_name": "opencode-production-files" }]
}
@@ -0,0 +1,4 @@
{
"accountId": "15d29c8639fd3733b1b5486a2acfd968",
"buildContext": { "isPreview": false, "mode": "dev" }
}
@@ -0,0 +1,22 @@
{
"name": "opencode-legacy-dev",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"domains": ["dev.opncd.ai", "api.dev.opencode.ai"],
"logpush": true,
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"GITHUB_APP_ID": { "type": "secret" },
"GITHUB_APP_PRIVATE_KEY": { "type": "secret" }
},
"manifest": {
"type": "complete",
"mainModule": "index.js",
"modules": {
"index.js": { "type": "esm" },
"index.js.map": { "type": "sourcemap" }
}
}
}
@@ -0,0 +1,4 @@
{
"accountId": "15d29c8639fd3733b1b5486a2acfd968",
"buildContext": { "isPreview": false, "mode": "production" }
}
@@ -0,0 +1,22 @@
{
"name": "opencode-legacy-production",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"domains": ["opncd.ai", "api.opencode.ai"],
"logpush": true,
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"GITHUB_APP_ID": { "type": "secret" },
"GITHUB_APP_PRIVATE_KEY": { "type": "secret" }
},
"manifest": {
"type": "complete",
"mainModule": "index.js",
"modules": {
"index.js": { "type": "esm" },
"index.js.map": { "type": "sourcemap" }
}
}
}
@@ -0,0 +1,4 @@
{
"accountId": "15d29c8639fd3733b1b5486a2acfd968",
"buildContext": { "isPreview": false, "mode": "dev" }
}
@@ -0,0 +1,38 @@
{
"name": "opencode-site-dev",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"assets": {
"htmlHandling": "drop-trailing-slash",
"runWorkerFirst": [
"/docs",
"/docs/*",
"!/docs/_build/*",
"!/docs/assets/*",
"!/docs/pagefind/*",
"!/docs/favicon.svg",
"!/docs/llms.txt",
"!/docs/sitemap.xml",
"!/docs/openapi.json",
"/v1/docs",
"/v1/docs/*",
"!/v1/docs/assets/*",
"!/v1/docs/pagefind/*",
"!/v1/docs/llms.txt",
"!/v1/docs/theme.json"
]
},
"domains": ["dev.opencode.ai", "docs.dev.opencode.ai"],
"triggers": [
{ "type": "fetch", "pattern": "dev.opencode.ai", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "dev.opencode.ai/*", "zone": "opencode.ai" }
],
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"ASSETS": { "type": "assets" },
"STAGE": { "type": "text", "value": "dev" }
},
"manifest": { "type": "partial", "mainModule": "index.mjs", "modules": {} }
}
@@ -0,0 +1,4 @@
{
"accountId": "15d29c8639fd3733b1b5486a2acfd968",
"buildContext": { "isPreview": false, "mode": "production" }
}
@@ -0,0 +1,38 @@
{
"name": "opencode-site-production",
"compatibilityDate": "2026-07-25",
"compatibilityFlags": ["nodejs_compat"],
"assets": {
"htmlHandling": "drop-trailing-slash",
"runWorkerFirst": [
"/docs",
"/docs/*",
"!/docs/_build/*",
"!/docs/assets/*",
"!/docs/pagefind/*",
"!/docs/favicon.svg",
"!/docs/llms.txt",
"!/docs/sitemap.xml",
"!/docs/openapi.json",
"/v1/docs",
"/v1/docs/*",
"!/v1/docs/assets/*",
"!/v1/docs/pagefind/*",
"!/v1/docs/llms.txt",
"!/v1/docs/theme.json"
]
},
"domains": ["opencode.ai", "docs.opencode.ai"],
"triggers": [
{ "type": "fetch", "pattern": "opencode.ai", "zone": "opencode.ai" },
{ "type": "fetch", "pattern": "opencode.ai/*", "zone": "opencode.ai" }
],
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"ASSETS": { "type": "assets" },
"STAGE": { "type": "text", "value": "production" }
},
"manifest": { "type": "partial", "mainModule": "index.mjs", "modules": {} }
}
@@ -0,0 +1,22 @@
{
"name": "opencode-update",
"main": "index.js",
"no_bundle": true,
"compatibility_date": "2026-07-21",
"workers_dev": false,
"preview_urls": false,
"pipelines": [{ "binding": "EVENTS", "stream": "251a89241c3a461c9007f6b6f345ed8b" }],
"routes": [
{ "pattern": "update.opencode.ai", "custom_domain": true },
{ "pattern": "opencode.ai/update", "zone_name": "opencode.ai" },
{ "pattern": "opencode.ai/update/*", "zone_name": "opencode.ai" }
],
"d1_databases": [
{
"binding": "DB",
"database_name": "opencode-update",
"database_id": "2c010a96-811f-43d5-804d-7188534e5858"
}
],
"observability": { "enabled": true }
}
+10
View File
@@ -7,6 +7,14 @@ inputs:
path:
description: Directory to upload
required: true
retention-days:
description: Days to keep the artifact (0 keeps the repository default)
required: false
default: "0"
include-hidden-files:
description: Include hidden files (deploy Build Output carries .vite metadata)
required: false
default: "false"
outputs:
digest:
description: SHA-256 of the artifact's SHA256SUMS
@@ -23,4 +31,6 @@ runs:
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
retention-days: ${{ inputs.retention-days }}
include-hidden-files: ${{ inputs.include-hidden-files }}
if-no-files-found: error
+21 -1
View File
@@ -2,16 +2,36 @@
# verify-artifacts.sh <dir>: checks every artifact downloaded into <dir>/<name> against its SHA256SUMS and that it
# holds exactly the listed files. Artifacts made by sign jobs (sign-*) must also match the manifest digest their
# job reported (OPENCODE_DIGESTS="name=digest ..."), so an artifact replaced after that job finished is rejected.
# Deploy jobs set OPENCODE_REQUIRE_DIGESTS=true: every artifact must match a reported digest, because the digest
# is what ties the bytes to the build job that made them.
. "$(dirname "$0")/lib.sh"
root=$(posix "$1")
# download-artifact unpacks a lone matching artifact straight into <dir>; put it back under its name, found by
# its manifest's reported digest.
if [ -f "$root/SHA256SUMS" ]; then
lone=$(sha256 "$root/SHA256SUMS" | cut -c1-64)
name=""
for pair in ${OPENCODE_DIGESTS:-}; do
if [ "${pair#*=}" = "$lone" ]; then name=${pair%%=*}; fi
done
[ -n "$name" ] || die "The downloaded artifact's SHA256SUMS does not have a reported digest"
staging=$(mktemp -d)
find "$root" -mindepth 1 -maxdepth 1 -exec mv {} "$staging/" \;
mv "$staging" "$root/$name"
fi
shopt -s nullglob
for dir in "$root"/*/; do
name=$(basename "$dir")
digest=""
for pair in ${OPENCODE_DIGESTS:-}; do
if [ "${pair%%=*}" = "$name" ]; then digest=${pair#*=}; fi
done
case "$name" in sign-*) [[ "$digest" =~ ^[0-9a-f]{64}$ ]] || die "Missing digest for $name" ;; esac
if [ -n "${OPENCODE_REQUIRE_DIGESTS:-}" ]; then
[[ "$digest" =~ ^[0-9a-f]{64}$ ]] || die "Missing digest for $name"
else
case "$name" in sign-*) [[ "$digest" =~ ^[0-9a-f]{64}$ ]] || die "Missing digest for $name" ;; esac
fi
(
cd "$dir"
if [ -n "$digest" ] && [ "$(sha256 SHA256SUMS | cut -c1-64)" != "$digest" ]; then die "SHA256SUMS digest mismatch in $name"; fi
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
{
"private": true,
"description": "The pinned wrangler CLI deploy-files.sh and deploy-update.sh run; npm ci --ignore-scripts installs exactly package-lock.json.",
"dependencies": {
"wrangler": "4.110.0"
}
}
+74 -12
View File
@@ -1,5 +1,17 @@
name: deploy-files
# Deploys the files Worker (services/files).
#
# - build runs repository code (typecheck and `wrangler deploy --dry-run`) with
# no environment and no secrets, and uploads only the bundled index.js with a
# SHA256SUMS whose digest it reports.
# - deploy runs in the dev|production environment and mints a short-lived
# Cloudflare token from the token issuer. It checks out only .github/release/,
# verifies the artifact against that digest, installs the wrangler CLI pinned
# in .github/release/wrangler, and runs only .github/release/deploy-files.sh.
# The Worker's name, route, R2 bucket and vars are the complete pinned
# wrangler.json in .github/release/targets/files/<stage>/; nothing in the
# artifact can name another destination.
on:
push:
branches:
@@ -15,7 +27,44 @@ permissions:
contents: read
jobs:
deploy:
files-build:
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
digest: ${{ steps.upload.outputs.digest }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: ./.github/actions/setup-bun
- name: Typecheck
working-directory: services/files
run: bun run typecheck:tsc
- name: Build
working-directory: services/files
run: |
artifact="$RUNNER_TEMP/files-artifact"
rm -rf "$artifact"
./node_modules/.bin/wrangler deploy --dry-run \
--env ${{ github.ref_name == 'production' && 'production' || 'dev' }} \
--outdir "$artifact"
# wrangler writes a README next to the bundle; the deploy only needs index.js.
rm -f "$artifact/README.md" "$artifact/index.js.map"
- id: upload
uses: ./.github/release/upload
with:
name: files-${{ github.ref_name }}
path: ${{ runner.temp }}/files-artifact
retention-days: 7
include-hidden-files: true
files-deploy:
needs: files-build
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: ${{ github.ref_name }}
@@ -23,13 +72,28 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Check out the deploy scripts
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
sparse-checkout: /.github/release/
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: ./.github/actions/setup-bun
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "24"
- name: Typecheck
working-directory: services/files
run: bun run typecheck:tsc
- name: Install the pinned wrangler CLI
working-directory: .github/release/wrangler
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Download
uses: ./.github/release/download
with:
pattern: files-${{ github.ref_name }}
require-digests: true
digests: files-${{ github.ref_name }}=${{ needs.files-build.outputs.digest }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
@@ -38,18 +102,16 @@ jobs:
role-session-name: opencode-${{ github.run_id }}
aws-region: us-east-1
# A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role
# above. It is a step output, so only the Deploy step gets it.
# A 15-minute token for this stage, minted by the token issuer (anomalyco/secrets) from the role above.
# It is a step output, so only the Deploy step gets it.
- name: Cloudflare token
id: cloudflare-token
run: bash .github/release/cloudflare-token.sh
env:
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
# wrangler.jsonc has no account id, and the token can't list accounts.
- name: Deploy
working-directory: services/files
run: bun run deploy --env ${{ github.ref_name == 'production' && 'production' || 'dev' }}
env:
CLOUDFLARE_ACCOUNT_ID: 15d29c8639fd3733b1b5486a2acfd968
STAGE: ${{ github.ref_name }}
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
run: bash .github/release/deploy-files.sh "$STAGE" "$RUNNER_TEMP/in/files-$STAGE"
+67 -14
View File
@@ -1,5 +1,17 @@
name: deploy-site
# Deploys the opencode.ai site (services/site) to dev.opencode.ai or opencode.ai.
#
# - build runs repository code (bun install, services/site/script/build.ts) with
# no environment and no secrets. The workflow's own read-only GITHUB_TOKEN is
# available only here, for script/github-snapshot.ts. It uploads the Build
# Output with a SHA256SUMS whose digest it reports.
# - deploy runs in the dev|production environment and mints a short-lived
# Cloudflare token from the token issuer. It checks out only .github/release/,
# verifies the artifact against that digest, installs the cf CLI pinned in
# .github/release/cf, and runs only .github/release/deploy-site.sh, which
# refuses an artifact whose config is not the pinned target in
# .github/release/targets/site/<stage>/.
on:
push:
branches:
@@ -15,7 +27,37 @@ permissions:
contents: read
jobs:
deploy:
site-build:
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
digest: ${{ steps.upload.outputs.digest }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: ./.github/actions/setup-bun
# The workflow's own token, at build time only: script/github-snapshot.ts records the repo numbers and
# releases the site falls back to. The Worker never gets a GitHub token.
- name: Build
working-directory: services/site
run: bun script/build.ts --mode ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ github.token }}
- id: upload
uses: ./.github/release/upload
with:
name: site-${{ github.ref_name }}
path: services/site/.cloudflare/output
retention-days: 7
include-hidden-files: true
site-deploy:
needs: site-build
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: ${{ github.ref_name }}
@@ -23,17 +65,28 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Check out the deploy scripts
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
sparse-checkout: /.github/release/
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: ./.github/actions/setup-bun
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "24"
# The workflow's own token, at build time only: script/github-snapshot.ts records the repo
# numbers and releases the site falls back to. The Worker never gets a GitHub token.
- name: Build
working-directory: services/site
run: bun script/build.ts --mode ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Install the pinned cf CLI
working-directory: .github/release/cf
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Download
uses: ./.github/release/download
with:
pattern: site-${{ github.ref_name }}
require-digests: true
digests: site-${{ github.ref_name }}=${{ needs.site-build.outputs.digest }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
@@ -42,8 +95,8 @@ jobs:
role-session-name: opencode-${{ github.run_id }}
aws-region: us-east-1
# A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role
# above. It is a step output, so only the Deploy step gets it.
# A 15-minute token for this stage, minted by the token issuer (anomalyco/secrets) from the role above.
# It is a step output, so only the Deploy step gets it.
- name: Cloudflare token
id: cloudflare-token
run: bash .github/release/cloudflare-token.sh
@@ -51,7 +104,7 @@ jobs:
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
- name: Deploy
working-directory: services/site
run: bunx cf deploy --prebuilt --mode ${{ github.ref_name }}
env:
STAGE: ${{ github.ref_name }}
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
run: bash .github/release/deploy-site.sh "$STAGE" "$RUNNER_TEMP/in/site-$STAGE"
+70 -12
View File
@@ -1,5 +1,16 @@
name: deploy-update
# Deploys the update Worker (services/update). Production only.
#
# - build runs repository code (typecheck and `wrangler deploy --dry-run`) with
# no environment and no secrets, and uploads only the bundled index.js with a
# SHA256SUMS whose digest it reports.
# - deploy runs in the production environment and mints a short-lived Cloudflare
# token from the token issuer. It checks out only .github/release/, verifies
# the artifact against that digest, installs the wrangler CLI pinned in
# .github/release/wrangler, and runs only .github/release/deploy-update.sh.
# The Worker's name, routes, custom domain, D1 database and Pipelines stream
# are the complete pinned wrangler.json in .github/release/targets/update/.
on:
push:
branches:
@@ -14,7 +25,42 @@ permissions:
contents: read
jobs:
deploy:
update-build:
if: github.repository == 'anomalyco/opencode' && github.ref_name == 'production'
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
digest: ${{ steps.upload.outputs.digest }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: ./.github/actions/setup-bun
- name: Typecheck
working-directory: services/update
run: bun run typecheck:tsc
- name: Build
working-directory: services/update
run: |
artifact="$RUNNER_TEMP/update-artifact"
rm -rf "$artifact"
./node_modules/.bin/wrangler deploy --dry-run --outdir "$artifact"
# wrangler writes a README next to the bundle; the deploy only needs index.js.
rm -f "$artifact/README.md" "$artifact/index.js.map"
- id: upload
uses: ./.github/release/upload
with:
name: update-production
path: ${{ runner.temp }}/update-artifact
retention-days: 7
include-hidden-files: true
update-deploy:
needs: update-build
if: github.repository == 'anomalyco/opencode' && github.ref_name == 'production'
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: production
@@ -22,13 +68,28 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Check out the deploy scripts
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
sparse-checkout: /.github/release/
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: ./.github/actions/setup-bun
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "24"
- name: Typecheck
working-directory: services/update
run: bun run typecheck:tsc
- name: Install the pinned wrangler CLI
working-directory: .github/release/wrangler
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Download
uses: ./.github/release/download
with:
pattern: update-production
require-digests: true
digests: update-production=${{ needs.update-build.outputs.digest }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
@@ -37,18 +98,15 @@ jobs:
role-session-name: opencode-${{ github.run_id }}
aws-region: us-east-1
# A 15-minute token for the production Workers only, minted by the token issuer (anomalyco/secrets) from the role
# above. It is a step output, so only the Deploy step gets it.
# A 15-minute token for production, minted by the token issuer (anomalyco/secrets) from the role above.
# It is a step output, so only the Deploy step gets it.
- name: Cloudflare token
id: cloudflare-token
run: bash .github/release/cloudflare-token.sh
env:
CLOUDFLARE_TOKEN_URL: ${{ vars.CLOUDFLARE_TOKEN_URL }}
# wrangler.jsonc has no account id, and the token can't list accounts.
- name: Deploy
working-directory: services/update
run: bun run deploy
env:
CLOUDFLARE_ACCOUNT_ID: 15d29c8639fd3733b1b5486a2acfd968
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
run: bash .github/release/deploy-update.sh production "$RUNNER_TEMP/in/update-production"
+112 -13
View File
@@ -1,5 +1,20 @@
name: deploy
# Deploys the legacy Worker and the data site (site, OG Worker, sync Workflow).
#
# Each service is split in two:
# - build runs repository code (bun install, cf build / bun script/build.ts) with
# no environment, no secrets and no OIDC token, and uploads the resolved Build
# Output with a SHA256SUMS whose digest it reports.
# - deploy runs in the dev|production environment and mints a short-lived
# Cloudflare token from the token issuer. It checks out only .github/release/,
# verifies the artifact against the digest the build job reported, installs
# the cf CLI pinned in .github/release/cf, and runs only
# .github/release/deploy-legacy.sh or deploy-data.sh. Those treat the artifact
# as data and refuse anything but the pinned targets in
# .github/release/targets/. That is what makes an account-wide token safe: the
# data sync Workflow PUT has no per-Worker permission, so only Dax-reviewed
# .github code ever holds a token that can write another Worker.
on:
push:
branches:
@@ -13,7 +28,33 @@ permissions:
contents: read
jobs:
legacy:
legacy-build:
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
digest: ${{ steps.upload.outputs.digest }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: ./.github/actions/setup-bun
- name: Build
working-directory: services/legacy
run: ./node_modules/.bin/cf build --mode ${{ github.ref_name }}
- id: upload
uses: ./.github/release/upload
with:
name: legacy-${{ github.ref_name }}
path: services/legacy/.cloudflare/output
retention-days: 7
include-hidden-files: true
legacy-deploy:
needs: legacy-build
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: ${{ github.ref_name }}
@@ -21,9 +62,28 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Check out the deploy scripts
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
sparse-checkout: /.github/release/
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: ./.github/actions/setup-bun
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "24"
- name: Install the pinned cf CLI
working-directory: .github/release/cf
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Download
uses: ./.github/release/download
with:
pattern: legacy-${{ github.ref_name }}
require-digests: true
digests: legacy-${{ github.ref_name }}=${{ needs.legacy-build.outputs.digest }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
@@ -32,8 +92,8 @@ jobs:
role-session-name: opencode-${{ github.run_id }}
aws-region: us-east-1
# A 15-minute token for this stage's Workers only, minted by the token issuer (anomalyco/secrets) from the role
# above. It is a step output, so only the Deploy step gets it.
# A 15-minute token for this stage, minted by the token issuer (anomalyco/secrets) from the role above.
# It is a step output, so only the Deploy step gets it.
- name: Cloudflare token
id: cloudflare-token
run: bash .github/release/cloudflare-token.sh
@@ -43,7 +103,6 @@ jobs:
# The GitHub App secrets are read here, so only this step ever has them. They reach cf through a file in the
# runner's temp directory, never argv, and the file is removed when the step ends.
- name: Deploy
working-directory: services/legacy
env:
STAGE: ${{ github.ref_name }}
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
@@ -57,10 +116,36 @@ jobs:
aws secretsmanager get-secret-value --secret-id "opencode/$STAGE/$name" --output json |
jq --arg name "$name" '{($name): .SecretString}'
done | jq -s add > "$secrets"
bun run deploy:$STAGE --secrets-file "$secrets"
bash .github/release/deploy-legacy.sh "$STAGE" "$RUNNER_TEMP/in/legacy-$STAGE" "$secrets"
data-build:
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
digest: ${{ steps.upload.outputs.digest }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: ./.github/actions/setup-bun
- name: Build
working-directory: services/data
run: bun script/build.ts --mode ${{ github.ref_name }}
- id: upload
uses: ./.github/release/upload
with:
name: data-${{ github.ref_name }}
path: services/data/.cloudflare/output
retention-days: 7
include-hidden-files: true
# The /data site, its OG image Worker and the sync Workflow (services/data).
data:
data-deploy:
needs: data-build
if: github.repository == 'anomalyco/opencode' && (github.ref_name == 'dev' || github.ref_name == 'production')
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: ${{ github.ref_name }}
@@ -68,14 +153,29 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: ./.github/actions/setup-bun
- name: Check out the deploy scripts
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ github.sha }}
sparse-checkout: /.github/release/
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: "24"
- name: Install the pinned cf CLI
working-directory: .github/release/cf
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Download
uses: ./.github/release/download
with:
pattern: data-${{ github.ref_name }}
require-digests: true
digests: data-${{ github.ref_name }}=${{ needs.data-build.outputs.digest }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
@@ -92,7 +192,6 @@ jobs:
# The Workers' secrets are read here, so only this step ever has them. They reach cf through files in the
# runner's temp directory, never argv, and are removed when the step ends.
- name: Deploy
working-directory: services/data
env:
STAGE: ${{ github.ref_name }}
CLOUDFLARE_API_TOKEN: ${{ steps.cloudflare-token.outputs.token }}
@@ -106,4 +205,4 @@ jobs:
aws secretsmanager get-secret-value --secret-id "opencode/$STAGE/$name" --output json |
jq --arg name "$name" '{($name): .SecretString}'
done | jq -s add > "$secrets"
bun run deploy:$STAGE --secrets-file "$secrets"
bash .github/release/deploy-data.sh "$STAGE" "$RUNNER_TEMP/in/data-$STAGE" "$secrets"