@@ -17,55 +17,74 @@ SIDECAR_IMAGE="${REPO}/objectstorage-sidecar"
17
17
18
18
# args to 'make build'
19
19
export DOCKER=" /buildx-entrypoint" # available in gcr.io/k8s-testimages/gcb-docker-gcloud image
20
- export BUILD_ARGS=" --push"
21
20
export PLATFORM
22
21
export SIDECAR_TAG=" ${SIDECAR_IMAGE} :${GIT_TAG} "
23
22
export CONTROLLER_TAG=" ${CONTROLLER_IMAGE} :${GIT_TAG} "
24
23
25
- make build
24
+ ADDITIONAL_BUILD_ARGS=" --push"
25
+ ADDITIONAL_CONTROLLER_TAGS=()
26
+ ADDITIONAL_SIDECAR_TAGS=()
26
27
27
28
# PULL_BASE_REF is 'main' for non-tagged commits on the main branch
28
29
if [[ " ${PULL_BASE_REF} " == main ]]; then
29
30
echo " ! ! ! this is a main branch build ! ! !"
30
31
# '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" )
33
34
# '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" )
36
37
fi
37
38
38
39
# PULL_BASE_REF is 'release-*' for non-tagged commits on release branches
39
40
if [[ " ${PULL_BASE_REF} " == release-* ]]; then
40
41
echo " ! ! ! this is a ${PULL_BASE_REF} release branch build ! ! !"
41
42
# '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} " )
44
45
fi
45
46
46
47
# PULL_BASE_REF is 'controller/TAG' for a tagged controller release
47
48
if [[ " ${PULL_BASE_REF} " == controller/* ]]; then
48
49
echo " ! ! ! this is a tagged controller release ! ! !"
49
50
TAG=" ${PULL_BASE_REF# controller/* } "
50
- gcloud container images add-tag " ${CONTROLLER_TAG} " " ${ CONTROLLER_IMAGE} :${TAG} "
51
+ ADDITIONAL_CONTROLLER_TAGS+=( " ${CONTROLLER_IMAGE} :${TAG} " )
51
52
fi
52
53
53
54
# PULL_BASE_REF is 'sidecar/TAG' for a tagged sidecar release
54
55
if [[ " ${PULL_BASE_REF} " == sidecar/* ]]; then
55
56
echo " ! ! ! this is a tagged sidecar release ! ! !"
56
57
TAG=" ${PULL_BASE_REF# sidecar/* } "
57
- gcloud container images add-tag " ${SIDECAR_TAG} " " ${ SIDECAR_IMAGE} :${TAG} "
58
+ ADDITIONAL_SIDECAR_TAGS+=( " ${SIDECAR_IMAGE} :${TAG} " )
58
59
fi
59
60
60
61
# PULL_BASE_REF is 'v0.y.z*' for tagged alpha releases where controller and sidecar are released simultaneously
61
62
# hand wave over complex matching logic by just looking for 'v0.' prefix
62
63
if [[ " ${PULL_BASE_REF} " == ' v0.' * ]]; then
63
64
echo " ! ! ! this is a tagged controller + sidecar release ! ! !"
64
65
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} " )
67
68
fi
68
69
69
70
# else, PULL_BASE_REF is something that doesn't release image(s) to staging, like:
70
71
# - a random branch name (e.g., feature-xyz)
71
72
# - 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