Skip to content

Commit f1f3921

Browse files
authored
Merge pull request #18 from kubernetes-sigs/main
Sync main -> release-0.2
2 parents 7b24025 + 4347978 commit f1f3921

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

Diff for: hack/cloudbuild.sh

+41-12
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,84 @@ SIDECAR_IMAGE="${REPO}/objectstorage-sidecar"
1717

1818
# args to 'make build'
1919
export DOCKER="/buildx-entrypoint" # available in gcr.io/k8s-testimages/gcb-docker-gcloud image
20-
export BUILD_ARGS="--push"
2120
export PLATFORM
2221
export SIDECAR_TAG="${SIDECAR_IMAGE}:${GIT_TAG}"
2322
export CONTROLLER_TAG="${CONTROLLER_IMAGE}:${GIT_TAG}"
2423

25-
make build
24+
ADDITIONAL_BUILD_ARGS="--push"
25+
ADDITIONAL_CONTROLLER_TAGS=()
26+
ADDITIONAL_SIDECAR_TAGS=()
2627

2728
# PULL_BASE_REF is 'main' for non-tagged commits on the main branch
2829
if [[ "${PULL_BASE_REF}" == main ]]; then
2930
echo " ! ! ! this is a main branch build ! ! !"
3031
# 'main' tag follows the main branch head
31-
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:main"
32-
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:main"
32+
ADDITIONAL_CONTROLLER_TAGS+=("${CONTROLLER_IMAGE}:main")
33+
ADDITIONAL_SIDECAR_TAGS+=("${SIDECAR_IMAGE}:main")
3334
# 'latest' tag follows 'main' for easy use by developers
34-
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:latest"
35-
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:latest"
35+
ADDITIONAL_CONTROLLER_TAGS+=("${CONTROLLER_IMAGE}:latest")
36+
ADDITIONAL_SIDECAR_TAGS+=("${SIDECAR_IMAGE}:latest")
3637
fi
3738

3839
# PULL_BASE_REF is 'release-*' for non-tagged commits on release branches
3940
if [[ "${PULL_BASE_REF}" == release-* ]]; then
4041
echo " ! ! ! this is a ${PULL_BASE_REF} release branch build ! ! !"
4142
# 'release-*' tags that follow each release branch head
42-
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:${PULL_BASE_REF}"
43-
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:${PULL_BASE_REF}"
43+
ADDITIONAL_CONTROLLER_TAGS+=("${CONTROLLER_IMAGE}:${PULL_BASE_REF}")
44+
ADDITIONAL_SIDECAR_TAGS+=("${SIDECAR_IMAGE}:${PULL_BASE_REF}")
4445
fi
4546

4647
# PULL_BASE_REF is 'controller/TAG' for a tagged controller release
4748
if [[ "${PULL_BASE_REF}" == controller/* ]]; then
4849
echo " ! ! ! this is a tagged controller release ! ! !"
4950
TAG="${PULL_BASE_REF#controller/*}"
50-
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:${TAG}"
51+
# when tagging a release image, do not apply any other tags other than the release tag
52+
# the registry.k8s.io scripting does not handle images with multiple tags
53+
ADDITIONAL_CONTROLLER_TAGS=()
54+
CONTROLLER_TAG="${CONTROLLER_IMAGE}:${TAG}"
5155
fi
5256

5357
# PULL_BASE_REF is 'sidecar/TAG' for a tagged sidecar release
5458
if [[ "${PULL_BASE_REF}" == sidecar/* ]]; then
5559
echo " ! ! ! this is a tagged sidecar release ! ! !"
5660
TAG="${PULL_BASE_REF#sidecar/*}"
57-
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:${TAG}"
61+
# when tagging a release image, do not apply any other tags other than the release tag
62+
# the registry.k8s.io scripting does not handle images with multiple tags
63+
ADDITIONAL_SIDECAR_TAGS=()
64+
SIDECAR_TAG="${SIDECAR_IMAGE}:${TAG}"
5865
fi
5966

6067
# PULL_BASE_REF is 'v0.y.z*' for tagged alpha releases where controller and sidecar are released simultaneously
6168
# hand wave over complex matching logic by just looking for 'v0.' prefix
6269
if [[ "${PULL_BASE_REF}" == 'v0.'* ]]; then
6370
echo " ! ! ! this is a tagged controller + sidecar release ! ! !"
6471
TAG="${PULL_BASE_REF}"
65-
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:${TAG}"
66-
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:${TAG}"
72+
# when tagging a release image, do not apply any other tags other than the release tag
73+
# the registry.k8s.io scripting does not handle images with multiple tags
74+
ADDITIONAL_CONTROLLER_TAGS=()
75+
ADDITIONAL_SIDECAR_TAGS=()
76+
CONTROLLER_TAG="${CONTROLLER_IMAGE}:${TAG}"
77+
SIDECAR_TAG="${SIDECAR_IMAGE}:${TAG}"
6778
fi
6879

6980
# else, PULL_BASE_REF is something that doesn't release image(s) to staging, like:
7081
# - a random branch name (e.g., feature-xyz)
7182
# - a version tag for a subdir with no image associated (e.g., client/v0.2.0, proto/v0.2.0)
83+
84+
# This script's tagging should be less error-prone if 'docker buildx' has all the tags that an image
85+
# will be tagged with during the build process. All tags are applied at once without need to
86+
# maintain tooling for adding tags to manifests after build.
87+
88+
BUILD_ARGS="${ADDITIONAL_BUILD_ARGS}"
89+
for tag in "${ADDITIONAL_CONTROLLER_TAGS[@]}"; do
90+
BUILD_ARGS="${BUILD_ARGS} --tag=${tag}"
91+
done
92+
export BUILD_ARGS
93+
make build.controller
94+
95+
BUILD_ARGS="${ADDITIONAL_BUILD_ARGS}"
96+
for tag in "${ADDITIONAL_SIDECAR_TAGS[@]}"; do
97+
BUILD_ARGS="${BUILD_ARGS} --tag=${tag}"
98+
done
99+
export BUILD_ARGS
100+
make build.sidecar

0 commit comments

Comments
 (0)