From 6fce58cf2dd81187caf245f506ecea6710354b5d Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Thu, 4 Jul 2024 11:41:56 +0100 Subject: [PATCH] changed commit to gitSHA --- Dockerfile | 6 +++--- Makefile | 12 ++++++------ main.go | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 222dbc9..e03b52f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,12 +17,12 @@ COPY pkg/ pkg/ COPY version/ version/ # Build -ARG COMMIT +ARG GIT_SHA ARG DIRTY -ENV COMMIT=${COMMIT:-unknown} +ENV GIT_SHA=${GIT_SHA:-unknown} ENV DIRTY=${DIRTY:-unknown} -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 5b9c2aa..7d6a072 100644 --- a/Makefile +++ b/Makefile @@ -278,22 +278,22 @@ test-unit: clean-cov generate fmt vet ## Run Unit tests. go test $(UNIT_DIRS) -coverprofile $(PROJECT_PATH)/coverage/unit/cover.out -v -timeout 0 $(TEST_PATTERN) ##@ Build -build: COMMIT=$(shell git rev-parse HEAD) +build: GIT_SHA=$(shell git rev-parse HEAD) build: DIRTY=$(shell $(check_dirty)) build: generate fmt vet ## Build manager binary. - go build -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" -o bin/manager main.go + go build -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" -o bin/manager main.go run: export LOG_LEVEL = debug run: export LOG_MODE = development -run: COMMIT=$(shell git rev-parse HEAD) +run: GIT_SHA=$(shell git rev-parse HEAD) run: DIRTY=$(shell $(check_dirty)) run: manifests generate fmt vet ## Run a controller from your host.) - go run -ldflags "-X main.commit=${COMMIT} -X main.dirty=${DIRTY}" ./main.go + go run -ldflags "-X main.gitSHA=${GIT_SHA} -X main.dirty=${DIRTY}" ./main.go -docker-build: COMMIT=$(shell git rev-parse HEAD) +docker-build: GIT_SHA=$(shell git rev-parse HEAD) docker-build: DIRTY=$(shell $(check_dirty)) docker-build: ## Build docker image with the manager. - docker build --build-arg COMMIT=$(COMMIT) --build-arg DIRTY=$(DIRTY) -t $(IMG) . + docker build --build-arg GIT_SHA=$(GIT_SHA) --build-arg DIRTY=$(DIRTY) -t $(IMG) . docker-push: ## Push docker image with the manager. docker push $(IMG) diff --git a/main.go b/main.go index efd0e45..fabb1f9 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,7 @@ var ( scheme = k8sruntime.NewScheme() logLevel = env.GetString("LOG_LEVEL", "info") logMode = env.GetString("LOG_MODE", "production") - commit string + gitSHA string dirty string ) @@ -72,7 +72,7 @@ func printControllerMetaInfo() { setupLog.Info(fmt.Sprintf("go version: %s", runtime.Version())) setupLog.Info(fmt.Sprintf("go os/arch: %s/%s", runtime.GOOS, runtime.GOARCH)) setupLog.Info("base logger", "log level", logLevel, "log mode", logMode) - setupLog.Info("", "version", version.Version, "commit", commit, "dirty", dirty) + setupLog.Info("", "version", version.Version, "commit", gitSHA, "dirty", dirty) } func main() {