Skip to content

Commit 61713e2

Browse files
authored
[all] Fix cloudbuild (#2145)
* Don't get git version with VERSION is overridden It creates an ugly error in the CI logs when there's no git checkout. * Fix cloudbuild issues
1 parent 42d28be commit 61713e2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ TAR_FILE ?= rootfs.tar
3232

3333
GOOS ?= $(shell go env GOOS)
3434
GOPROXY ?= $(shell go env GOPROXY)
35-
GIT_VERSION := $(shell git describe --dirty --tags --match='v*')
36-
VERSION ?= $(GIT_VERSION)
35+
VERSION ?= $(shell git describe --dirty --tags --match='v*')
3736
GOARCH :=
3837
GOFLAGS :=
3938
TAGS :=

cloudbuild.yaml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ options:
99
machineType: 'N1_HIGHCPU_8'
1010
steps:
1111
- name: gcr.io/k8s-testimages/gcb-docker-gcloud
12-
entrypoint: make
12+
entrypoint: bash
1313
env:
14-
- REGISTRY=gcr.io/$PROJECT_ID
15-
- VERSION=$_GIT_TAG
14+
# Required because the default HOME is /builder/root but buildx is
15+
# installed in /root/.docker. Not setting this results in docker not
16+
# finding buildx during make.
17+
- HOME=/root
1618
args:
17-
- push-multiarch-images
19+
- -c
20+
- |
21+
# Run the image's buildx entrypoint to initialise the build environment
22+
# appropriately for the image before running make
23+
/buildx-entrypoint version
24+
25+
make push-multiarch-images \
26+
REGISTRY=gcr.io/$PROJECT_ID \
27+
VERSION=$_SHORT_TAG
1828
substitutions:
1929
# _GIT_TAG will be filled with a git-based tag for the image, of the form
2030
# vYYYYMMDD-hash, and can be used as a substitution
21-
_GIT_TAG: '12345'
31+
_GIT_TAG: 'v99999999-v12345'
32+
# Remove date prefix (first 10 characters) to create valid semver version:
33+
# v20220510-v1.24.0-alpha.0-15-g09bd268 => v1.24.0-alpha.0-15-g09bd268
34+
_SHORT_TAG: '${_GIT_TAG:10}'
2235
# _PULL_BASE_REF will contain the ref that was pushed to to trigger this
2336
# build - a branch like 'master' or 'release-0.2', or a tag like 'v0.2'.
2437
_PULL_BASE_REF: 'master'

0 commit comments

Comments
 (0)