Skip to content

Commit

Permalink
chore: Report git version/tag/hash in the startup logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rg0now committed May 10, 2024
1 parent 374ecc5 commit e1f30a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
28 changes: 19 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions cmd/stunnerd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<unknown>"
)

func main() {
os.Args[0] = "stunnerd"
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions pkg/buildinfo/build_info.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit e1f30a6

Please sign in to comment.