check_update changes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-28 15:15:46 +01:00
parent 9c5bc54452
commit 53c8ff14da

View File

@@ -429,24 +429,18 @@ check_update() {
REPOSITORY_URL=$(echo $IMAGE | cut -d '/' -f1) REPOSITORY_URL=$(echo $IMAGE | cut -d '/' -f1)
# Check whether repository url is available # if image repository url doesn't contain dot (safebox)
CURL_CHECK="curl -m 5 -s -o /dev/null -w "%{http_code}" https://$REPOSITORY_URL/v2/"
CURL_CHECK_CODE=$(eval $CURL_CHECK)
# if valid accessible url OR a repository name without dot (safebox)
if [[ "$CURL_CHECK_CODE" == "200" ]] ; then
debug "$REPOSITORY_URL repository accessed successfully"
# if repository url is not set
if [[ "$(echo "$REPOSITORY_URL" | grep '\.')" == "" ]]; then if [[ "$(echo "$REPOSITORY_URL" | grep '\.')" == "" ]]; then
REPOSITORY_URL="registry.hub.docker.com" REMOTE_URL="registry.hub.docker.com"
TEMP_PATH=$IMAGE TEMP_PATH=$IMAGE
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:{$IMAGE}:pull" | jq -r .token) TEMP_IMAGE=$(echo $TEMP_PATH | cut -d ':' -f1)
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:{$TEMP_IMAGE}:pull" | jq -r .token)
TOKEN_HEADER='-H "Authorization: Bearer '$TOKEN'"' TOKEN_HEADER='-H "Authorization: Bearer '$TOKEN'"'
else else
REMOTE_URL=""
# -f2- IMAGE can contain subdirectories # -f2- IMAGE can contain subdirectories
TEMP_PATH=$(echo $IMAGE | cut -d '/' -f2-) TEMP_PATH=$(echo $IMAGE | cut -d '/' -f2-)
TOKEN=""
TOKEN_HEADER="" TOKEN_HEADER=""
fi fi
@@ -460,21 +454,31 @@ check_update() {
REMOTE_URL="https://$REPOSITORY_URL/v2/$TEMP_IMAGE/manifests/$TEMP_VERSION" REMOTE_URL="https://$REPOSITORY_URL/v2/$TEMP_IMAGE/manifests/$TEMP_VERSION"
debug "$REMOTE_URL" debug "$REMOTE_URL"
# Check whether repository url is available
#CURL_CHECK="curl -m 5 -s -o /dev/null -w "%{http_code}" https://$REPOSITORY_URL/v2/"
CURL_CHECK='curl -m 5 -s -o /dev/null -w "%{http_code}" '"$REMOTE_URL"
CURL_CHECK_CODE=$(eval $CURL_CHECK)
# if valid accessible url
if [[ "$CURL_CHECK_CODE" == "200" ]] ; then
debug "$REMOTE_URL repository accessed successfully"
#digest=$(curl --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "$REMOTE_URL" | jq -r '.config.digest'); #digest=$(curl --silent -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "$REMOTE_URL" | jq -r '.config.digest');
# Digest for the whole manifest, which includes all architectures. # Digest for the whole manifest, which includes all architectures.
digest=$(curl -s -I "$TOKEN_HEADER" -H "Accept: application/vnd.oci.image.index.v1+json" "$REMOTE_URL" | grep -i Docker-Content-Digest | cut -d ' ' -f2 | tr -d '\r\n') CURL_DIGEST=$(echo 'curl -s -I "'$TOKEN_HEADER'" -H "Accept: application/vnd.oci.image.index.v1+json" "'$REMOTE_URL'" | grep -i Docker-Content-Digest' | cut -d ' ' -f2 | tr -d '\r\n')
digest=$(eval $CURL_DIGEST)
#debug "docker images -q --no-trunc $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION"; #debug "docker images -q --no-trunc $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION";
#local_digest=$(docker images -q --no-trunc $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION) #local_digest=$(docker images -q --no-trunc $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION)
debug "docker image inspect $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION --format '{{index .RepoDigests 0}}' | cut -d '@' -f2" debug "docker image inspect $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION --format '{{index .RepoDigests 0}}' | cut -d '@' -f2"
# Digest for the whole manifest, which includes all architectures. # Digest for the whole manifest, which includes all architectures.
local_digest=$(docker image inspect $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION --format '{{index .RepoDigests 0}}' | cut -d '@' -f2) local_digest=$(docker image inspect $IMAGE --format '{{index .RepoDigests 0}}' | cut -d '@' -f2)
debug "REMOTE DIGEST: $digest" debug "REMOTE DIGEST: $digest"
debug "LOCAL DIGEST: $local_digest" debug "LOCAL DIGEST: $local_digest"
if [ "$digest" != "$local_digest" ]; then if [ "$digest" != "$local_digest" ]; then
echo "Update available. Executing update command..." echo "Update available. You can execute update command..."
UPDATE="1" UPDATE="1"
#DOCKER_PULL="docker pull $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION" #DOCKER_PULL="docker pull $REPOSITORY_URL/$TEMP_IMAGE:$TEMP_VERSION"
#eval $DOCKER_PULL #eval $DOCKER_PULL
@@ -486,10 +490,11 @@ check_update() {
# UPDATE="1"; # UPDATE="1";
#fi #fi
else else
UPDATE="0"
echo "Already up to date. Nothing to do." echo "Already up to date. Nothing to do."
fi fi
else else
debug "$REPOSITORY_URL not accessible, http error code: $CURL_CHECK_CODE" debug "$REMOTE_URL not accessible, http error code: $CURL_CHECK_CODE"
echo "Force image pull has started without digest check..." echo "Force image pull has started without digest check..."
DOCKER_PULL="docker pull $IMAGE" DOCKER_PULL="docker pull $IMAGE"