#!/usr/bin/env bash # Put every task branch of the training repositories into their images, so the grading harness can check a task # out without the network (its own `git fetch` may fail; its `git checkout ` then still finds the branch). # Run on the node while GitHub is reachable. The image keeps its name and its default command; only fetched git # objects are added. # # A commit of a container keeps the command the container ran as the image's default. The first run of this script # on 2026-12-01 left 18 images starting `bash -c ` for 90 seconds, and task containers started in that # time failed. So: the config is put back with a one-line build right after the commit, under a temporary name, and # the real name is moved to the result only at the end. set -u R=/data/train/mini D=/usr/bin/docker python3 - <<'EOF' > /tmp/mini_pool_harness_images.txt import json for r, v in json.load(open("/data/train/mini/src/train/pool/pool.json"))["repositories"].items(): print(v["harness_image"], v["dataset_image"]) EOF one() { img=$1; alt=$2; name=prefetch-$(echo "$img" | tr -c 'a-zA-Z0-9' '-' | cut -c1-60); tmp="mini-prefetch-tmp:$(echo "$img" | tr -c 'a-zA-Z0-9' '-' | cut -c1-80)" have=$($D run --rm "$img" bash -c 'cd /testbed && git branch -r | wc -l' 2>/dev/null | tr -d ' \n') if [ "${have:-0}" -ge 300 ]; then echo "ok $img: already $have remote branches"; return 0; fi $D rm -f "$name" >/dev/null 2>&1 $D run -d --name "$name" "$img" bash -c 'cd /testbed && for t in 1 2 3 4 5; do git fetch -q origin "+refs/heads/*:refs/remotes/origin/*" && break; sleep 20; done; git branch -r | wc -l > /tmp/branches.txt' >/dev/null || { echo "FAILED start $img"; return 1; } $D wait "$name" >/dev/null n=$($D cp "$name":/tmp/branches.txt - 2>/dev/null | tar -xO 2>/dev/null | tr -d ' \n') $D commit "$name" "$tmp" >/dev/null || { echo "FAILED commit $img"; $D rm -f "$name" >/dev/null 2>&1; return 1; } $D rm -f "$name" >/dev/null 2>&1 printf 'FROM %s\nENTRYPOINT []\nCMD ["/bin/bash"]\n' "$tmp" | $D build -q -t "$tmp-final" - >/dev/null 2>&1 || { echo "FAILED config $img"; return 1; } ep=$($D image inspect --format '{{json .Config.Entrypoint}} {{json .Config.Cmd}}' "$tmp-final") [ "$ep" = 'null ["/bin/bash"]' ] || { echo "FAILED config check $img: $ep"; return 1; } $D tag "$tmp-final" "$img" && $D tag "$img" "$alt" && $D tag "$img" "docker.io/$alt" $D rmi "$tmp" "$tmp-final" >/dev/null 2>&1 echo "ok $img: $n remote branches in the image" } export -f one; export D echo "== prefetch start $(date -u +%TZ)" xargs -P 4 -L 1 bash -c 'one "$0" "$1"' < /tmp/mini_pool_harness_images.txt echo "== prefetch done $(date -u +%TZ)" while read img alt; do echo "$($D image inspect --format 'EP={{json .Config.Entrypoint}} CMD={{json .Config.Cmd}}' "$img")"; done < /tmp/mini_pool_harness_images.txt | sort | uniq -c