Skip to content
58 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

The runner base keeps its old comment, so the pushed base image still matches its folder1#!/usr/bin/env bash
2# Sets up what Deployments needs on a Cloudflare account, once. Safe to run
3# again: each step skips what exists. Then deploy with scripts/deploy.sh.
4#
5# Needs the Workers for Platforms add-on on the account, and a zone for
6# apps (g1t uses g1t.page) named in services/pages/wrangler.jsonc.
7#
8# Two steps need more than `wrangler login` can do: a wildcard DNS record
9# on the apps' zone, and an API token for the deployments service. Set
10# CLOUDFLARE_EMAIL and CLOUDFLARE_API_KEY (a Global API Key) and this
11# script makes both; otherwise it says what to make by hand.
12set -euo pipefail
13
14ROOT="$(cd "$(dirname "$0")/.." && pwd)"
15export CLOUDFLARE_API_TOKEN="${CLOUDFLARE_DEPLOY_TOKEN:-}"
16ZONE="${G1T_APPS_ZONE:-g1t.page}"
17NAMESPACE="g1t-deployments"
18TOKEN_FILE="$ROOT/.credentials/deployments-cloudflare-token.txt"
19w() { npx wrangler "$@"; }
20
21cd "$ROOT/services/deployments"
22
23echo "== D1 database"
24if grep -q TO_BE_CREATED wrangler.jsonc; then
25 id=$(w d1 create g1t-deployments </dev/null 2>&1 | grep -oE '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | head -1 || true)
26 [ -n "$id" ] || { echo "Could not create the database; is it there already? (npx wrangler d1 list)"; exit 1; }
27 sed -i "s/TO_BE_CREATED/$id/" wrangler.jsonc
28 echo "Created $id and wrote it into services/deployments/wrangler.jsonc. Commit that."
29else
30 echo "Already set."
31fi
32
33echo "== Dispatch namespace and event queue"
34w dispatch-namespace list 2>/dev/null | grep -q "$NAMESPACE" || w dispatch-namespace create "$NAMESPACE"
35w queues list 2>/dev/null | grep -q g1t-events-deployments || w queues create g1t-events-deployments
The docs folder is gone, and what it held lives where people read it: how a self-hosted g1t runs and how to deploy g1t to Cloudflare are pages on docs.g1t.sh under Run g1t yourself, and speed, rate limits and operating g1t.sh are sections of CONTRIBUTING.md; code that cited a file in docs/ now points to the page or section that covers it, or says what it means itself, and applied migrations and the runner images are left as they were.36# Where every consumer sends what it gave up on
37# (docs.g1t.sh/guides/deploy-to-cloudflare/#the-dead-letter-queue).
Merge branch 'worktree-agent-ad8a36dfcd4176015' into spend-guardrails38w queues list 2>/dev/null | grep -q g1t-events-dlq || w queues create g1t-events-dlq
The runner base keeps its old comment, so the pushed base image still matches its folder39
40echo "== DNS record and the service's token"
41if [ -n "${CLOUDFLARE_API_KEY:-}" ] && [ -n "${CLOUDFLARE_EMAIL:-}" ]; then
42 G1T_APPS_ZONE="$ZONE" TOKEN_FILE="$TOKEN_FILE" python "$ROOT/scripts/cloudflare-setup.py"
43else
44 cat <<EOF
45Set CLOUDFLARE_EMAIL and CLOUDFLARE_API_KEY to do this for you, or by hand:
46 1. On $ZONE, add a proxied DNS record: type AAAA, name *, content 100::
47 2. Create an API token with Workers Scripts: Edit and Account Analytics:
48 Read on the account, and save it as one line in
49 $TOKEN_FILE
50EOF
51fi
52
53if [ -f "$TOKEN_FILE" ]; then
54 echo "== Storing the token as the deployments service's secret"
55 w deploy
56 tr -d '\r\n' <"$TOKEN_FILE" | w secret put CLOUDFLARE_API_TOKEN
57fi
58echo "== Done. Now: scripts/deploy.sh"

This file's history is long; its oldest lines are credited to the oldest commit read.