|
| 1 | +name: Deploy runner to celld |
| 2 | + |
| 3 | +# The production headless runner runs on a celld fleet (Render service headless-cells, bucket openwork-celld/fleet). |
| 4 | +# celld nodes don't build from the repo: a new runner exists only after `celld deploy` writes it to the bucket. This |
| 5 | +# workflow does that on every dev push that changes the runner or a package bundled into it, so the runner never |
| 6 | +# falls behind Workbot and den-api (which Render deploys from the same push). |
| 7 | +# |
| 8 | +# Each run first deploys the bundle to a throwaway bucket prefix, starts a local node on it and runs a real turn; |
| 9 | +# only then does it deploy to the fleet and wait until every node has adopted the new version. See |
| 10 | +# ee/apps/headless-runner/OWNER-CELLS.md. |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: |
| 15 | + - dev |
| 16 | + paths: |
| 17 | + - "ee/apps/headless-runner/**" |
| 18 | + - "ee/packages/headless-protocol/**" |
| 19 | + - "ee/packages/headless-computer/**" |
| 20 | + - "packages/sandbox-daytona/**" |
| 21 | + - "pnpm-lock.yaml" |
| 22 | + - ".github/workflows/celld-runner-deploy.yml" |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: celld-runner-deploy |
| 30 | + cancel-in-progress: false |
| 31 | + |
| 32 | +jobs: |
| 33 | + deploy: |
| 34 | + name: Deploy runner to celld |
| 35 | + if: github.repository == 'different-ai/openwork' |
| 36 | + runs-on: blacksmith-4vcpu-ubuntu-2404 |
| 37 | + environment: celld-production |
| 38 | + timeout-minutes: 30 |
| 39 | + |
| 40 | + env: |
| 41 | + CELLD_VERSION: v0.6.2 |
| 42 | + AWS_ACCESS_KEY_ID: ${{ secrets.CELLD_R2_ACCESS_KEY_ID }} |
| 43 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.CELLD_R2_SECRET_ACCESS_KEY }} |
| 44 | + AWS_REGION: auto |
| 45 | + S3_ENDPOINT: https://5abbcca46f2a1399566cab3a8f8bd2c6.r2.cloudflarestorage.com |
| 46 | + FLEET_BUCKET: s3://openwork-celld/fleet |
| 47 | + PREFLIGHT_BUCKET: s3://openwork-celld/ci/${{ github.run_id }}-${{ github.run_attempt }} |
| 48 | + RUNNER_VARS: ${{ secrets.CELLD_RUNNER_VARS }} |
| 49 | + RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} |
| 50 | + RENDER_OWNER_ID: tea-cspud29u0jms7384itk0 |
| 51 | + RENDER_SERVICE_ID: srv-db3upfjbc2fs73c1ii70 |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Verify secrets are configured |
| 55 | + run: | |
| 56 | + set -euo pipefail |
| 57 | + missing="" |
| 58 | + for name in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY RUNNER_VARS RENDER_API_KEY; do |
| 59 | + [ -z "${!name}" ] && missing="$missing $name" |
| 60 | + done |
| 61 | + if [ -n "$missing" ]; then |
| 62 | + echo "::error::Missing celld-production secrets:$missing (CELLD_R2_ACCESS_KEY_ID, CELLD_R2_SECRET_ACCESS_KEY, CELLD_RUNNER_VARS, RENDER_API_KEY)." |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Checkout |
| 67 | + uses: actions/checkout@v6 |
| 68 | + |
| 69 | + - name: Setup Node |
| 70 | + uses: actions/setup-node@v6 |
| 71 | + with: |
| 72 | + node-version: 24 |
| 73 | + |
| 74 | + - name: Setup pnpm |
| 75 | + uses: pnpm/action-setup@v4 |
| 76 | + with: |
| 77 | + version: 11.4.0 |
| 78 | + |
| 79 | + - name: Install and build the runner's packages |
| 80 | + run: | |
| 81 | + pnpm install --filter "@openwork-ee/headless-runner..." --frozen-lockfile |
| 82 | + pnpm --filter "@openwork-ee/headless-runner^..." --if-present run build |
| 83 | +
|
| 84 | + - name: Install celld |
| 85 | + run: | |
| 86 | + set -euo pipefail |
| 87 | + curl -fsSL https://celld.dev/install.sh | sh |
| 88 | + echo "$HOME/.local/bin" >> "$GITHUB_PATH" |
| 89 | + "$HOME/.local/bin/celld" --version |
| 90 | +
|
| 91 | + # CELLD_RUNNER_VARS is one JSON object of the runner's HEADLESS_* settings (secrets included). Mask every value: |
| 92 | + # GitHub masks the whole secret, not the values inside it. |
| 93 | + - name: Bundle the runner |
| 94 | + run: | |
| 95 | + set -euo pipefail |
| 96 | + umask 077 |
| 97 | + printf '%s' "$RUNNER_VARS" > "$RUNNER_TEMP/vars.json" |
| 98 | + jq -r '.[]' "$RUNNER_TEMP/vars.json" | while IFS= read -r value; do [ -n "$value" ] && echo "::add-mask::$value"; done |
| 99 | + cd ee/apps/headless-runner |
| 100 | + pnpm exec tsx scripts/celld-bundle.ts "$RUNNER_TEMP/celld" "$RUNNER_TEMP/vars.json" |
| 101 | + echo "CELLD_ESBUILD=$PWD/node_modules/.bin/esbuild" >> "$GITHUB_ENV" |
| 102 | +
|
| 103 | + - name: Preflight on a throwaway prefix |
| 104 | + run: | |
| 105 | + set -euo pipefail |
| 106 | + celld deploy "$RUNNER_TEMP/celld/wrangler.json" --bucket "$PREFLIGHT_BUCKET" |
| 107 | + CELLD_WATCH="$RUNNER_TEMP/watch" celld --bucket "$PREFLIGHT_BUCKET" --listen 127.0.0.1:18080 > "$RUNNER_TEMP/node.log" 2>&1 & |
| 108 | + for _ in $(seq 1 90); do curl -sf http://127.0.0.1:18080/health > /dev/null && break; sleep 1; done |
| 109 | + cd ee/apps/headless-runner |
| 110 | + SMOKE_BASE=http://127.0.0.1:18080 HEADLESS_API_TOKEN="$(jq -r .HEADLESS_API_TOKEN "$RUNNER_TEMP/vars.json")" pnpm exec tsx scripts/celld-smoke.ts |
| 111 | +
|
| 112 | + - name: Preflight node log |
| 113 | + if: failure() |
| 114 | + run: grep -v -E "log_ship_loop|node_lease_attempt|celld::memory" "$RUNNER_TEMP/node.log" | tail -80 || true |
| 115 | + |
| 116 | + - name: Deploy to the fleet |
| 117 | + id: fleet |
| 118 | + run: | |
| 119 | + set -euo pipefail |
| 120 | + live="$(aws s3 cp "$FLEET_BUCKET/deploy/current.json" - --endpoint-url "$S3_ENDPOINT" --region auto 2>/dev/null | jq -r '.version // empty' || true)" |
| 121 | + version="$(celld deploy "$RUNNER_TEMP/celld/wrangler.json" --bucket "$FLEET_BUCKET" --json | jq -r '.version')" |
| 122 | + if [ -z "$version" ] || [ "$version" = "null" ]; then echo "::error::celld deploy reported no version"; exit 1; fi |
| 123 | + # The version is a content hash: an unchanged bundle redeploys the live version, which nodes don't re-adopt. |
| 124 | + echo "unchanged=$([ "$version" = "$live" ] && echo true || echo false)" >> "$GITHUB_OUTPUT" |
| 125 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 126 | + echo "Deployed $version (was ${live:-none})" |
| 127 | +
|
| 128 | + # Nodes poll the pointer every 30 seconds. Every running instance must report adopting this version. |
| 129 | + - name: Wait for every node to adopt it |
| 130 | + if: steps.fleet.outputs.unchanged != 'true' |
| 131 | + env: |
| 132 | + VERSION: ${{ steps.fleet.outputs.version }} |
| 133 | + run: | |
| 134 | + set -euo pipefail |
| 135 | + started="$(date -u -d '-5 minutes' +%Y-%m-%dT%H:%M:%SZ)" |
| 136 | + instances="$(curl -sf -H "Authorization: Bearer $RENDER_API_KEY" "https://api.render.com/v1/services/$RENDER_SERVICE_ID" | jq -r '.serviceDetails.numInstances')" |
| 137 | + for _ in $(seq 1 30); do |
| 138 | + adopted="$(curl -sf -G -H "Authorization: Bearer $RENDER_API_KEY" https://api.render.com/v1/logs \ |
| 139 | + --data-urlencode "ownerId=$RENDER_OWNER_ID" --data-urlencode "resource=$RENDER_SERVICE_ID" \ |
| 140 | + --data-urlencode "text=deployment_adopted" --data-urlencode "startTime=$started" --data-urlencode "limit=100" \ |
| 141 | + | jq --arg v "$VERSION" '[.logs[] | select(.message | contains("version=" + $v)) | (.labels[] | select(.name == "instance") | .value)] | unique | length')" |
| 142 | + echo "adopted on $adopted of $instances nodes" |
| 143 | + [ "$adopted" -ge "$instances" ] && exit 0 |
| 144 | + sleep 10 |
| 145 | + done |
| 146 | + echo "::error::Not every node adopted $VERSION within 5 minutes; check the headless-cells logs." |
| 147 | + exit 1 |
| 148 | +
|
| 149 | + - name: Clean up |
| 150 | + if: always() |
| 151 | + run: | |
| 152 | + rm -rf "$RUNNER_TEMP/celld" "$RUNNER_TEMP/vars.json" "$RUNNER_TEMP/watch" |
| 153 | + aws s3 rm --recursive "$PREFLIGHT_BUCKET/" --endpoint-url "$S3_ENDPOINT" --region auto --only-show-errors || true |
0 commit comments