From 00dd02f89c82c2b74ead3380a73c263b35c54a2f Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Mon, 16 Aug 2021 05:10:19 -0700 Subject: [PATCH] test images: Use PULL_BASE_SHA for non-git image building In the test image build jobs, the image-util.sh script is not being run in a git repository, which causes git log to fail. In this case, we can use the PULL_BASE_SHA set in cloudbuild.yaml instead. --- test/images/cloudbuild.yaml | 4 +++- test/images/image-util.sh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/images/cloudbuild.yaml b/test/images/cloudbuild.yaml index c575622e52f..936b8629ddd 100644 --- a/test/images/cloudbuild.yaml +++ b/test/images/cloudbuild.yaml @@ -14,8 +14,8 @@ steps: dir: ./test/images/ env: - DOCKER_CLI_EXPERIMENTAL=enabled - - TAG=$_GIT_TAG - BASE_REF=$_PULL_BASE_REF + - GIT_COMMIT_ID=$_PULL_BASE_SHA - WHAT=$_WHAT - REGISTRY=$_REGISTRY # The default cloudbuild has HOME=/builder/home and docker buildx is in /root/.docker/cli-plugins/docker-buildx @@ -40,6 +40,8 @@ substitutions: # _PULL_BASE_REF will contain the ref that was pushed to to trigger this build - # a branch like 'master' or 'release-0.2', or a tag like 'v0.2'. _PULL_BASE_REF: 'master' + # _PULL_BASE_SHA will contain the git SHA from which the image will be built from. + _PULL_BASE_SHA: '12345' # _REGISTRY will contain the staging registry. _REGISTRY: 'gcr.io/k8s-staging-e2e-test-images' # _WHAT will contain the image name to be built and published to the staging registry. diff --git a/test/images/image-util.sh b/test/images/image-util.sh index e01f8c731a7..81120aa2a07 100755 --- a/test/images/image-util.sh +++ b/test/images/image-util.sh @@ -36,7 +36,9 @@ source "${KUBE_ROOT}/hack/lib/util.sh" # Mapping of go ARCH to actual architectures shipped part of multiarch/qemu-user-static project declare -A QEMUARCHS=( ["amd64"]="x86_64" ["arm"]="arm" ["arm64"]="aarch64" ["ppc64le"]="ppc64le" ["s390x"]="s390x" ) -GIT_COMMIT_ID=$(git log -1 --format=%h) +# NOTE(claudiub): In the test image build jobs, this script is not being run in a git repository, +# which would cause git log to fail. Instead, we can use the GIT_COMMIT_ID set in cloudbuild.yaml. +GIT_COMMIT_ID=$(git log -1 --format=%h || echo "${GIT_COMMIT_ID}") windows_os_versions=(1809 2004 20H2) declare -A WINDOWS_OS_VERSIONS_MAP