Skip to content

g1t/.g1t/workflows/runner-base.yml

89 lines3,745 bytesCodeBlame
1# Rebuilds the base image of g1t's sandboxes (services/runner/base/Dockerfile:
2# the OS, toolchains and the Claude Code CLI), pushes it to Cloudflare's
3# registry, and opens a pull request that records it in
4# services/runner/base.json. Merging that pull request is what rolls it out:
5# the next deploy builds the runner's image on it, in seconds.
6#
7# Weekly, for security updates and new stable toolchains; when the base's
8# folder changes on main (a change that forgot to rebuild it); and by hand.
9#
10# It runs on a self-hosted runner with the `docker` label. g1t's own
11# machines have Docker now, but this build's own downloads (Docker's apt
12# repository over HTTPS) do not yet trust a guarded job's egress
13# certificate, so it stays where the network is open. Until a runner is
14# registered, run the same thing by hand on a machine with Docker:
15#
16# node scripts/deploy.mjs build-base
17#
18# and commit services/runner/base.json. docs/DEPLOYING.md explains both.
19name: Runner base image
20
21on:
22 schedule:
23 - cron: "17 6 * * 1"
24 push:
25 branches: [main]
26 paths:
27 - services/runner/base/**
28 workflow_dispatch:
29 inputs:
30 no_cache:
31 description: "Build every layer again, ignoring the previous base"
32 type: boolean
33 default: false
34
35concurrency:
36 group: runner-base
37 cancel-in-progress: false
38
39env:
40 CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
41 WRANGLER_SEND_METRICS: "false"
42
43jobs:
44 build:
45 name: Build and push the base
46 runs-on: [self-hosted, docker]
47 environment: production
48 timeout-minutes: 60
49 steps:
50 - uses: actions/checkout@v5
51 - name: Install Wrangler
52 run: npm ci --workspaces=false --no-audit --no-fund
53 - name: Build and push
54 env:
55 CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
56 CI: "true"
57 NO_CACHE: ${{ inputs.no_cache }}
58 run: |
59 args=()
60 if [ "$NO_CACHE" = "true" ]; then args+=(--no-cache); fi
61 node scripts/deploy.mjs build-base "${args[@]}"
62 # The runner's own image on the new base, so the deploy after the
63 # merge finds it in the registry instead of building it.
64 - name: Build and push the runner's image on it
65 env:
66 CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
67 CI: "true"
68 run: node scripts/deploy.mjs image
69 - name: Open a pull request with base.json
70 env:
71 G1T_TOKEN: ${{ github.token }}
72 REPO: ${{ github.repository }}
73 run: |
74 if git diff --quiet -- services/runner/base.json; then
75 echo "The base is unchanged."
76 exit 0
77 fi
78 branch="runner-base/$(date -u +%Y%m%d-%H%M)"
79 git config user.name "g1t"
80 git config user.email "g1t@users.noreply.g1t.sh"
81 git checkout -b "$branch"
82 git add services/runner/base.json
83 git commit -m "A new base image for g1t's sandboxes"
84 git push origin "$branch"
85 tag=$(node -e 'console.log(require("./services/runner/base.json").image.split(":").pop())')
86 body=$(node -e 'const b=require("./services/runner/base.json"); console.log("Built and pushed by the Runner base image workflow.\n\n| | |\n| --- | --- |\n" + Object.entries(b.versions).map(([k,v]) => `| ${k} | ${v} |`).join("\n") + `\n| size | ${(b.size_bytes/1e9).toFixed(2)} GB unpacked |`)')
87 curl -fsS -X POST "https://api.g1t.sh/repos/$REPO/pulls" \
88 -H "Authorization: Bearer $G1T_TOKEN" -H "Content-Type: application/json" \
89 -d "$(node -e 'console.log(JSON.stringify({ title: `Runner base image ${process.argv[1]}`, branch: process.argv[2], body: process.argv[3] }))' "$tag" "$branch" "$body")"