diff --git a/Makefile b/Makefile index 613dfdf170d..a61210649d0 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,9 @@ +# Version number +VERSION=$(shell ./tools/image-tag | cut -d, -f 1) + +GIT_REVISION := $(shell git rev-parse --short HEAD) +GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) + GOPATH := $(shell go env GOPATH) GORELEASER := $(GOPATH)/bin/goreleaser @@ -14,7 +20,7 @@ ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \ # ALL_PKGS is used with 'go cover' ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC)))) -GO_OPT= -mod vendor +GO_OPT= -mod vendor -ldflags "-X main.Branch=$(GIT_BRANCH) -X main.Revision=$(GIT_REVISION) -X main.Version=$(VERSION)" GOTEST_OPT?= -race -timeout 5m -count=1 GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -cover GOTEST=go test diff --git a/cmd/tempo/main.go b/cmd/tempo/main.go index db3343c6e8c..4670e22034e 100644 --- a/cmd/tempo/main.go +++ b/cmd/tempo/main.go @@ -25,7 +25,17 @@ import ( const appName = "tempo" +// Version is set via build flag -ldflags -X main.Version +var ( + Version string + Branch string + Revision string +) + func init() { + version.Version = Version + version.Branch = Branch + version.Revision = Revision prometheus.MustRegister(version.NewCollector(appName)) }