Use git sha1 as version if not tagged (#2969)
This commit is contained in:
parent
c30124e192
commit
8bd9ac8697
23
Makefile
23
Makefile
|
@ -1,12 +1,18 @@
|
||||||
VERSION := $(shell sh -c 'git describe --always --tags')
|
VERSION := $(shell git describe --exact-match --tags 2>/dev/null)
|
||||||
BRANCH := $(shell sh -c 'git rev-parse --abbrev-ref HEAD')
|
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
COMMIT := $(shell sh -c 'git rev-parse --short HEAD')
|
COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
ifdef GOBIN
|
ifdef GOBIN
|
||||||
PATH := $(GOBIN):$(PATH)
|
PATH := $(GOBIN):$(PATH)
|
||||||
else
|
else
|
||||||
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
|
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
LDFLAGS := -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)
|
||||||
|
ifdef VERSION
|
||||||
|
LDFLAGS += -X main.version=$(VERSION)
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
# Standard Telegraf build
|
# Standard Telegraf build
|
||||||
default: prepare build
|
default: prepare build
|
||||||
|
|
||||||
|
@ -15,17 +21,16 @@ windows: prepare-windows build-windows
|
||||||
|
|
||||||
# Only run the build (no dependency grabbing)
|
# Only run the build (no dependency grabbing)
|
||||||
build:
|
build:
|
||||||
go install -ldflags \
|
go install -ldflags "$(LDFLAGS)" ./...
|
||||||
"-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)" ./...
|
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
GOOS=windows GOARCH=amd64 go build -o telegraf.exe -ldflags \
|
GOOS=windows GOARCH=amd64 go build -o telegraf.exe \
|
||||||
"-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)" \
|
-ldflags "$(LDFLAGS)" \
|
||||||
./cmd/telegraf/telegraf.go
|
./cmd/telegraf/telegraf.go
|
||||||
|
|
||||||
build-for-docker:
|
build-for-docker:
|
||||||
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o telegraf -ldflags \
|
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o telegraf \
|
||||||
"-s -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)" \
|
-ldflags "$(LDFLAGS)" \
|
||||||
./cmd/telegraf/telegraf.go
|
./cmd/telegraf/telegraf.go
|
||||||
|
|
||||||
# run package script
|
# run package script
|
||||||
|
|
|
@ -57,7 +57,9 @@ var fService = flag.String("service", "",
|
||||||
|
|
||||||
// Telegraf version, populated linker.
|
// Telegraf version, populated linker.
|
||||||
// ie, -ldflags "-X main.version=`git describe --always --tags`"
|
// ie, -ldflags "-X main.version=`git describe --always --tags`"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
nextVersion = "1.4.0"
|
||||||
version string
|
version string
|
||||||
commit string
|
commit string
|
||||||
branch string
|
branch string
|
||||||
|
@ -196,7 +198,7 @@ func reloadLoop(
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Printf("I! Starting Telegraf (version %s)\n", version)
|
log.Printf("I! Starting Telegraf %s\n", displayVersion())
|
||||||
log.Printf("I! Loaded outputs: %s", strings.Join(c.OutputNames(), " "))
|
log.Printf("I! Loaded outputs: %s", strings.Join(c.OutputNames(), " "))
|
||||||
log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " "))
|
log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " "))
|
||||||
log.Printf("I! Tags enabled: %s", c.ListTags())
|
log.Printf("I! Tags enabled: %s", c.ListTags())
|
||||||
|
@ -254,6 +256,13 @@ func (p *program) Stop(s service.Service) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func displayVersion() string {
|
||||||
|
if version == "" {
|
||||||
|
return fmt.Sprintf("v%s~pre%s", nextVersion, commit)
|
||||||
|
}
|
||||||
|
return "v" + version
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() { usageExit(0) }
|
flag.Usage = func() { usageExit(0) }
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -295,7 +304,7 @@ func main() {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "version":
|
case "version":
|
||||||
fmt.Printf("Telegraf v%s (git: %s %s)\n", version, branch, commit)
|
fmt.Printf("Telegraf %s (git: %s %s)\n", displayVersion(), branch, commit)
|
||||||
return
|
return
|
||||||
case "config":
|
case "config":
|
||||||
config.PrintSampleConfig(
|
config.PrintSampleConfig(
|
||||||
|
@ -323,7 +332,7 @@ func main() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case *fVersion:
|
case *fVersion:
|
||||||
fmt.Printf("Telegraf v%s (git: %s %s)\n", version, branch, commit)
|
fmt.Printf("Telegraf %s (git: %s %s)\n", displayVersion(), branch, commit)
|
||||||
return
|
return
|
||||||
case *fSampleConfig:
|
case *fSampleConfig:
|
||||||
config.PrintSampleConfig(
|
config.PrintSampleConfig(
|
||||||
|
|
Loading…
Reference in New Issue