From fe538d9104797f040810c2581461b855bf60f965 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 24 Nov 2026 03:35:53 -0600 Subject: [PATCH] deploy: add external Workers agent-inbox, webhook-gateway, webhook-gateway-sink (#5767) Pins sourced from dezren39/hatch-personal at ae79c332a78a7ba39b6dacd0f30228384d58dfdc. Sink must deploy before gateway on a fresh account. --- lib/default.nix | 16 ++++ pkgs/deploy/default.nix | 9 +++ pkgs/deploy/services.nix | 68 +++++++++++++++++ pkgs/external-workers/agent-inbox-deploy.nix | 36 +++++++++ pkgs/external-workers/agent-inbox-deploy.sh | 67 +++++++++++++++++ .../webhook-gateway-deploy.nix | 36 +++++++++ .../webhook-gateway-deploy.sh | 73 +++++++++++++++++++ .../webhook-gateway-sink-deploy.nix | 37 ++++++++++ .../webhook-gateway-sink-deploy.sh | 71 ++++++++++++++++++ 9 files changed, 413 insertions(+) create mode 100644 pkgs/external-workers/agent-inbox-deploy.nix create mode 100755 pkgs/external-workers/agent-inbox-deploy.sh create mode 100644 pkgs/external-workers/webhook-gateway-deploy.nix create mode 100755 pkgs/external-workers/webhook-gateway-deploy.sh create mode 100644 pkgs/external-workers/webhook-gateway-sink-deploy.nix create mode 100755 pkgs/external-workers/webhook-gateway-sink-deploy.sh diff --git a/lib/default.nix b/lib/default.nix index bf0ecba8d3..8c607b1a3b 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -851,6 +851,13 @@ let cf = pkgs.callPackage ../pkgs/cf { }; wrangler = pkgs.callPackage ../pkgs/wrangler { }; }; + # Issue #5767, external-Worker slice: the hatch-personal Workers' + # deploy apps (pinned rev staged at deploy time). + agentInboxDeploy = pkgs.callPackage ../pkgs/external-workers/agent-inbox-deploy.nix { }; + webhookGatewayDeploy = pkgs.callPackage ../pkgs/external-workers/webhook-gateway-deploy.nix { }; + webhookGatewaySinkDeploy = + pkgs.callPackage ../pkgs/external-workers/webhook-gateway-sink-deploy.nix + { }; in { packages = { @@ -870,6 +877,9 @@ let queueTransportAlertDeploy messageBridge messageBridgeDeploy + agentInboxDeploy + webhookGatewayDeploy + webhookGatewaySinkDeploy ; mcpx-docs = mcpxDocs; fleet-docs = fleetDocs; @@ -958,6 +968,9 @@ let cf-container-hello-deploy = mkApp cfContainerHelloDeploy "Deploy the cf-container-hello Worker from its flake package (needs Bitwarden and sops access)"; queue-transport-alert-deploy = mkApp queueTransportAlertDeploy "Deploy the queue-transport-alert Worker (broker outage alert, code#6369) from its flake package via the cf versions flow (needs Bitwarden and sops access)"; message-bridge-deploy = mkApp messageBridgeDeploy "Deploy the message-bridge Worker (Claude custom connector that sends and receives messages, plus history page) through the cf versions flow (tagged version, then deployment) and set its access token; --code-only uploads code with Cloudflare env vars (CI), --deploy-version rolls back, --print-urls prints the connector URL (needs Bitwarden and sops access)"; + agent-inbox-deploy = mkApp agentInboxDeploy "Deploy the agent-inbox Worker from the pinned dezren39/hatch-personal source (needs hatch-personal read access plus Bitwarden and sops access)"; + webhook-gateway-deploy = mkApp webhookGatewayDeploy "Deploy the webhook-gateway Worker from the pinned dezren39/hatch-personal source — deploy the sink first on a fresh account (needs hatch-personal read access plus Bitwarden and sops access)"; + webhook-gateway-sink-deploy = mkApp webhookGatewaySinkDeploy "Deploy the webhook-gateway-sink Worker from the pinned dezren39/hatch-personal source (needs hatch-personal read access plus Bitwarden and sops access)"; mcpx = { type = "app"; program = "${mcpx}/bin/mcpx"; @@ -1699,6 +1712,9 @@ let grep -q "cf-container-hello" list.txt grep -q "queue-transport-alert" list.txt grep -q "message-bridge" list.txt + grep -q "agent-inbox" list.txt + grep -q "webhook-gateway" list.txt + grep -q "webhook-gateway-sink" list.txt grep -q "secrets-broker" list.txt grep -q "pm-aggregator" list.txt grep -q "pm-projector" list.txt diff --git a/pkgs/deploy/default.nix b/pkgs/deploy/default.nix index 93294c9920..0a724a1a68 100644 --- a/pkgs/deploy/default.nix +++ b/pkgs/deploy/default.nix @@ -67,6 +67,15 @@ let # Issue #12909: ready-for-agent, packaged from its pinned npm # tarballs — the last of the four #12768 services to register. readyForAgent = callPackage ../ready-for-agent/package.nix { }; + # Issue #5767, external-Worker slice: agent-inbox, webhook-gateway, + # and webhook-gateway-sink live in dezren39/hatch-personal (source + # verdict comment 6974159268), not this repo. Each deploy app + # carries the pinned hatch-personal rev and stages the worker dir + # at deploy time (sparse checkout — no full clone, no build, no + # deploy-time npm install; both workers are dependency-free). + agentInboxDeploy = callPackage ../external-workers/agent-inbox-deploy.nix { }; + webhookGatewayDeploy = callPackage ../external-workers/webhook-gateway-deploy.nix { }; + webhookGatewaySinkDeploy = callPackage ../external-workers/webhook-gateway-sink-deploy.nix { }; }; # The registry names each target's store path without depending on it # (code#12738): string context would make building the CLI realize every diff --git a/pkgs/deploy/services.nix b/pkgs/deploy/services.nix index ff9478b256..b0d10b8723 100644 --- a/pkgs/deploy/services.nix +++ b/pkgs/deploy/services.nix @@ -24,6 +24,9 @@ cfContainerHelloDeploy, queueTransportAlertDeploy, messageBridgeDeploy, + agentInboxDeploy, + webhookGatewayDeploy, + webhookGatewaySinkDeploy, pmAggregator, pmProjector, pmTunnel, @@ -323,6 +326,71 @@ class = "cloudflare"; }; + # Issue #5767, external-Worker slice: agent-inbox, webhook-gateway, + # and webhook-gateway-sink live in dezren39/hatch-personal (source + # verdict comment 6974159268), not this repo. Each deploy app stages + # its worker dir from the pinned hatch-personal rev at deploy time + # (sparse checkout) and runs wrangler deploy there; both workers are + # dependency-free, so there is no build and no deploy-time npm + # install. Credentials are gathered impurely at deploy time, so the + # definitions name no secrets (the phase-1 shape). The pinned rev is + # repeated in `environment` so `deploy list` shows the source pin + # next to the target. Deploy the sink before the gateway on a fresh + # account (the gateway binds to the SINK service). + agent-inbox = { + package = agentInboxDeploy; + entryPoint = "bin/agent-inbox-deploy"; + args = [ ]; + environment = { + HATCH_PERSONAL_REPO = "dezren39/hatch-personal"; + HATCH_PERSONAL_REV = "ae79c332a78a7ba39b6dacd0f30228384d58dfdc"; + HATCH_WORKER_PATH = "workspace/agent-inbox/worker"; + }; + secrets = [ ]; # resolved by the deploy app itself at deploy time + user = "user"; + ports = [ ]; + restart = "no"; + healthCheck = null; + targets = [ "cloudflare" ]; + class = "cloudflare"; + }; + + webhook-gateway = { + package = webhookGatewayDeploy; + entryPoint = "bin/webhook-gateway-deploy"; + args = [ ]; + environment = { + HATCH_PERSONAL_REPO = "dezren39/hatch-personal"; + HATCH_PERSONAL_REV = "ae79c332a78a7ba39b6dacd0f30228384d58dfdc"; + HATCH_WORKER_PATH = "workspace/webhook-gateway"; + }; + secrets = [ ]; # resolved by the deploy app itself at deploy time + user = "user"; + ports = [ ]; + restart = "no"; + healthCheck = null; + targets = [ "cloudflare" ]; + class = "cloudflare"; + }; + + webhook-gateway-sink = { + package = webhookGatewaySinkDeploy; + entryPoint = "bin/webhook-gateway-sink-deploy"; + args = [ ]; + environment = { + HATCH_PERSONAL_REPO = "dezren39/hatch-personal"; + HATCH_PERSONAL_REV = "ae79c332a78a7ba39b6dacd0f30228384d58dfdc"; + HATCH_WORKER_PATH = "workspace/webhook-gateway/sink"; + }; + secrets = [ ]; # resolved by the deploy app itself at deploy time + user = "user"; + ports = [ ]; + restart = "no"; + healthCheck = null; + targets = [ "cloudflare" ]; + class = "cloudflare"; + }; + # Route proxy - issue #5768, migration M1 of the deployment # architecture (design doc/2026-11-04_deployment-architecture-services-layer.md, §7): the # hand-written opencode-route-proxy.service unit is already gone diff --git a/pkgs/external-workers/agent-inbox-deploy.nix b/pkgs/external-workers/agent-inbox-deploy.nix new file mode 100644 index 0000000000..0be2fbee92 --- /dev/null +++ b/pkgs/external-workers/agent-inbox-deploy.nix @@ -0,0 +1,36 @@ +# Deploy app for the agent-inbox Worker — issue #5767, external-Worker +# registration slice. The Worker's source lives in dezren39/hatch-personal +# (not this repo), so this app carries the pinned source coordinates and +# stages them at deploy time (sparse checkout of the worker dir at the +# pinned rev — trees only, no full clone). The worker is +# dependency-free, so there is no build and no deploy-time npm install. +# Cloudflare credentials are gathered impurely at deploy time (sops +# account id, wrangler token), so the registry definition names no +# secrets of its own — the phase-1 shape. +{ + writeShellApplication, + bws, + git, + jq, + nodejs, + sops, + wrangler, +}: +writeShellApplication { + name = "agent-inbox-deploy"; + runtimeInputs = [ + bws + git + jq + nodejs + sops + wrangler + ]; + text = '' + export HATCH_PERSONAL_REPO="dezren39/hatch-personal" + export HATCH_PERSONAL_REV="ae79c332a78a7ba39b6dacd0f30228384d58dfdc" + export HATCH_WORKER_PATH="workspace/agent-inbox/worker" + repo_root=$(git rev-parse --show-toplevel) + exec bash "$repo_root/pkgs/external-workers/agent-inbox-deploy.sh" "$@" + ''; +} diff --git a/pkgs/external-workers/agent-inbox-deploy.sh b/pkgs/external-workers/agent-inbox-deploy.sh new file mode 100755 index 0000000000..daa867fece --- /dev/null +++ b/pkgs/external-workers/agent-inbox-deploy.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# Deploys the agent-inbox Worker whose source lives in +# dezren39/hatch-personal (issue #5767, external-Worker registration +# slice). The worker is dependency-free (no package.json — wrangler +# uploads src/ + wrangler.toml directly), so the deploy needs no build +# and no deploy-time npm install: it stages the pinned source tree and +# runs `wrangler deploy`. +# +# Usage: +# agent-inbox-deploy.sh [--dry-run] [--rev ] +# +# --dry-run stages the source and runs `wrangler deploy --dry-run` +# (validates wrangler.toml, uploads nothing, needs no credentials). +# A full deploy needs CLOUDFLARE_ACCOUNT_ID (decrypted from sops here, +# like the other cloudflare deploy apps) and a Cloudflare token +# wrangler can use (CLOUDFLARE_API_TOKEN env or wrangler login). +# Worker secrets (TURSO_TOKEN, ADMIN_TOKEN) are managed out of band +# with `wrangler secret put` and are never carried here. +# +# Source overrides (default: the pinned rev in the deploy.nix that +# wraps this script): +# HATCH_PERSONAL_REPO owner/repo (default dezren39/hatch-personal) +# HATCH_PERSONAL_REV full commit SHA to deploy +# HATCH_WORKER_PATH worker dir inside that repo +set -euo pipefail + +REPO="${HATCH_PERSONAL_REPO:?HATCH_PERSONAL_REPO must be set by the deploy app}" +PINNED_REV="${HATCH_PERSONAL_REV:?HATCH_PERSONAL_REV must be set by the deploy app}" +SUBPATH="${HATCH_WORKER_PATH:?HATCH_WORKER_PATH must be set by the deploy app}" +WORKER="agent-inbox" + +DRY_RUN=0 +REV="$PINNED_REV" +while [ $# -gt 0 ]; do + case "$1" in + --dry-run) DRY_RUN=1; shift ;; + --rev) + REV="${2:?--rev needs a value}"; shift 2 ;; + --rev=*) REV="${1#--rev=}"; shift ;; + -h|--help) + echo "Usage: $0 [--dry-run] [--rev ]"; exit 0 ;; + *) echo "error: unknown argument $1 (usage: $0 [--dry-run] [--rev ])" >&2; exit 2 ;; + esac +done + +if [ "$REV" != "$PINNED_REV" ]; then + echo "warning: deploying $WORKER at $REV, not the pinned $PINNED_REV" >&2 +fi + +STAGE="$(mktemp -d)" +trap 'rm -rf "$STAGE"' EXIT +echo "staging $REPO $SUBPATH at $REV ..." >&2 +git clone --quiet --filter=blob:none --no-checkout "https://github.com/${REPO}.git" "$STAGE/checkout" +git -C "$STAGE/checkout" sparse-checkout set "$SUBPATH" +git -C "$STAGE/checkout" checkout --quiet "$REV" +WORKDIR="$STAGE/checkout/$SUBPATH" +[ -f "$WORKDIR/wrangler.toml" ] || { echo "error: $SUBPATH has no wrangler.toml at $REV" >&2; exit 1; } + +if [ "$DRY_RUN" = 1 ]; then + ( cd "$WORKDIR" && wrangler deploy --dry-run ) + exit 0 +fi + +repo_root="$(git rev-parse --show-toplevel)" +CLOUDFLARE_ACCOUNT_ID="$(sops decrypt --extract '["cloudflare_account_id"]' "${repo_root}/secrets/sops/common/cloudflare.yaml")" +export CLOUDFLARE_ACCOUNT_ID +( cd "$WORKDIR" && wrangler deploy ) diff --git a/pkgs/external-workers/webhook-gateway-deploy.nix b/pkgs/external-workers/webhook-gateway-deploy.nix new file mode 100644 index 0000000000..fe52e81572 --- /dev/null +++ b/pkgs/external-workers/webhook-gateway-deploy.nix @@ -0,0 +1,36 @@ +# Deploy app for the webhook-gateway Worker — issue #5767, +# external-Worker registration slice. The Worker's source lives in +# dezren39/hatch-personal (not this repo), so this app carries the +# pinned source coordinates and stages them at deploy time (sparse +# checkout of the worker dir at the pinned rev — trees only, no full +# clone). The worker is dependency-free, so there is no build and no +# deploy-time npm install. Cloudflare credentials are gathered +# impurely at deploy time (sops account id, wrangler token), so the +# registry definition names no secrets of its own — the phase-1 shape. +{ + writeShellApplication, + bws, + git, + jq, + nodejs, + sops, + wrangler, +}: +writeShellApplication { + name = "webhook-gateway-deploy"; + runtimeInputs = [ + bws + git + jq + nodejs + sops + wrangler + ]; + text = '' + export HATCH_PERSONAL_REPO="dezren39/hatch-personal" + export HATCH_PERSONAL_REV="ae79c332a78a7ba39b6dacd0f30228384d58dfdc" + export HATCH_WORKER_PATH="workspace/webhook-gateway" + repo_root=$(git rev-parse --show-toplevel) + exec bash "$repo_root/pkgs/external-workers/webhook-gateway-deploy.sh" "$@" + ''; +} diff --git a/pkgs/external-workers/webhook-gateway-deploy.sh b/pkgs/external-workers/webhook-gateway-deploy.sh new file mode 100755 index 0000000000..b3e169ed2f --- /dev/null +++ b/pkgs/external-workers/webhook-gateway-deploy.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# Deploys the webhook-gateway Worker whose source lives in +# dezren39/hatch-personal (issue #5767, external-Worker registration +# slice). The worker is dependency-free (no package.json — wrangler +# uploads src/ + wrangler.toml directly), so the deploy needs no build +# and no deploy-time npm install: it stages the pinned source tree and +# runs `wrangler deploy`. +# +# Ordering note: the gateway binds to two internal services declared in +# its wrangler.toml — SINK (webhook-gateway-sink) and LEDGER +# (ledger-svc, same repo). Deploy the sink (and ledger-svc) before the +# gateway on a fresh account, or the gateway deploy fails binding +# resolution. +# +# Usage: +# webhook-gateway-deploy.sh [--dry-run] [--rev ] +# +# --dry-run stages the source and runs `wrangler deploy --dry-run` +# (validates wrangler.toml, uploads nothing, needs no credentials). +# A full deploy needs CLOUDFLARE_ACCOUNT_ID (decrypted from sops here, +# like the other cloudflare deploy apps) and a Cloudflare token +# wrangler can use (CLOUDFLARE_API_TOKEN env or wrangler login). +# Gateway bindings (D1 webhook-gateway, R2 payloads, delivery queue, +# cron) are provisioned out of band and never carried here. +# +# Source overrides (default: the pinned rev in the deploy.nix that +# wraps this script): +# HATCH_PERSONAL_REPO owner/repo (default dezren39/hatch-personal) +# HATCH_PERSONAL_REV full commit SHA to deploy +# HATCH_WORKER_PATH worker dir inside that repo +set -euo pipefail + +REPO="${HATCH_PERSONAL_REPO:?HATCH_PERSONAL_REPO must be set by the deploy app}" +PINNED_REV="${HATCH_PERSONAL_REV:?HATCH_PERSONAL_REV must be set by the deploy app}" +SUBPATH="${HATCH_WORKER_PATH:?HATCH_WORKER_PATH must be set by the deploy app}" +WORKER="webhook-gateway" + +DRY_RUN=0 +REV="$PINNED_REV" +while [ $# -gt 0 ]; do + case "$1" in + --dry-run) DRY_RUN=1; shift ;; + --rev) + REV="${2:?--rev needs a value}"; shift 2 ;; + --rev=*) REV="${1#--rev=}"; shift ;; + -h|--help) + echo "Usage: $0 [--dry-run] [--rev ]"; exit 0 ;; + *) echo "error: unknown argument $1 (usage: $0 [--dry-run] [--rev ])" >&2; exit 2 ;; + esac +done + +if [ "$REV" != "$PINNED_REV" ]; then + echo "warning: deploying $WORKER at $REV, not the pinned $PINNED_REV" >&2 +fi + +STAGE="$(mktemp -d)" +trap 'rm -rf "$STAGE"' EXIT +echo "staging $REPO $SUBPATH at $REV ..." >&2 +git clone --quiet --filter=blob:none --no-checkout "https://github.com/${REPO}.git" "$STAGE/checkout" +git -C "$STAGE/checkout" sparse-checkout set "$SUBPATH" +git -C "$STAGE/checkout" checkout --quiet "$REV" +WORKDIR="$STAGE/checkout/$SUBPATH" +[ -f "$WORKDIR/wrangler.toml" ] || { echo "error: $SUBPATH has no wrangler.toml at $REV" >&2; exit 1; } + +if [ "$DRY_RUN" = 1 ]; then + ( cd "$WORKDIR" && wrangler deploy --dry-run ) + exit 0 +fi + +repo_root="$(git rev-parse --show-toplevel)" +CLOUDFLARE_ACCOUNT_ID="$(sops decrypt --extract '["cloudflare_account_id"]' "${repo_root}/secrets/sops/common/cloudflare.yaml")" +export CLOUDFLARE_ACCOUNT_ID +( cd "$WORKDIR" && wrangler deploy ) diff --git a/pkgs/external-workers/webhook-gateway-sink-deploy.nix b/pkgs/external-workers/webhook-gateway-sink-deploy.nix new file mode 100644 index 0000000000..dd1125e30c --- /dev/null +++ b/pkgs/external-workers/webhook-gateway-sink-deploy.nix @@ -0,0 +1,37 @@ +# Deploy app for the webhook-gateway-sink Worker — issue #5767, +# external-Worker registration slice. The Worker's source lives in +# dezren39/hatch-personal under workspace/webhook-gateway/sink (not +# this repo), so this app carries the pinned source coordinates and +# stages them at deploy time (sparse checkout of the worker dir at the +# pinned rev — trees only, no full clone). The worker is +# dependency-free, so there is no build and no deploy-time npm install. +# Cloudflare credentials are gathered impurely at deploy time (sops +# account id, wrangler token), so the registry definition names no +# secrets of its own — the phase-1 shape. +{ + writeShellApplication, + bws, + git, + jq, + nodejs, + sops, + wrangler, +}: +writeShellApplication { + name = "webhook-gateway-sink-deploy"; + runtimeInputs = [ + bws + git + jq + nodejs + sops + wrangler + ]; + text = '' + export HATCH_PERSONAL_REPO="dezren39/hatch-personal" + export HATCH_PERSONAL_REV="ae79c332a78a7ba39b6dacd0f30228384d58dfdc" + export HATCH_WORKER_PATH="workspace/webhook-gateway/sink" + repo_root=$(git rev-parse --show-toplevel) + exec bash "$repo_root/pkgs/external-workers/webhook-gateway-sink-deploy.sh" "$@" + ''; +} diff --git a/pkgs/external-workers/webhook-gateway-sink-deploy.sh b/pkgs/external-workers/webhook-gateway-sink-deploy.sh new file mode 100755 index 0000000000..aa00894b1a --- /dev/null +++ b/pkgs/external-workers/webhook-gateway-sink-deploy.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +# Deploys the webhook-gateway-sink Worker whose source lives in +# dezren39/hatch-personal (issue #5767, external-Worker registration +# slice). The worker is dependency-free (no package.json — wrangler +# uploads src/ + wrangler.toml directly), so the deploy needs no build +# and no deploy-time npm install: it stages the pinned source tree and +# runs `wrangler deploy`. +# +# Ordering note: this sink is the stand-in target the webhook-gateway +# reaches through its SINK service binding — deploy the sink before the +# gateway on a fresh account. +# +# Usage: +# webhook-gateway-sink-deploy.sh [--dry-run] [--rev ] +# +# --dry-run stages the source and runs `wrangler deploy --dry-run` +# (validates wrangler.toml, uploads nothing, needs no credentials). +# A full deploy needs CLOUDFLARE_ACCOUNT_ID (decrypted from sops here, +# like the other cloudflare deploy apps) and a Cloudflare token +# wrangler can use (CLOUDFLARE_API_TOKEN env or wrangler login). +# The sink's KV namespace (SINK_LOG) is provisioned out of band and +# never carried here. +# +# Source overrides (default: the pinned rev in the deploy.nix that +# wraps this script): +# HATCH_PERSONAL_REPO owner/repo (default dezren39/hatch-personal) +# HATCH_PERSONAL_REV full commit SHA to deploy +# HATCH_WORKER_PATH worker dir inside that repo +set -euo pipefail + +REPO="${HATCH_PERSONAL_REPO:?HATCH_PERSONAL_REPO must be set by the deploy app}" +PINNED_REV="${HATCH_PERSONAL_REV:?HATCH_PERSONAL_REV must be set by the deploy app}" +SUBPATH="${HATCH_WORKER_PATH:?HATCH_WORKER_PATH must be set by the deploy app}" +WORKER="webhook-gateway-sink" + +DRY_RUN=0 +REV="$PINNED_REV" +while [ $# -gt 0 ]; do + case "$1" in + --dry-run) DRY_RUN=1; shift ;; + --rev) + REV="${2:?--rev needs a value}"; shift 2 ;; + --rev=*) REV="${1#--rev=}"; shift ;; + -h|--help) + echo "Usage: $0 [--dry-run] [--rev ]"; exit 0 ;; + *) echo "error: unknown argument $1 (usage: $0 [--dry-run] [--rev ])" >&2; exit 2 ;; + esac +done + +if [ "$REV" != "$PINNED_REV" ]; then + echo "warning: deploying $WORKER at $REV, not the pinned $PINNED_REV" >&2 +fi + +STAGE="$(mktemp -d)" +trap 'rm -rf "$STAGE"' EXIT +echo "staging $REPO $SUBPATH at $REV ..." >&2 +git clone --quiet --filter=blob:none --no-checkout "https://github.com/${REPO}.git" "$STAGE/checkout" +git -C "$STAGE/checkout" sparse-checkout set "$SUBPATH" +git -C "$STAGE/checkout" checkout --quiet "$REV" +WORKDIR="$STAGE/checkout/$SUBPATH" +[ -f "$WORKDIR/wrangler.toml" ] || { echo "error: $SUBPATH has no wrangler.toml at $REV" >&2; exit 1; } + +if [ "$DRY_RUN" = 1 ]; then + ( cd "$WORKDIR" && wrangler deploy --dry-run ) + exit 0 +fi + +repo_root="$(git rev-parse --show-toplevel)" +CLOUDFLARE_ACCOUNT_ID="$(sops decrypt --extract '["cloudflare_account_id"]' "${repo_root}/secrets/sops/common/cloudflare.yaml")" +export CLOUDFLARE_ACCOUNT_ID +( cd "$WORKDIR" && wrangler deploy )