Skip to content

Instantly share code, notes, and snippets.

@dumbmoron
Last active February 10, 2024 00:10
Show Gist options
  • Save dumbmoron/7c556d6226f73921e3548e7fab947b2d to your computer and use it in GitHub Desktop.
Save dumbmoron/7c556d6226f73921e3548e7fab947b2d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# utility for syncing docker images across repos, or even registries
# depends on regclient. installation guide: https://github.com/regclient/regclient/blob/main/docs/install.md
# edit IMAGE_A and IMAGE_B below to whatever you want
# if the tags exist on both sides, but differ, A is the authoritative source (B will be overwritten)
IMAGE_A="ghcr.io/wukko/cobalt"
IMAGE_B="ghcr.io/justusecobalt/cobalt"
set -eu -o pipefail
ALL_TAGS=$(sort -Vru < <(printf '%s\n%s\n' "$(regctl tag ls $IMAGE_A)" "$(regctl tag ls $IMAGE_B)"))
N=8
for tag in $ALL_TAGS; do
SOURCE="$IMAGE_A:$tag"
DEST="$IMAGE_B:$tag"
(
echo "checking $SOURCE <-> $DEST"
DIFF=$(regctl manifest diff "$SOURCE" "$DEST" 2>/dev/null || echo 404)
if [ "$DIFF" != "" ]; then
regctl image copy "$SOURCE" "$DEST" || true
sleep 3
regctl image copy "$DEST" "$SOURCE" || true
fi
) &
if [[ $(jobs -r -p | wc -l) -ge $N ]]; then
wait -n
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment