Last active
November 22, 2023 00:00
-
-
Save MatthiasLohr/df1ab0ea4fe97d52b9427adc2086f365 to your computer and use it in GitHub Desktop.
Execute script if new docker image is available
This file contains hidden or 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 | |
# Example usage: | |
# ./docker-image-update-check.sh gitlab/gitlab-ce update-gitlab.sh | |
IMAGE="$1" | |
COMMAND="$2" | |
echo "Fetching Docker Hub token..." | |
token=$(curl --silent "https://auth.docker.io/token?scope=repository:$IMAGE:pull&service=registry.docker.io" | jq -r '.token') | |
echo -n "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') | |
echo "$digest" | |
echo -n "Fetching local digest... " | |
local_digest=$(docker images -q --no-trunc $IMAGE:latest) | |
echo "$local_digest" | |
if [ "$digest" != "$local_digest" ] ; then | |
echo "Update available. Executing update command..." | |
($COMMAND) | |
else | |
echo "Already up to date. Nothing to do." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A more recent and complete version of this code and some more scripts can be found here: https://gitlab.com/MatthiasLohr/omnibus-gitlab-management-scripts. For questions, please create a ticket here.
A complete tutorial on how to run GitLab on a Synology NAS can be found here: https://mlohr.com/gitlab-on-a-diskstation/