|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Mirror the image Pier uses for each task, then bake that mirrored image into |
| 3 | +# the corresponding hidden-test verifier image. The verifier Dockerfiles are |
| 4 | +# intentionally not changed in the dataset checkout: their FROM instruction is |
| 5 | +# rewritten only in a temporary Dockerfile for this build. |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +: "${BATCH:?BATCH must be set}" |
| 9 | +: "${BATCH_COUNT:?BATCH_COUNT must be set}" |
| 10 | +: "${DATASET_DIR:?DATASET_DIR must be set}" |
| 11 | +: "${TARGET_REGISTRY:?TARGET_REGISTRY must be set}" |
| 12 | +: "${TARGET_CREDS:?TARGET_CREDS must be set}" |
| 13 | + |
| 14 | +force="${FORCE:-false}" |
| 15 | +case "$force" in |
| 16 | + true|false) ;; |
| 17 | + *) echo "FORCE must be true or false, got: $force" >&2; exit 2 ;; |
| 18 | +esac |
| 19 | + |
| 20 | +if (( BATCH < 0 || BATCH >= BATCH_COUNT )); then |
| 21 | + echo "BATCH must be in [0, $((BATCH_COUNT - 1))], got: $BATCH" >&2 |
| 22 | + exit 2 |
| 23 | +fi |
| 24 | + |
| 25 | +task_id_filter="${TASK_ID:-}" |
| 26 | +if [[ -n "$task_id_filter" ]]; then |
| 27 | + if [[ ! -d "$DATASET_DIR/$task_id_filter" ]]; then |
| 28 | + echo "Unknown DeepSWE task_id: $task_id_filter" >&2 |
| 29 | + exit 2 |
| 30 | + fi |
| 31 | + task_dirs=("$DATASET_DIR/$task_id_filter") |
| 32 | +else |
| 33 | + mapfile -t task_dirs < <(find "$DATASET_DIR" -mindepth 1 -maxdepth 1 -type d -print | sort) |
| 34 | +fi |
| 35 | +total="${#task_dirs[@]}" |
| 36 | +batch_size=$(( (total + BATCH_COUNT - 1) / BATCH_COUNT )) |
| 37 | +start=$(( BATCH * batch_size )) |
| 38 | +end=$(( start + batch_size )) |
| 39 | +(( end > total )) && end=$total |
| 40 | + |
| 41 | +echo "DeepSWE tasks: $total; batch $BATCH/$BATCH_COUNT: indexes $start..$((end - 1))" |
| 42 | + |
| 43 | +runtime_ok=0 |
| 44 | +verifier_ok=0 |
| 45 | +skipped=0 |
| 46 | + |
| 47 | +image_exists() { |
| 48 | + skopeo inspect "docker://$1" --creds="$TARGET_CREDS" >/dev/null 2>&1 |
| 49 | +} |
| 50 | + |
| 51 | +for (( index=start; index<end; index++ )); do |
| 52 | + task_dir="${task_dirs[$index]}" |
| 53 | + task_id="${task_dir##*/}" |
| 54 | + task_toml="$task_dir/task.toml" |
| 55 | + tests_dir="$task_dir/tests" |
| 56 | + |
| 57 | + test -f "$task_toml" |
| 58 | + test -f "$tests_dir/Dockerfile" |
| 59 | + |
| 60 | + # This is Pier's default agent image. It is also the base image declared by |
| 61 | + # the task's verifier Dockerfile; checking that prevents a mismatched pair. |
| 62 | + source_runtime=$(sed -n 's/^docker_image = "\([^"]*\)"/\1/p' "$task_toml") |
| 63 | + test -n "$source_runtime" |
| 64 | + test_runtime=$(awk '$1 == "FROM" { print $2; exit }' "$tests_dir/Dockerfile") |
| 65 | + if [[ "$source_runtime" != "$test_runtime" ]]; then |
| 66 | + echo "[$task_id] task.toml image and tests/Dockerfile base differ" >&2 |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + |
| 70 | + # Keep the original source path below the target prefix. This follows the |
| 71 | + # repository's other image-sync jobs and avoids collisions between sources. |
| 72 | + runtime_dest="${TARGET_REGISTRY%/}/${source_runtime}" |
| 73 | + verifier_dest="${TARGET_REGISTRY%/}/deep-swe-verifier/${task_id}:v1.1" |
| 74 | + |
| 75 | + printf '[%d/%d] %s runtime: ' "$((index + 1))" "$total" "$task_id" |
| 76 | + if [[ "$force" == false ]] && image_exists "$runtime_dest"; then |
| 77 | + echo 'SKIP' |
| 78 | + ((skipped+=1)) |
| 79 | + else |
| 80 | + echo 'COPY' |
| 81 | + skopeo copy --all "docker://${source_runtime}" "docker://${runtime_dest}" --dest-creds="$TARGET_CREDS" |
| 82 | + ((runtime_ok+=1)) |
| 83 | + fi |
| 84 | + |
| 85 | + printf '[%d/%d] %s verifier: ' "$((index + 1))" "$total" "$task_id" |
| 86 | + if [[ "$force" == false ]] && image_exists "$verifier_dest"; then |
| 87 | + echo 'SKIP' |
| 88 | + ((skipped+=1)) |
| 89 | + continue |
| 90 | + fi |
| 91 | + echo 'BUILD + PUSH' |
| 92 | + |
| 93 | + # Building from the mirrored runtime makes a batch self-contained after the |
| 94 | + # copy step, rather than pulling its hidden-test base from public ECR. |
| 95 | + temp_dir=$(mktemp -d) |
| 96 | + trap 'rm -rf "$temp_dir"' EXIT |
| 97 | + awk -v runtime="$runtime_dest" ' |
| 98 | + $1 == "FROM" { print "FROM " runtime; next } |
| 99 | + { print } |
| 100 | + ' "$tests_dir/Dockerfile" > "$temp_dir/Dockerfile" |
| 101 | + |
| 102 | + docker pull "$runtime_dest" |
| 103 | + docker build --pull --tag "$verifier_dest" --file "$temp_dir/Dockerfile" "$tests_dir" |
| 104 | + docker push "$verifier_dest" |
| 105 | + # Each task has a different large runtime base. Reclaim it before the next |
| 106 | + # task so an Actions runner does not accumulate the full 113-image suite. |
| 107 | + docker image rm -f "$verifier_dest" "$runtime_dest" >/dev/null 2>&1 || true |
| 108 | + rm -rf "$temp_dir" |
| 109 | + trap - EXIT |
| 110 | + ((verifier_ok+=1)) |
| 111 | +done |
| 112 | + |
| 113 | +echo "Batch complete: $runtime_ok runtime copies, $verifier_ok verifier builds, $skipped skips" |
0 commit comments