feat(scripts): CLOUDFLARE_API_BASE_URL and CLOUDFLARE_CONTAINER_REGISTRY
Cloudflare's API and registry stay the defaults.
Jason Schwarzenberger authored 1 parent bbfcbd5commit b6dbbfd895730faf8a6b706d38c24cc4a3e3a378Browse files
7 files changed+13−10
Files (7)
modifiedscripts/bootstrap-admins.sh+1−1View file
| @@ -59,7 +59,7 @@ | ||
| 59 | 59 | if [[ -z "${CLOUDFLARE_API_TOKEN:-}" || -z "${CLOUDFLARE_ACCOUNT_ID:-}" ]]; then |
| 60 | 60 | none "it isn't in the environment or wrangler.jsonc, and without CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID the deployed Worker's list can't be read" |
| 61 | 61 | fi |
| 62 | -SETTINGS="$(curl -sS --retry 4 --retry-all-errors --retry-delay 3 "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/$WORKER/settings" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" || true)" | |
| 62 | +SETTINGS="$(curl -sS --retry 4 --retry-all-errors --retry-delay 3 "${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}/accounts/$CLOUDFLARE_ACCOUNT_ID/workers/scripts/$WORKER/settings" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" || true)" | |
| 63 | 63 | if jq -e '.success == true' >/dev/null 2>&1 <<<"$SETTINGS"; then |
| 64 | 64 | LIVE="$(jq -r '[.result.bindings[]? | select(.type == "plain_text" and .name == "BOOTSTRAP_ADMINS") | .text][0] // empty' <<<"$SETTINGS")" |
| 65 | 65 | LIVE="$(trimmed "$LIVE")" |
modifiedscripts/bootstrap.sh+3−2View file
| @@ -25,7 +25,8 @@ | ||
| 25 | 25 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 26 | 26 | APP="$ROOT/apps/diffinery" |
| 27 | 27 | WRANGLER=(pnpm --dir "$APP" exec wrangler) |
| 28 | -API="https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID" | |
| 28 | +CF_API="${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}" | |
| 29 | +API="$CF_API/accounts/$CLOUDFLARE_ACCOUNT_ID" | |
| 29 | 30 | |
| 30 | 31 | cf() { # cf METHOD PATH [JSON] |
| 31 | 32 | local method="$1" path="$2" body="${3:-}" |
| @@ -127,7 +128,7 @@ | ||
| 127 | 128 | if [[ -z "$qid" ]]; then warn "Could not find the diffinery-mail-events queue, so it isn't subscribed to Email Sending's bounce and complaint events."; return; fi |
| 128 | 129 | # The zone that holds the sending domain (the domain itself or a parent), as scripts/email-sending.sh finds it. |
| 129 | 130 | while [[ "$name" == *.* ]]; do |
| 130 | - zone="$(curl -sS "https://api.cloudflare.com/client/v4/zones?name=$name" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" | jq -r '.result[0].id // empty' || true)" | |
| 131 | + zone="$(curl -sS "${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}/zones?name=$name" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" | jq -r '.result[0].id // empty' || true)" | |
| 131 | 132 | [[ -n "$zone" ]] && break |
| 132 | 133 | name="${name#*.}" |
| 133 | 134 | done |
modifiedscripts/email-sending.sh+1−1View file
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | |
| 13 | 13 | : "${CLOUDFLARE_API_TOKEN:?set CLOUDFLARE_API_TOKEN}" |
| 14 | 14 | DOMAIN="${MAIL_DOMAIN:-${DIFFINERY_DOMAIN:-diffinery.com}}" |
| 15 | -CF="https://api.cloudflare.com/client/v4" | |
| 15 | +CF="${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}" | |
| 16 | 16 | |
| 17 | 17 | cf() { curl -sS "$CF$1" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"; } |
| 18 | 18 | warn() { echo "::warning::$*" >&2; } |
modifiedscripts/runner-image.sh+1−1View file
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | } | sha256sum | cut -c1-24 |
| 21 | 21 | ) |
| 22 | 22 | : "${CLOUDFLARE_ACCOUNT_ID:?CLOUDFLARE_ACCOUNT_ID is required}" |
| 23 | -image="registry.cloudflare.com/$CLOUDFLARE_ACCOUNT_ID/$name:$tag" | |
| 23 | +image="${CLOUDFLARE_CONTAINER_REGISTRY:-registry.cloudflare.com}/$CLOUDFLARE_ACCOUNT_ID/$name:$tag" | |
| 24 | 24 | wrangler() { (cd apps/diffinery && pnpm exec wrangler "$@"); } |
| 25 | 25 | |
| 26 | 26 | if ! listed=$(wrangler containers images list --json --filter "(^|/)$name\$" 2>&1); then |
modifiedscripts/setup.sh+5−3View file
| @@ -19,6 +19,8 @@ | ||
| 19 | 19 | # GITHUB_APP_ID, GITHUB_APP_SLUG, GITHUB_APP_CLIENT_ID, GITHUB_APP_URL |
| 20 | 20 | # the GitHub App of GitHub runners (docs/self-hosting/configuration.md#github-runners) |
| 21 | 21 | # ROLLOUT_WAIT_MINUTES how long to wait for the container rollout (default 10) |
| 22 | +# CLOUDFLARE_API_BASE_URL another Cloudflare-compatible API (default Cloudflare's) | |
| 23 | +# CLOUDFLARE_CONTAINER_REGISTRY the registry runner images go to (default registry.cloudflare.com) | |
| 22 | 24 | # |
| 23 | 25 | # Every step is idempotent: it creates only what is missing and keeps your data and secrets, so run |
| 24 | 26 | # it again to update. Secrets are never printed. Needs Node.js 22+, pnpm, jq, curl, openssl and Docker. |
| @@ -26,7 +28,7 @@ | ||
| 26 | 28 | |
| 27 | 29 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 28 | 30 | APP="$ROOT/apps/diffinery" |
| 29 | -CF_API="https://api.cloudflare.com/client/v4" | |
| 31 | +CF_API="${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}" | |
| 30 | 32 | PLACEHOLDER_D1="00000000-0000-0000-0000-000000000000" |
| 31 | 33 | DRY_RUN=0 |
| 32 | 34 | ASK=1 |
| @@ -173,7 +175,7 @@ | ||
| 173 | 175 | |
| 174 | 176 | step "Rendering the deploy config (placeholder D1 id) and bundling the Worker" |
| 175 | 177 | # A placeholder runner image: the dry run builds no container image (that needs Docker and the registry). |
| 176 | - RUNNER_IMAGE="registry.cloudflare.com/${CLOUDFLARE_ACCOUNT_ID:-00000000000000000000000000000000}/diffinery-runner:dry-run" \ | |
| 178 | + RUNNER_IMAGE="${CLOUDFLARE_CONTAINER_REGISTRY:-registry.cloudflare.com}/${CLOUDFLARE_ACCOUNT_ID:-00000000000000000000000000000000}/diffinery-runner:dry-run" \ | |
| 177 | 179 | node "$ROOT/scripts/render-config.mjs" --d1 "$PLACEHOLDER_D1" ${ACCESS_TEAM_DOMAIN:+--team "$ACCESS_TEAM_DOMAIN"} \ |
| 178 | 180 | --public-url "https://$DIFFINERY_DOMAIN" ${DIFFINERY_ZONE:+--zone "$DIFFINERY_ZONE"} --mail-from "$MAIL_FROM" --admins "$ADMINS" |
| 179 | 181 | OUT="$(mktemp -d "${TMPDIR:-/tmp}/diffinery-dry-run.XXXXXX")" |
| @@ -205,7 +207,7 @@ | ||
| 205 | 207 | env -u GITHUB_ENV "$ROOT/scripts/runner-image.sh" | tee "$image_log" |
| 206 | 208 | RUNNER_IMAGE="$(tail -n 1 "$image_log")" |
| 207 | 209 | rm -f "$image_log" |
| 208 | -[[ "$RUNNER_IMAGE" == registry.cloudflare.com/* ]] || die "scripts/runner-image.sh didn't print the runner image" | |
| 210 | +[[ "$RUNNER_IMAGE" == ${CLOUDFLARE_CONTAINER_REGISTRY:-registry.cloudflare.com}/* ]] || die "scripts/runner-image.sh didn't print the runner image" | |
| 209 | 211 | export RUNNER_IMAGE |
| 210 | 212 | |
| 211 | 213 | step "Creating or updating Cloudflare resources (scripts/bootstrap.sh)" |
modifiedscripts/turnstile.sh+1−1View file
| @@ -43,7 +43,7 @@ | ||
| 43 | 43 | APP="$ROOT/apps/diffinery" |
| 44 | 44 | WRANGLER=(pnpm --dir "$APP" exec wrangler) |
| 45 | 45 | WORKER=diffinery |
| 46 | -API="https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID" | |
| 46 | +API="${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}/accounts/$CLOUDFLARE_ACCOUNT_ID" | |
| 47 | 47 | WIDGET_NAME="diffinery $DOMAIN" |
| 48 | 48 | PERMISSION="Account → Turnstile → Edit (\"Turnstile Sites Write\" in the API reference)" |
| 49 | 49 |
modifiedscripts/wait-container-rollout.sh+1−1View file
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | # ROLLOUT_WAIT_MINUTES (default 10) rather than failing the deploy. |
| 11 | 11 | set -euo pipefail |
| 12 | 12 | : "${CLOUDFLARE_API_TOKEN:?}" "${CLOUDFLARE_ACCOUNT_ID:?}" "${RUNNER_IMAGE:?RUNNER_IMAGE is required (scripts/runner-image.sh)}" |
| 13 | -api() { curl -fsS --retry 4 --retry-all-errors --retry-delay 3 "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/containers$1" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"; } | |
| 13 | +api() { curl -fsS --retry 4 --retry-all-errors --retry-delay 3 "${CLOUDFLARE_API_BASE_URL:-https://api.cloudflare.com/client/v4}/accounts/$CLOUDFLARE_ACCOUNT_ID/containers$1" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"; } | |
| 14 | 14 | deadline=$(( $(date +%s) + ${ROLLOUT_WAIT_MINUTES:-10} * 60 )) |
| 15 | 15 | last="" |
| 16 | 16 | while :; do |