Skip to content

Commit d84c399

Browse files
committed
Let "latest" tag follow the highest version
Latest tag is now added to the new version when it is release by Netbox.
1 parent a217ce8 commit d84c399

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

build-functions/docker-functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
push_image_to_registry() {
4+
local target_tag=$1
5+
echo "⏫ Pushing '${target_tag}'"
6+
$DRY docker push "${target_tag}"
7+
echo "✅ Finished pushing the Docker image '${target_tag}'."
8+
}

build.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,18 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
222222
# composing the additional DOCKER_SHORT_TAG,
223223
# i.e. "v2.6.1" becomes "v2.6",
224224
# which is only relevant for version tags
225+
# Also let "latest" follow the highest version
225226
###
226227
if [[ "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then
227228
MAJOR=${BASH_REMATCH[1]}
228229
MINOR=${BASH_REMATCH[2]}
229230

230231
TARGET_DOCKER_SHORT_TAG="${DOCKER_SHORT_TAG-${DOCKER_REGISTRY}/${DOCKER_ORG}/${DOCKER_REPO}:v${MAJOR}.${MINOR}}"
232+
TARGET_DOCKER_LATEST_TAG="latest"
231233

232234
if [ "${DOCKER_TARGET}" != "main" ]; then
233235
TARGET_DOCKER_SHORT_TAG="${TARGET_DOCKER_SHORT_TAG}-${DOCKER_TARGET}"
236+
TARGET_DOCKER_LATEST_TAG="${TARGET_DOCKER_LATEST_TAG}-${DOCKER_TARGET}"
234237
fi
235238
fi
236239

@@ -292,6 +295,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
292295
)
293296
if [ -n "${TARGET_DOCKER_SHORT_TAG}" ]; then
294297
DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_SHORT_TAG}" )
298+
DOCKER_BUILD_ARGS+=( -t "${TARGET_DOCKER_LATEST_TAG}" )
295299
fi
296300

297301
# --label
@@ -344,6 +348,8 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
344348
echo " Build reason set to: ${BUILD_REASON}"
345349
$DRY docker build "${DOCKER_BUILD_ARGS[@]}" .
346350
echo "✅ Finished building the Docker images '${TARGET_DOCKER_TAG}'"
351+
echo "🔎 Inspecting labels on '${TARGET_DOCKER_TAG}'"
352+
$DRY docker inspect "${TARGET_DOCKER_TAG}" --format "{{json .Config.Labels}}"
347353
else
348354
echo "Build skipped because sources didn't change"
349355
echo "::set-output name=skipped::true"
@@ -354,16 +360,12 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
354360
# Pushing the docker images if either `--push` or `--push-only` are passed
355361
###
356362
if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ] ; then
357-
echo "⏫ Inspecting labels on '${TARGET_DOCKER_TAG}'"
358-
$DRY docker inspect "${TARGET_DOCKER_TAG}" --format "{{json .Config.Labels}}"
359-
echo "⏫ Pushing '${TARGET_DOCKER_TAG}'"
360-
$DRY docker push "${TARGET_DOCKER_TAG}"
361-
echo "✅ Finished pushing the Docker image '${TARGET_DOCKER_TAG}'."
363+
source ./build-functions/docker-functions.sh
364+
push_image_to_registry "${TARGET_DOCKER_TAG}"
362365

363366
if [ -n "${TARGET_DOCKER_SHORT_TAG}" ]; then
364-
echo "⏫ Pushing '${TARGET_DOCKER_SHORT_TAG}'"
365-
$DRY docker push "${TARGET_DOCKER_SHORT_TAG}"
366-
echo "✅ Finished pushing the Docker image '${TARGET_DOCKER_SHORT_TAG}'."
367+
push_image_to_registry "${TARGET_DOCKER_SHORT_TAG}"
368+
push_image_to_registry "${TARGET_DOCKER_LATEST_TAG}"
367369
fi
368370
fi
369371
done

0 commit comments

Comments
 (0)