TELEGRAF_VERSION=1.7.2
go get -d github.com/influxdata/telegraf
cd $GOPATH/src/github.com/influxdata/telegraf
git checkout "$TELEGRAF_VERSION"
make deps
GOOS=linux GOARCH=amd64 go build -o telegraf-"$TELEGRAF_VERSION" ./cmd/telegraf
./telegraf-"$TELEGRAF_VERSION" version
Telegraf v1.7.0~unknown (git: unknown unknown)
To see Telegraf v1.7.2~unknown (git: unknown unknown)
I see Telegraf v1.7.0~unknown (git: unknown unknown)
These values are normally set in make telegraf with help from git, if you want to set them manually you can do it like:
go build -ldflags " -X main.commit=c6feb056 -X main.branch=release-1.7 -X main.version=1.7.2" ./cmd/telegraf
You might also want to add -w -s in your final build to reduce the binary size:
go build -ldflags " -w -s -X main.commit=c6feb056 -X main.branch=release-1.7 -X main.version=1.7.2" ./cmd/telegraf
I misunderstood this initially, if you don't set a version then you get the last major version (set in cmd/telegraf/telegraf.go). I believe this is used in the nightly builds to set the version. I'm going to reopen and will have it set no version if non is explicitly specified.
Oh I see the lines now in cmd/telegraf/telegraf.go, I just assumed that if I had checked out the 1.7.2-tag, it would also build the 1.7.2-binary, but isn't that the case?
Am I correct that my script above will be compiling a version 1.7.2 binary, but because I didn't specify any of this: -X main.commit=c6feb056 -X main.branch=release-1.7 -X main.version=1.7.2 the code defaults to 1.7.0?
You are building it correctly for 1.7.2, just make sure to add the appropriate linker flags to get the version string. We'll fix this in 1.8 with #4521.