Created
October 21, 2021 11:32
-
-
Save Kline-/bbd802a142e6e78cb9cc86533f9a74bf to your computer and use it in GitHub Desktop.
Check docker hub for image updates. Adapted from: https://mlohr.com/check-for-docker-image-updates/
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
#!/bin/bash | |
VERBOSE=false | |
ec() { | |
if $VERBOSE; then echo -en $1; fi | |
} | |
for IMAGE in $(docker images | grep -v '^REPOSITORY' | cut -f1 -d' ') | |
do | |
ec "Fetching Docker Hub token...\n" | |
token=$(curl --silent "https://auth.docker.io/token?scope=repository:$IMAGE:pull&service=registry.docker.io" | jq -r '.token') | |
ec "Fetching remote digest... " | |
digest=$(curl --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \ | |
-H "Authorization: Bearer $token" \ | |
"https://registry.hub.docker.com/v2/$IMAGE/manifests/latest" | jq -r '.config.digest') | |
ec "$digest\n" | |
ec "Fetching local digest... " | |
local_digest=$(docker images -q --no-trunc $IMAGE:latest) | |
ec "$local_digest\n" | |
if [ "$digest" != "$local_digest" ] ; then | |
echo "Update available for: $IMAGE" | |
else | |
echo "Already up to date. Nothing to do for: $IMAGE" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment