diff --git a/Makefile b/Makefile index c0598e7b..ebb17857 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,17 @@ +# Build variables +PACKAGE = github.com/l7mp/stunner +BUILD_DIR ?= bin/ +VERSION ?= $(shell (git describe --tags --abbrev=8 --always --long) | tr "/" "-") +COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null) +BUILD_DATE ?= $(shell date +%FT%T%z) +LDFLAGS += -X main.version=${VERSION} -X main.commitHash=${COMMIT_HASH} -X main.buildDate=${BUILD_DATE} + +ifeq (${VERBOSE}, 1) +ifeq ($(filter -v,${GOARGS}),) + GOARGS += -v +endif +endif + .PHONY: all all: build @@ -14,20 +28,16 @@ vet: ## Run go vet against code. go vet ./... .PHONY: test -test: manifests generate fmt vet test ## Run tests. +test: generate fmt vet + go test ./... -v ##@ Build .PHONY: build -build: generate fmt vet ## Build binary. - go build -o bin/stunnerd cmd/stunnerd/main.go - go build -o bin/turncat cmd/turncat/main.go - -.PHONY: run -run: manifests generate fmt vet ## Run a controller from your host. - go run cmd/stunnerd/main.go +build: generate fmt vet + go build ${GOARGS} -ldflags "${LDFLAGS}" -o ${BUILD_DIR}/stunnerd cmd/stunnerd/main.go + go build ${GOARGS} -o ${BUILD_DIR}/turncat cmd/turncat/main.go -# clean up generated files .PHONY: clean clean: echo 'Use "make generate` to autogenerate server code' > pkg/server/server.go diff --git a/cmd/stunnerd/main.go b/cmd/stunnerd/main.go index 74f2a7bf..ccab9821 100644 --- a/cmd/stunnerd/main.go +++ b/cmd/stunnerd/main.go @@ -13,10 +13,15 @@ import ( "github.com/l7mp/stunner" stnrv1 "github.com/l7mp/stunner/pkg/apis/v1" + "github.com/l7mp/stunner/pkg/buildinfo" cdsclient "github.com/l7mp/stunner/pkg/config/client" ) -// usage: stunnerd -v turn://user1:passwd1@127.0.0.1:3478?transport=udp +var ( + version = "dev" + commitHash = "n/a" + buildDate = "" +) func main() { os.Args[0] = "stunnerd" @@ -74,7 +79,8 @@ func main() { log := st.GetLogger().NewLogger("stunnerd") - log.Infof("starting stunnerd instance %q", st.GetId()) + buildInfo := buildinfo.BuildInfo{Version: version, CommitHash: commitHash, BuildDate: buildDate} + log.Infof("starting stunnerd id %q, STUNner %s ", st.GetId(), buildInfo.String()) conf := make(chan *stnrv1.StunnerConfig, 1) defer close(conf) diff --git a/pkg/buildinfo/build_info.go b/pkg/buildinfo/build_info.go new file mode 100644 index 00000000..4665b91f --- /dev/null +++ b/pkg/buildinfo/build_info.go @@ -0,0 +1,13 @@ +package buildinfo + +import "fmt" + +type BuildInfo struct { + Version string + CommitHash string + BuildDate string +} + +func (i BuildInfo) String() string { + return fmt.Sprintf("version %s (%s) built on %s", i.Version, i.CommitHash, i.BuildDate) +}