From bb53b2fbac607bf842aa24d39e3638162b53f7e4 Mon Sep 17 00:00:00 2001 From: Sid Shukla Date: Tue, 21 Nov 2023 18:45:19 +0530 Subject: [PATCH] Add last git commit hash to build flags This ensures we have the git hash of the changes in our CI logs so we can correlate the code changes being executed. --- Makefile | 9 ++++++--- hack/ensure-go.sh | 2 +- hack/install-go.sh | 4 ++-- main.go | 12 +++++++++--- package/docker/Dockerfile | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 687e2c20da..f29da7233c 100644 --- a/Makefile +++ b/Makefile @@ -235,7 +235,8 @@ kind-delete: ## Delete the kind cluster .PHONY: build build: generate fmt ## Build manager binary. - go build -o bin/manager main.go + GIT_COMMIT_HASH=`git rev-parse HEAD` && \ + go build -ldflags "-X main.gitCommit=$${GIT_COMMIT_HASH}" -o bin/manager main.go .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. @@ -243,7 +244,8 @@ run: manifests generate fmt vet ## Run a controller from your host. .PHONY: docker-build docker-build: $(KO) ## Build docker image with the manager. - KO_DOCKER_REPO=ko.local $(KO) build -B --platform=${PLATFORMS} -t ${IMG_TAG} -L . + GIT_COMMIT_HASH=`git rev-parse HEAD` && \ + KO_DOCKER_REPO=ko.local GOFLAGS="-ldflags=-X=main.gitCommitHash=$${GIT_COMMIT_HASH}" $(KO) build -B --platform=${PLATFORMS} -t ${IMG_TAG} -L . .PHONY: docker-push docker-push: $(KO) ## Push docker image with the manager. @@ -330,7 +332,8 @@ cluster-templates: $(KUSTOMIZE) ## Generate cluster templates for all flavors .PHONY: docker-build-e2e docker-build-e2e: $(KO) ## Build docker image with the manager with e2e tag. - KO_DOCKER_REPO=ko.local $(KO) build -B --platform=${PLATFORMS_E2E} -t e2e -L . + GIT_COMMIT_HASH=`git rev-parse HEAD` && \ + KO_DOCKER_REPO=ko.local GOFLAGS="-ldflags=-X=main.gitCommitHash=$${GIT_COMMIT_HASH}" $(KO) build -B --platform=${PLATFORMS_E2E} -t e2e -L . docker tag ko.local/cluster-api-provider-nutanix:e2e ${IMG_REPO}:e2e .PHONY: prepare-local-clusterctl diff --git a/hack/ensure-go.sh b/hack/ensure-go.sh index c06edf43cd..cbb16b0229 100755 --- a/hack/ensure-go.sh +++ b/hack/ensure-go.sh @@ -31,7 +31,7 @@ EOF local go_version IFS=" " read -ra go_version <<< "$(go version)" local minimum_go_version - minimum_go_version=go1.18.3 + minimum_go_version=go1.21.4 if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then cat <