Skip to content

Commit

Permalink
Merge pull request #24 from pierresouchay/added_version_in_build
Browse files Browse the repository at this point in the history
Added Version information in the build
  • Loading branch information
aiharos authored Apr 15, 2020
2 parents fed83d3 + 83e45d1 commit d27aa95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: go
go:
- 1.x
script:
- go build -o haproxy-connect
- 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}"
sudo: false
before_deploy:
- echo "Deploying $TRAVIS_TAG to GitHub releases"
Expand Down
12 changes: 12 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BIN := haproxy-connect
SOURCES := $(shell find . -name '*.go')

all: test bin

$(BIN): $(SOURCES)
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}"

bin: $(BIN)

test:
go test -v -timeout 30s ${gobuild_args} ./...
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"flag"
"fmt"
"os"
"strings"

log "github.com/sirupsen/logrus"
Expand All @@ -14,6 +16,15 @@ import (
"github.com/criteo/haproxy-consul-connect/consul"
)

// Version is set by Travis build
var Version string = "v0.1.9-Dev"

// BuildTime is set by Travis
var BuildTime string = "2020-01-01T00:00:00Z"

// GitHash The last reference Hash from Git
var GitHash string = "unknown"

type consulLogger struct{}

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

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

if versionFlag != nil && *versionFlag {
fmt.Printf("Version: %s ; BuildTime: %s ; GitHash: %s\n", Version, BuildTime, GitHash)
os.Exit(0)
}

ll, err := log.ParseLevel(*logLevel)
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit d27aa95

Please sign in to comment.