@@ -17,55 +17,74 @@ SIDECAR_IMAGE="${REPO}/objectstorage-sidecar"
1717
1818# args to 'make build'
1919export DOCKER=" /buildx-entrypoint" # available in gcr.io/k8s-testimages/gcb-docker-gcloud image
20- export BUILD_ARGS=" --push"
2120export PLATFORM
2221export SIDECAR_TAG=" ${SIDECAR_IMAGE} :${GIT_TAG} "
2322export 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
2829if [[ " ${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" )
3637fi
3738
3839# PULL_BASE_REF is 'release-*' for non-tagged commits on release branches
3940if [[ " ${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} " )
4445fi
4546
4647# PULL_BASE_REF is 'controller/TAG' for a tagged controller release
4748if [[ " ${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+ ADDITIONAL_CONTROLLER_TAGS+=( " ${CONTROLLER_IMAGE} :${TAG} " )
5152fi
5253
5354# PULL_BASE_REF is 'sidecar/TAG' for a tagged sidecar release
5455if [[ " ${PULL_BASE_REF} " == sidecar/* ]]; then
5556 echo " ! ! ! this is a tagged sidecar release ! ! !"
5657 TAG=" ${PULL_BASE_REF# sidecar/* } "
57- gcloud container images add-tag " ${SIDECAR_TAG} " " ${ SIDECAR_IMAGE} :${TAG} "
58+ ADDITIONAL_SIDECAR_TAGS+=( " ${SIDECAR_IMAGE} :${TAG} " )
5859fi
5960
6061# PULL_BASE_REF is 'v0.y.z*' for tagged alpha releases where controller and sidecar are released simultaneously
6162# hand wave over complex matching logic by just looking for 'v0.' prefix
6263if [[ " ${PULL_BASE_REF} " == ' v0.' * ]]; then
6364 echo " ! ! ! this is a tagged controller + sidecar release ! ! !"
6465 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} "
66+ ADDITIONAL_CONTROLLER_TAGS+=( " ${CONTROLLER_IMAGE} :${TAG} " )
67+ ADDITIONAL_SIDECAR_TAGS+=( " ${SIDECAR_IMAGE} :${TAG} " )
6768fi
6869
6970# else, PULL_BASE_REF is something that doesn't release image(s) to staging, like:
7071# - a random branch name (e.g., feature-xyz)
7172# - a version tag for a subdir with no image associated (e.g., client/v0.2.0, proto/v0.2.0)
73+
74+ # 'gcloud container images add-tag' within the cloudbuild infrastructure doesn't preserve the date
75+ # of the underlying image when adding a new tag, resulting in tags dated Dec 31, 1969 (the epoch).
76+ # To ensure the right date on all built image tags, do the build with '--tag' args for all tags.
77+
78+ BUILD_ARGS=" ${ADDITIONAL_BUILD_ARGS} "
79+ for tag in " ${ADDITIONAL_CONTROLLER_TAGS[@]} " ; do
80+ BUILD_ARGS=" ${BUILD_ARGS} --tag=${tag} "
81+ done
82+ export BUILD_ARGS
83+ make build.controller
84+
85+ BUILD_ARGS=" ${ADDITIONAL_BUILD_ARGS} "
86+ for tag in " ${ADDITIONAL_SIDECAR_TAGS[@]} " ; do
87+ BUILD_ARGS=" ${BUILD_ARGS} --tag=${tag} "
88+ done
89+ export BUILD_ARGS
90+ make build.sidecar
0 commit comments