Skip to content

Commit 7e08b38

Browse files
committed
Fix floating image tags by building once with multiple tags
Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
1 parent ef19933 commit 7e08b38

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

scripts/docker.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /bin/bash
22
#
33
# Copyright 2021 Google LLC
4-
# Modifications Copyright (C) 2025 OpenInfra Foundation Europe.
4+
# Modifications Copyright (C) 2025-2026 OpenInfra Foundation Europe.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -27,7 +27,8 @@ function err {
2727
function docker_build {
2828
action=$1 # docker buildx operation, it should be either load or push.
2929
name=$2 # function name, e.g. apply-setters
30-
tag=$3 # function tag, e.g. v1.2.3
30+
shift 2
31+
local tags=("$@") # one or more tags, e.g. v1.2.3 v1.2 v1
3132

3233
build_args=()
3334

@@ -53,15 +54,21 @@ function docker_build {
5354
echo "Setting build context to ${function_dir}"
5455
fi
5556

56-
echo "building ${CR_REGISTRY}/${name}:${tag}"
57+
# Build tag arguments
58+
local tag_args=()
59+
for tag in "${tags[@]}"; do
60+
tag_args+=(-t "${CR_REGISTRY}/${name}:${tag}")
61+
done
62+
63+
echo "building ${CR_REGISTRY}/${name} with tags: ${tags[*]}"
5764

5865
case "${action}" in
5966
load)
6067
IFS=' ' read -r -a extra_args_array <<< "${EXTRA_BUILD_ARGS:-}"
6168

6269
# Use + conditional parameter expansion to protect from unbound array variable
6370
docker buildx build --load \
64-
-t "${CR_REGISTRY}/${name}:${tag}" \
71+
"${tag_args[@]}" \
6572
-f "${dockerfile}" \
6673
"${build_args[@]+"${build_args[@]}"}" \
6774
"${extra_args_array[@]+"${extra_args_array[@]}"}" \
@@ -71,7 +78,7 @@ function docker_build {
7178
IFS=' ' read -r -a extra_args_array <<< "${EXTRA_BUILD_ARGS:-}"
7279
# build and push multi-arch image.
7380
docker buildx build --push \
74-
-t "${CR_REGISTRY}/${name}:${tag}" \
81+
"${tag_args[@]}" \
7582
-f "${dockerfile}" \
7683
--platform "linux/amd64,linux/arm64" \
7784
"${build_args[@]+"${build_args[@]}"}" \

scripts/go-function-release.sh

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#! /bin/bash
22
#
33
# Copyright 2021 Google LLC
4+
# Modifications Copyright (C) 2026 The kpt Authors.
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
67
# you may not use this file except in compliance with the License.
@@ -65,14 +66,10 @@ EXTRA_BUILD_ARGS="${EXTRA_BUILD_ARGS:-}"
6566

6667
case "$1" in
6768
build)
68-
for version in "${version_array[@]}"; do
69-
docker_build "load" "${CURRENT_FUNCTION}" "${version}"
70-
done
69+
docker_build "load" "${CURRENT_FUNCTION}" "${version_array[@]}"
7170
;;
7271
push)
73-
for version in "${version_array[@]}"; do
74-
docker_build "push" "${CURRENT_FUNCTION}" "${version}"
75-
done
72+
docker_build "push" "${CURRENT_FUNCTION}" "${version_array[@]}"
7673
;;
7774
*)
7875
echo "Usage: $0 {build|push}"

0 commit comments

Comments
 (0)