Diffinery

homeflare/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

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 @@
5959 if [[ -z "${CLOUDFLARE_API_TOKEN:-}" || -z "${CLOUDFLARE_ACCOUNT_ID:-}" ]]; then
6060 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"
6161 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)"
6363 if jq -e '.success == true' >/dev/null 2>&1 <<<"$SETTINGS"; then
6464 LIVE="$(jq -r '[.result.bindings[]? | select(.type == "plain_text" and .name == "BOOTSTRAP_ADMINS") | .text][0] // empty' <<<"$SETTINGS")"
6565 LIVE="$(trimmed "$LIVE")"
modifiedscripts/bootstrap.sh+3−2View file
@@ -25,7 +25,8 @@
2525 ROOT="$(cd "$(dirname "$0")/.." && pwd)"
2626 APP="$ROOT/apps/diffinery"
2727 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"
2930
3031 cf() { # cf METHOD PATH [JSON]
3132 local method="$1" path="$2" body="${3:-}"
@@ -127,7 +128,7 @@
127128 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
128129 # The zone that holds the sending domain (the domain itself or a parent), as scripts/email-sending.sh finds it.
129130 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)"
131132 [[ -n "$zone" ]] && break
132133 name="${name#*.}"
133134 done
modifiedscripts/email-sending.sh+1−1View file
@@ -12,7 +12,7 @@
1212
1313 : "${CLOUDFLARE_API_TOKEN:?set CLOUDFLARE_API_TOKEN}"
1414 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}"
1616
1717 cf() { curl -sS "$CF$1" -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"; }
1818 warn() { echo "::warning::$*" >&2; }
modifiedscripts/runner-image.sh+1−1View file
@@ -20,7 +20,7 @@
2020 } | sha256sum | cut -c1-24
2121 )
2222 : "${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"
2424 wrangler() { (cd apps/diffinery && pnpm exec wrangler "$@"); }
2525
2626 if ! listed=$(wrangler containers images list --json --filter "(^|/)$name\$" 2>&1); then
modifiedscripts/setup.sh+5−3View file
@@ -19,6 +19,8 @@
1919 # GITHUB_APP_ID, GITHUB_APP_SLUG, GITHUB_APP_CLIENT_ID, GITHUB_APP_URL
2020 # the GitHub App of GitHub runners (docs/self-hosting/configuration.md#github-runners)
2121 # 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)
2224 #
2325 # Every step is idempotent: it creates only what is missing and keeps your data and secrets, so run
2426 # it again to update. Secrets are never printed. Needs Node.js 22+, pnpm, jq, curl, openssl and Docker.
@@ -26,7 +28,7 @@
2628
2729 ROOT="$(cd "$(dirname "$0")/.." && pwd)"
2830 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}"
3032 PLACEHOLDER_D1="00000000-0000-0000-0000-000000000000"
3133 DRY_RUN=0
3234 ASK=1
@@ -173,7 +175,7 @@
173175
174176 step "Rendering the deploy config (placeholder D1 id) and bundling the Worker"
175177 # 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" \
177179 node "$ROOT/scripts/render-config.mjs" --d1 "$PLACEHOLDER_D1" ${ACCESS_TEAM_DOMAIN:+--team "$ACCESS_TEAM_DOMAIN"} \
178180 --public-url "https://$DIFFINERY_DOMAIN" ${DIFFINERY_ZONE:+--zone "$DIFFINERY_ZONE"} --mail-from "$MAIL_FROM" --admins "$ADMINS"
179181 OUT="$(mktemp -d "${TMPDIR:-/tmp}/diffinery-dry-run.XXXXXX")"
@@ -205,7 +207,7 @@
205207 env -u GITHUB_ENV "$ROOT/scripts/runner-image.sh" | tee "$image_log"
206208 RUNNER_IMAGE="$(tail -n 1 "$image_log")"
207209 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"
209211 export RUNNER_IMAGE
210212
211213 step "Creating or updating Cloudflare resources (scripts/bootstrap.sh)"
modifiedscripts/turnstile.sh+1−1View file
@@ -43,7 +43,7 @@
4343 APP="$ROOT/apps/diffinery"
4444 WRANGLER=(pnpm --dir "$APP" exec wrangler)
4545 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"
4747 WIDGET_NAME="diffinery $DOMAIN"
4848 PERMISSION="Account → Turnstile → Edit (\"Turnstile Sites Write\" in the API reference)"
4949
modifiedscripts/wait-container-rollout.sh+1−1View file
@@ -10,7 +10,7 @@
1010 # ROLLOUT_WAIT_MINUTES (default 10) rather than failing the deploy.
1111 set -euo pipefail
1212 : "${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"; }
1414 deadline=$(( $(date +%s) + ${ROLLOUT_WAIT_MINUTES:-10} * 60 ))
1515 last=""
1616 while :; do