Repository navigation
129 lines (120 loc) · 5.02 KB
/
Copy pathbox-image.yml
File metadata and controls
129 lines (120 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# The box image (runner/box/Dockerfile; docs/virtual-runners.md, "The box
# image"): what a virtual runner's machine boots to run one thread. Built for
# linux/amd64 (Fly's default), checked with runner/box/smoke.sh, then pushed
# to the private registry of the Fly app the boxes live in, as
# registry.fly.io/<app>. It's private because it holds Claude Code, which
# isn't ours to publish (Mike, 19 Nov): Fly pulls it for that app's
# machines with no credentials, and no one else can.
#
# - a push to main that changes what the image holds: `<commit>` and
# `latest`. New boxes take `latest` (the service's default image,
# convex/boxes.ts defaultBoxImage), so they run the runner from the
# main that Mike's backend is deployed from;
# - a release tag (release/YYYY-MM-DD, runner/src/upstream.ts):
# `<commit>` and `release-YYYY-MM-DD`, for a virtual runner pinned to a
# release;
# - by hand (workflow_dispatch): `<commit>`, and `latest` from main.
#
# The app is the repo variable FLY_BOX_APP (the deployment's FLY_APP), and
# the secret FLY_BOX_IMAGE_TOKEN a Fly token that reaches that app only
# (`fly tokens create deploy -a <app>`, or an org token narrowed with
# `fly tokens attenuate`). Without them (a fork that hasn't set up boxes)
# the image is still built and checked, just not pushed.
#
# Free, as runner.yml's must be (Mike, 9 Nov): a standard hosted runner, no
# schedule, a newer push cancelling the run before it, and only when the
# image's files changed (the paths below: what the Dockerfile copies, the
# image's own files, and this file). No action but checkout, pinned as
# workflow-pins.test.ts wants; plain docker for the rest.
name: Box image
on:
push:
branches: [main]
# Paths aren't checked for tags: every release tag builds.
tags: ['release/*']
paths:
- 'runner/src/**'
- 'runner/bin/**'
- 'runner/package.json'
- 'runner/package-lock.json'
- 'runner/.npmrc'
- 'runner/.dockerignore'
- 'runner/box/Dockerfile'
- 'runner/box/entrypoint.sh'
- 'runner/box/smoke.sh'
- '.github/workflows/box-image.yml'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: box-image-${{ github.ref }}
cancel-in-progress: true
jobs:
image:
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
persist-credentials: false
- name: Names and tags
id: names
env:
APP: ${{ vars.FLY_BOX_APP }}
HAS_TOKEN: ${{ secrets.FLY_BOX_IMAGE_TOKEN != '' }}
REF: ${{ github.ref }}
SHA: ${{ github.sha }}
run: |
if [ -n "$APP" ] && [ "$HAS_TOKEN" = true ]; then
image="registry.fly.io/$APP"; push=true
else
image="threadbear-box"; push=false
echo "::notice::FLY_BOX_APP or FLY_BOX_IMAGE_TOKEN isn't set, so the image is built and checked but not pushed."
fi
tags="$image:$SHA"
case "$REF" in
refs/heads/main) tags="$tags $image:latest" ;;
refs/tags/release/*) tags="$tags $image:release-${REF#refs/tags/release/}" ;;
esac
{
echo "image=$image"
echo "push=$push"
echo "tags=$tags"
echo "built_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
} >> "$GITHUB_OUTPUT"
echo "Tags: $tags"
- name: Sign in to the registry
if: steps.names.outputs.push == 'true'
env:
TOKEN: ${{ secrets.FLY_BOX_IMAGE_TOKEN }}
run: printf '%s' "$TOKEN" | docker login registry.fly.io -u x --password-stdin
- name: Build
# The last `latest` as a cache, when there is one: the Claude Code and
# packages layers only change when their versions do.
env:
IMAGE: ${{ steps.names.outputs.image }}
SHA: ${{ github.sha }}
BUILT_AT: ${{ steps.names.outputs.built_at }}
SOURCE: ${{ github.server_url }}/${{ github.repository }}
run: |
docker build --platform linux/amd64 -f runner/box/Dockerfile \
--cache-from "$IMAGE:latest" --build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg COMMIT="$SHA" --build-arg BUILT_AT="$BUILT_AT" \
--label org.opencontainers.image.source="$SOURCE" \
--label org.opencontainers.image.revision="$SHA" \
--label org.opencontainers.image.description="Threadbear virtual runner box: the runner in box mode and Claude Code" \
-t "$IMAGE:$SHA" runner
docker image ls "$IMAGE"
- name: Smoke test
run: runner/box/smoke.sh "${{ steps.names.outputs.image }}:${{ github.sha }}"
- name: Push
if: steps.names.outputs.push == 'true'
env:
IMAGE: ${{ steps.names.outputs.image }}
SHA: ${{ github.sha }}
TAGS: ${{ steps.names.outputs.tags }}
run: |
for tag in $TAGS; do
[ "$tag" = "$IMAGE:$SHA" ] || docker tag "$IMAGE:$SHA" "$tag"
docker push "$tag"
done