From 858611ad675385a304b878bd4baa04b52e3c4ece Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 19 Apr 2023 10:14:44 +0200 Subject: [PATCH] Check if the new image tag exists --- build-functions/get-public-image-config.sh | 6 ++++++ build.sh | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build-functions/get-public-image-config.sh b/build-functions/get-public-image-config.sh index 70c292c..0a19c3f 100644 --- a/build-functions/get-public-image-config.sh +++ b/build-functions/get-public-image-config.sh @@ -1,5 +1,11 @@ #!/bin/bash +check_if_tags_exists() { + local image=$1 + local tag=$2 + skopeo list-tags "docker://$image" | jq -r ".Tags | contains([\"$tag\"])" +} + get_image_label() { local label=$1 local image=$2 diff --git a/build.sh b/build.sh index d1c08e4..5bbaf4d 100755 --- a/build.sh +++ b/build.sh @@ -139,7 +139,8 @@ fi # Check if we have everything needed for the build source ./build-functions/check-commands.sh - +# Load all build functions +source ./build-functions/get-public-image-config.sh source ./build-functions/gh-functions.sh IMAGE_NAMES="${IMAGE_NAMES-docker.io/netboxcommunity/netbox}" @@ -309,19 +310,22 @@ gh_env "FINAL_DOCKER_TAG=${IMAGE_NAME_TAGS[0]}" ### # Checking if the build is necessary, # meaning build only if one of those values changed: +# - a new tag is beeing created # - base image digest # - netbox git ref (Label: netbox.git-ref) # - netbox-docker git ref (Label: org.opencontainers.image.revision) ### -# Load information from registry (only for docker.io) +# Load information from registry (only for first registry in "IMAGE_NAMES") SHOULD_BUILD="false" BUILD_REASON="" if [ -z "${GH_ACTION}" ]; then # Asuming non Github builds should always proceed SHOULD_BUILD="true" BUILD_REASON="${BUILD_REASON} interactive" +elif [ "false" == "$(check_if_tags_exists "${IMAGE_NAMES[0]}" "$TARGET_DOCKER_TAG")" ]; then + SHOULD_BUILD="true" + BUILD_REASON="${BUILD_REASON} newtag" else - source ./build-functions/get-public-image-config.sh echo "Checking labels for '${FINAL_DOCKER_TAG}'" BASE_LAST_LAYER=$(get_image_last_layer "${DOCKER_FROM}") OLD_BASE_LAST_LAYER=$(get_image_label netbox.last-base-image-layer "${FINAL_DOCKER_TAG}")