#!/usr/bin/env bash # Pull the test image of every training repository once (the harness's name) and tag it with the dataset's name too. # bash train/pull_pool.sh train/pool/pool.json set -u POOL=${1:?pool.json} python3 - "$POOL" <<'EOF' > /tmp/mini_pool_images.txt import json, sys for r, v in json.load(open(sys.argv[1]))["repositories"].items(): print(v["harness_image"], v["dataset_image"]) EOF pull_one() { h=$1; d=$2 for try in $(seq 1 30); do if sudo -n docker image inspect "$h" >/dev/null 2>&1 || sudo -n docker pull -q "$h" >/dev/null 2>&1; then sudo -n docker tag "$h" "$d" 2>/dev/null; sudo -n docker tag "$h" "docker.io/$d" 2>/dev/null echo "ok $h"; return 0 fi # the harness's name may not be published: fall back to the dataset's name if sudo -n docker pull -q "$d" >/dev/null 2>&1; then sudo -n docker tag "$d" "$h"; echo "ok(dataset name) $d"; return 0; fi sleep $((15 + try * 10)) done echo "FAILED $h"; return 1 } export -f pull_one echo "== pool pull start $(date -u +%FT%TZ): $(wc -l < /tmp/mini_pool_images.txt) images" xargs -P 6 -L 1 bash -c 'pull_one "$0" "$1"' < /tmp/mini_pool_images.txt echo "== pool pull done $(date -u +%FT%TZ): $(grep -c . /tmp/mini_pool_images.txt) asked"