-
-
Save zimbatm/c106f1007843889d92d6bb115d43b479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Usage: ./skopeo-push-maybe <SOURCE-IMAGE> <DEST-IMAGE> | |
# | |
# Like skopeo copy but assumes that if the image already exists there is no | |
# need to re-upload the image. | |
# | |
# Needs skopeo 0.1.29+ | |
set -uo pipefail | |
# Config | |
source=$1 | |
dest=$2 | |
## Main | |
# Avoid re-uploading images | |
out=$(skopeo inspect "${dest}" 2>&1) | |
es=$? | |
if [[ $es = 0 ]]; then | |
echo "image already exists" | |
exit 0 | |
fi | |
# Ugly differentiator on error message output since all exit with the same | |
# exit status | |
if echo "$out" | grep "manifest unknown" >/dev/null; then | |
# image doesn't exist, upload | |
exec skopeo copy "$source" "$dest" | |
fi | |
# some other error | |
echo "$out" | |
exit "$es" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment