Skip to content

Commit 83e45d1

Browse files
committed
Added Version information in the build
1 parent 1fb7c36 commit 83e45d1

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: go
22
go:
33
- 1.x
44
script:
5-
- go build -o haproxy-connect
5+
- go build -o haproxy-connect -ldflags "-X main.BuildTime=`date -u '+%Y-%m-%dT%H:%M:%SZ'` -X main.GitHash=`git rev-parse HEAD` -X main.Version=${TRAVIS_TAG:-Dev}"
66
sudo: false
77
before_deploy:
88
- echo "Deploying $TRAVIS_TAG to GitHub releases"

GNUmakefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BIN := haproxy-connect
2+
SOURCES := $(shell find . -name '*.go')
3+
4+
all: test bin
5+
6+
$(BIN): $(SOURCES)
7+
go build -o haproxy-connect -ldflags "-X main.BuildTime=`date -u '+%Y-%m-%dT%H:%M:%SZ'` -X main.GitHash=`git rev-parse HEAD` -X main.Version=$${TRAVIS_TAG:-Dev}"
8+
9+
bin: $(BIN)
10+
11+
test:
12+
go test -v -timeout 30s ${gobuild_args} ./...

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
6+
"os"
57
"strings"
68

79
log "github.com/sirupsen/logrus"
@@ -14,6 +16,15 @@ import (
1416
"github.com/criteo/haproxy-consul-connect/consul"
1517
)
1618

19+
// Version is set by Travis build
20+
var Version string = "v0.1.9-Dev"
21+
22+
// BuildTime is set by Travis
23+
var BuildTime string = "2020-01-01T00:00:00Z"
24+
25+
// GitHash The last reference Hash from Git
26+
var GitHash string = "unknown"
27+
1728
type consulLogger struct{}
1829

1930
// Debugf Display debug message
@@ -37,6 +48,7 @@ func (consulLogger) Errorf(format string, args ...interface{}) {
3748
}
3849

3950
func main() {
51+
versionFlag := flag.Bool("version", false, "Show version and exit")
4052
logLevel := flag.String("log-level", "INFO", "Log level")
4153
consulAddr := flag.String("http-addr", "127.0.0.1:8500", "Consul agent address")
4254
service := flag.String("sidecar-for", "", "The consul service id to proxy")
@@ -50,6 +62,11 @@ func main() {
5062
token := flag.String("token", "", "Consul ACL token")
5163
flag.Parse()
5264

65+
if versionFlag != nil && *versionFlag {
66+
fmt.Printf("Version: %s ; BuildTime: %s ; GitHash: %s\n", Version, BuildTime, GitHash)
67+
os.Exit(0)
68+
}
69+
5370
ll, err := log.ParseLevel(*logLevel)
5471
if err != nil {
5572
log.Fatal(err)

0 commit comments

Comments
 (0)