Skip to content

Commit 858611a

Browse files
committed
Check if the new image tag exists
1 parent 155e90c commit 858611a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

build-functions/get-public-image-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22

3+
check_if_tags_exists() {
4+
local image=$1
5+
local tag=$2
6+
skopeo list-tags "docker://$image" | jq -r ".Tags | contains([\"$tag\"])"
7+
}
8+
39
get_image_label() {
410
local label=$1
511
local image=$2

build.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ fi
139139

140140
# Check if we have everything needed for the build
141141
source ./build-functions/check-commands.sh
142-
142+
# Load all build functions
143+
source ./build-functions/get-public-image-config.sh
143144
source ./build-functions/gh-functions.sh
144145

145146
IMAGE_NAMES="${IMAGE_NAMES-docker.io/netboxcommunity/netbox}"
@@ -309,19 +310,22 @@ gh_env "FINAL_DOCKER_TAG=${IMAGE_NAME_TAGS[0]}"
309310
###
310311
# Checking if the build is necessary,
311312
# meaning build only if one of those values changed:
313+
# - a new tag is beeing created
312314
# - base image digest
313315
# - netbox git ref (Label: netbox.git-ref)
314316
# - netbox-docker git ref (Label: org.opencontainers.image.revision)
315317
###
316-
# Load information from registry (only for docker.io)
318+
# Load information from registry (only for first registry in "IMAGE_NAMES")
317319
SHOULD_BUILD="false"
318320
BUILD_REASON=""
319321
if [ -z "${GH_ACTION}" ]; then
320322
# Asuming non Github builds should always proceed
321323
SHOULD_BUILD="true"
322324
BUILD_REASON="${BUILD_REASON} interactive"
325+
elif [ "false" == "$(check_if_tags_exists "${IMAGE_NAMES[0]}" "$TARGET_DOCKER_TAG")" ]; then
326+
SHOULD_BUILD="true"
327+
BUILD_REASON="${BUILD_REASON} newtag"
323328
else
324-
source ./build-functions/get-public-image-config.sh
325329
echo "Checking labels for '${FINAL_DOCKER_TAG}'"
326330
BASE_LAST_LAYER=$(get_image_last_layer "${DOCKER_FROM}")
327331
OLD_BASE_LAST_LAYER=$(get_image_label netbox.last-base-image-layer "${FINAL_DOCKER_TAG}")

0 commit comments

Comments
 (0)