Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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