Skip to content

Instantly share code, notes, and snippets.

@MatthiasLohr
Last active November 22, 2023 00:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthiasLohr/df1ab0ea4fe97d52b9427adc2086f365 to your computer and use it in GitHub Desktop.
Save MatthiasLohr/df1ab0ea4fe97d52b9427adc2086f365 to your computer and use it in GitHub Desktop.
Execute script if new docker image is available
#!/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
@MatthiasLohr
Copy link
Author

MatthiasLohr commented Apr 24, 2020

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment