Skip to content

Sync main -> release-0.2 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions hack/cloudbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,84 @@ SIDECAR_IMAGE="${REPO}/objectstorage-sidecar"

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

make build
ADDITIONAL_BUILD_ARGS="--push"
ADDITIONAL_CONTROLLER_TAGS=()
ADDITIONAL_SIDECAR_TAGS=()

# PULL_BASE_REF is 'main' for non-tagged commits on the main branch
if [[ "${PULL_BASE_REF}" == main ]]; then
echo " ! ! ! this is a main branch build ! ! !"
# 'main' tag follows the main branch head
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:main"
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:main"
ADDITIONAL_CONTROLLER_TAGS+=("${CONTROLLER_IMAGE}:main")
ADDITIONAL_SIDECAR_TAGS+=("${SIDECAR_IMAGE}:main")
# 'latest' tag follows 'main' for easy use by developers
gcloud container images add-tag "${CONTROLLER_TAG}" "${CONTROLLER_IMAGE}:latest"
gcloud container images add-tag "${SIDECAR_TAG}" "${SIDECAR_IMAGE}:latest"
ADDITIONAL_CONTROLLER_TAGS+=("${CONTROLLER_IMAGE}:latest")
ADDITIONAL_SIDECAR_TAGS+=("${SIDECAR_IMAGE}:latest")
fi

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

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

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

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

# else, PULL_BASE_REF is something that doesn't release image(s) to staging, like:
# - a random branch name (e.g., feature-xyz)
# - a version tag for a subdir with no image associated (e.g., client/v0.2.0, proto/v0.2.0)

# This script's tagging should be less error-prone if 'docker buildx' has all the tags that an image
# will be tagged with during the build process. All tags are applied at once without need to
# maintain tooling for adding tags to manifests after build.

BUILD_ARGS="${ADDITIONAL_BUILD_ARGS}"
for tag in "${ADDITIONAL_CONTROLLER_TAGS[@]}"; do
BUILD_ARGS="${BUILD_ARGS} --tag=${tag}"
done
export BUILD_ARGS
make build.controller

BUILD_ARGS="${ADDITIONAL_BUILD_ARGS}"
for tag in "${ADDITIONAL_SIDECAR_TAGS[@]}"; do
BUILD_ARGS="${BUILD_ARGS} --tag=${tag}"
done
export BUILD_ARGS
make build.sidecar