From ee45c461a2e988cec68f322d7c13c49cceef1ff7 Mon Sep 17 00:00:00 2001 From: Blaine Gardner Date: Thu, 14 Sep 2023 13:39:24 -0600 Subject: [PATCH] allow cloudbuild to build git tags Use the K8s-/Prow-provided _PULL_BASE_REF substitution variable [1] to build images with tags based on the git commit tag. By the K8s docs, this should work, but it remains to be tested. [1] https://github.com/kubernetes/test-infra/blob/master/config/jobs/image-pushing/README.md#custom-substitutions Signed-off-by: Blaine Gardner --- cloudbuild.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index f8057d34..ea212e66 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,5 +1,6 @@ # GCloud build docs: https://cloud.google.com/cloud-build/docs/build-config -# Builds go to: https://console.cloud.google.com/gcr/images/k8s-staging-test-infra/global/ +# Builds go to https://console.cloud.google.com/gcr/images/k8s-staging-test-infra/global/ +# Build logs in https://testgrid.k8s.io/sig-storage-image-build timeout: 3000s options: substitution_option: 'ALLOW_LOOSE' @@ -19,10 +20,15 @@ steps: args: - buildx - build - - --platform="linux/amd64,linux/arm64" + - --platform=linux/amd64,linux/arm64 - --tag=gcr.io/k8s-staging-sig-storage/objectstorage-controller:${_GIT_TAG} + # using _PULL_BASE_REF as a tag will often just build and overwrite the same 'master' tag, + # BUT! if the commit has a git tag, it will build that tag instead. this mechanism allows + # creating the semver-tagged images that will be auto-promoted to release + - --tag=gcr.io/k8s-staging-sig-storage/objectstorage-controller:${_PULL_BASE_REF} - --tag=gcr.io/k8s-staging-sig-storage/objectstorage-controller:latest - . images: - gcr.io/k8s-staging-sig-storage/objectstorage-controller:${_GIT_TAG} + - gcr.io/k8s-staging-sig-storage/objectstorage-controller:${_PULL_BASE_REF} - gcr.io/k8s-staging-sig-storage/objectstorage-controller:latest