@@ -22,6 +22,7 @@ concurrency:
2222
2323env :
2424 AGENT_ENV_ENVIRONMENT : dev
25+ COMPUTER_IMAGE_MIRROR : ghcr.io/scaleapi/agentenv-ci-computers
2526 PIP_DISABLE_PIP_VERSION_CHECK : " 1"
2627
2728jobs :
@@ -169,8 +170,14 @@ jobs:
169170 shard : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
170171 runs-on : ubuntu-latest
171172 timeout-minutes : 40
173+ permissions :
174+ contents : read
175+ packages : write
172176 steps :
173177 - uses : actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
178+ # The tests run with packages: write; only the share step, on main, gets the token.
179+ with :
180+ persist-credentials : false
174181 - uses : actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
175182 with :
176183 python-version : " 3.12"
@@ -183,29 +190,22 @@ jobs:
183190 # starts afterwards.
184191 - name : Pull the base images from mirror.gcr.io
185192 run : python3 .github/scripts/mirror_base_images.py src tst
186- # A computer image or disk is tagged with a key of everything it is built from, and the composer reuses one the
187- # image store already holds for its key. That key includes the lock of the packages the image installs, which the
188- # composer resolves from Ubuntu's archive, PyPI and download URLs unless the store holds it. The registry keeps
189- # its storage on the runner, and the computer tests share their locks and files in the packages folder
190- # (tst/util/package_cache.py); both are restored from what main saved latest this week, so a run neither resolves
191- # nor builds again what hasn't changed. A shard that runs no computer tests misses.
192- - name : Week of the computer images' cache
193+ # The computer tests share the package locks a compose resolves, and the files they name, in the packages folder
194+ # (tst/util/package_cache.py). An image's key includes its lock, which the composer otherwise resolves from
195+ # Ubuntu's archive, PyPI and download URLs, so the folder is restored from what main saved latest this week.
196+ - name : Week of the packages' cache
193197 id : week
194198 run : echo "week=$(date -u +%G-W%V)" >> "$GITHUB_OUTPUT"
195- - name : Restore the computer images and packages
196- id : computers
199+ - name : Restore the packages
200+ id : packages
197201 uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
198202 with :
199- path : |
200- ${{ runner.temp }}/registry
201- ${{ runner.temp }}/packages
202- key : computers-${{ matrix.shard }}-${{ steps.week.outputs.week }}
203- restore-keys : computers-${{ matrix.shard }}-${{ steps.week.outputs.week }}-
203+ path : ${{ runner.temp }}/packages
204+ key : packages-${{ matrix.shard }}-${{ steps.week.outputs.week }}
205+ restore-keys : packages-${{ matrix.shard }}-${{ steps.week.outputs.week }}-
204206 - name : Start the local registry
205207 run : |
206- mkdir -p "$RUNNER_TEMP/registry"
207- docker run --detach --name registry --publish 5000:5000 --volume "$RUNNER_TEMP/registry:/var/lib/registry" \
208- mirror.gcr.io/library/registry:2
208+ docker run --detach --name registry --publish 5000:5000 mirror.gcr.io/library/registry:2
209209 timeout 30 sh -c 'until curl -sf http://localhost:5000/v2/ >/dev/null; do sleep 1; done'
210210 # x64 hosted runners have /dev/kvm; the disk form's tests boot under it, and skip without it, which fails below.
211211 - name : Let the local provider boot disks with KVM
@@ -215,49 +215,37 @@ jobs:
215215 env :
216216 AGENTENV_TEST_SHARD : ${{ matrix.shard }}/12
217217 AGENTENV_TEST_PACKAGES : ${{ runner.temp }}/packages
218+ AGENT_ENV_COMPUTER_IMAGE_MIRROR : ${{ env.COMPUTER_IMAGE_MIRROR }}
218219 run : |
219220 .venv/bin/python -m pytest -m int_test_slow -n 2 --dist loadfile -rA --timeout=1200 \
220221 --junitxml=junit-integration-slow.xml tst/integration --ignore=tst/integration/env/gateway/gateway_test.py
221- # Only the computer images this run used are kept, with the packages, and only main saves them, once its tests
222- # pass, so pull requests reuse main's without filling the repository's cache. An image is used when the registry's
223- # log has a request for it by its tag (prune_registry.py), so what a week's earlier runs built and this one no
224- # longer asks for is dropped. The garbage collection frees what only the dropped tags and repositories referenced;
225- # with --delete-untagged it would also delete the untagged platform manifests of an image index, and their layers.
226- # The entry is named by the image keys the registry holds and the locks the packages hold, so a run that built a
227- # new image or resolved a new lock saves a new one.
228- - name : Keep only the computer images this run used
229- id : kept
222+ # Only main saves the packages, once its tests pass, so pull requests reuse main's without filling the
223+ # repository's cache. The entry is named by the locks the folder holds, so a run that resolved a new lock saves a
224+ # new one.
225+ - name : Name the packages' cache entry
226+ id : lockkey
230227 if : always()
231228 run : |
232- repositories="$RUNNER_TEMP/registry/docker/registry/v2/repositories"
233- if [ ! -d "$repositories/agentenv-computers" ]; then echo "computers=false" >> "$GITHUB_OUTPUT"; exit 0; fi
234- docker logs registry > "$RUNNER_TEMP/registry.log" 2>&1
235- docker stop registry
236- sudo find "$repositories" -mindepth 1 -maxdepth 1 ! -name agentenv-computers -exec rm -rf {} +
237- sudo python3 .github/scripts/prune_registry.py prune "$RUNNER_TEMP/registry" agentenv-computers \
238- "$RUNNER_TEMP/registry.log"
239- docker run --rm --volume "$RUNNER_TEMP/registry:/var/lib/registry" mirror.gcr.io/library/registry:2 \
240- garbage-collect /etc/docker/registry/config.yml > /dev/null
241- sudo python3 .github/scripts/prune_registry.py links "$RUNNER_TEMP/registry" agentenv-computers
242- mkdir -p "$RUNNER_TEMP/packages"
243- du -sh "$RUNNER_TEMP/registry" "$RUNNER_TEMP/packages"
244- if [ -z "$(sudo ls "$repositories/agentenv-computers/_manifests/tags")" ]; then
245- echo "computers=false" >> "$GITHUB_OUTPUT"; exit 0
246- fi
247- key=$({ sudo ls "$repositories/agentenv-computers/_manifests/tags"
248- ls "$RUNNER_TEMP/packages/agentenv-packages/locks" 2>/dev/null; } | sort | sha256sum | cut -c1-16)
249- echo "key=computers-${{ matrix.shard }}-${{ steps.week.outputs.week }}-$key" >> "$GITHUB_OUTPUT"
250- echo "computers=true" >> "$GITHUB_OUTPUT"
251- - name : Save the computer images and packages
229+ locks="$RUNNER_TEMP/packages/agentenv-packages/locks"
230+ if [ -z "$(ls "$locks" 2>/dev/null)" ]; then echo "packages=false" >> "$GITHUB_OUTPUT"; exit 0; fi
231+ key=$(ls "$locks" | sort | sha256sum | cut -c1-16)
232+ echo "key=packages-${{ matrix.shard }}-${{ steps.week.outputs.week }}-$key" >> "$GITHUB_OUTPUT"
233+ echo "packages=true" >> "$GITHUB_OUTPUT"
234+ - name : Save the packages
252235 if : >-
253236 always() && github.event_name == 'push' && steps.tests.outcome == 'success'
254- && steps.kept .outputs.computers == 'true' && steps.kept .outputs.key != steps.computers .outputs.cache-matched-key
237+ && steps.lockkey .outputs.packages == 'true' && steps.lockkey .outputs.key != steps.packages .outputs.cache-matched-key
255238 uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
256239 with :
257- path : |
258- ${{ runner.temp }}/registry
259- ${{ runner.temp }}/packages
260- key : ${{ steps.kept.outputs.key }}
240+ path : ${{ runner.temp }}/packages
241+ key : ${{ steps.lockkey.outputs.key }}
242+ - name : Share the computer images
243+ continue-on-error : true
244+ if : >-
245+ always() && steps.tests.outcome == 'success' && github.event_name == 'push'
246+ env :
247+ GITHUB_TOKEN : ${{ github.token }}
248+ run : .venv/bin/python .github/scripts/share_computer_images.py "$COMPUTER_IMAGE_MIRROR"
261249 - name : Skips must be declared capability gaps
262250 if : always()
263251 run : |
0 commit comments