From fc5e2f406ab7fafdd99dc891e6bdd28d75dcf048 Mon Sep 17 00:00:00 2001 From: Rohit Ramkumar Date: Tue, 17 Apr 2018 21:04:50 -0700 Subject: [PATCH] Add support for logging latest commit hash of GLBC build being used --- Makefile | 3 +++ build/build.sh | 11 ++++++++--- build/rules.mk | 1 + cmd/glbc/main.go | 1 + pkg/version/version.go | 4 ++++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 4d750ab838..16ca47a04e 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,9 @@ PKG := k8s.io/ingress-gce # for each BINARY. CONTAINER_BINARIES := glbc +# Latest commit hash for current branch. +GIT_COMMIT := $(shell git rev-parse HEAD) + # Registry to push to. REGISTRY ?= gcr.io/google_containers diff --git a/build/build.sh b/build/build.sh index 90b9c472de..89a3782aca 100755 --- a/build/build.sh +++ b/build/build.sh @@ -29,6 +29,11 @@ fi if [ -z "${VERSION}" ]; then echo "VERSION must be set" exit 1 + +fi +if [ -z "${GIT_COMMIT}" ]; then + echo "GIT_COMMIT must be set" + exit 1 fi export CGO_ENABLED=0 @@ -37,7 +42,7 @@ if [ $GOARCH == "amd64" ]; then export GOBIN="$GOPATH/bin/linux_amd64" fi -go install \ - -installsuffix "static" \ - -ldflags "-X ${PKG}/pkg/version.Version=${VERSION}" \ +go install \ + -installsuffix "static" \ + -ldflags "-X ${PKG}/pkg/version.Version=${VERSION} -X ${PKG}/pkg/version.GitCommit=${GIT_COMMIT}" \ ./... diff --git a/build/rules.mk b/build/rules.mk index bab9307767..a6ea7553e9 100644 --- a/build/rules.mk +++ b/build/rules.mk @@ -122,6 +122,7 @@ $(GO_BINARIES): build-dirs ARCH=$(ARCH) \ VERSION=$(VERSION) \ PKG=$(PKG) \ + GIT_COMMIT=$(GIT_COMMIT) \ ./build/build.sh \ " diff --git a/cmd/glbc/main.go b/cmd/glbc/main.go index 60c483a2ed..ab5263c03a 100644 --- a/cmd/glbc/main.go +++ b/cmd/glbc/main.go @@ -52,6 +52,7 @@ func main() { } glog.V(0).Infof("Starting GLBC image: %q, cluster name %q", version.Version, flags.F.ClusterName) + glog.V(0).Infof("Latest commit hash: %q", version.GitCommit) for i, a := range os.Args { glog.V(0).Infof("argv[%d]: %q", i, a) } diff --git a/pkg/version/version.go b/pkg/version/version.go index 4093bc0d77..1d3262723f 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -19,3 +19,7 @@ package version // Version is a version string populated by the build using -ldflags "-X // ${PKG}/pkg/version.Version=${VERSION}". var Version = "UNKNOWN" + +// GitCommit is the latest git commit hash populated by the build using +// -ldflags "-X ${PKG}/pkg/version.GitCommit=${GIT_COMMIT}". +var GitCommit = "UNKNOWN"