feat: embed build version info in binaries
This commit is contained in:
24
Makefile
Normal file
24
Makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
APP=inps
|
||||||
|
|
||||||
|
VERSION ?= 0.1.0
|
||||||
|
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
|
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
|
||||||
|
GO_VERSION := $(shell go env GOVERSION 2>/dev/null || echo unknown)
|
||||||
|
|
||||||
|
LDFLAGS := -s -w \
|
||||||
|
-X 'github.com/openp2p-cn/inp2p/pkg/config.Version=$(VERSION)' \
|
||||||
|
-X 'github.com/openp2p-cn/inp2p/pkg/config.GitCommit=$(GIT_COMMIT)' \
|
||||||
|
-X 'github.com/openp2p-cn/inp2p/pkg/config.BuildTime=$(BUILD_TIME)' \
|
||||||
|
-X 'github.com/openp2p-cn/inp2p/pkg/config.GoVersion=$(GO_VERSION)'
|
||||||
|
|
||||||
|
.PHONY: build build-client build-server
|
||||||
|
|
||||||
|
build: build-client build-server
|
||||||
|
|
||||||
|
build-client:
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
||||||
|
go build -ldflags "$(LDFLAGS)" -o bin/inp2pc ./cmd/inp2pc
|
||||||
|
|
||||||
|
build-server:
|
||||||
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
||||||
|
go build -ldflags "$(LDFLAGS)" -o bin/inp2ps ./cmd/inp2ps
|
||||||
@@ -41,7 +41,8 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *version {
|
if *version {
|
||||||
fmt.Printf("inp2pc version %s\n", config.Version)
|
fmt.Printf("inp2pc version %s\ncommit: %s\nbuild: %s\ngo: %s\n",
|
||||||
|
config.Version, config.GitCommit, config.BuildTime, config.GoVersion)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *version {
|
if *version {
|
||||||
fmt.Printf("inp2ps version %s\n", config.Version)
|
fmt.Printf("inp2ps version %s\ncommit: %s\nbuild: %s\ngo: %s\n",
|
||||||
|
config.Version, config.GitCommit, config.BuildTime, config.GoVersion)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,15 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// Version info (set via -ldflags)
|
||||||
Version = "0.1.0"
|
var (
|
||||||
|
Version = "0.1.0"
|
||||||
|
GitCommit = "unknown"
|
||||||
|
BuildTime = "unknown"
|
||||||
|
GoVersion = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
DefaultWSPort = 27183 // WSS signaling
|
DefaultWSPort = 27183 // WSS signaling
|
||||||
DefaultSTUNUDP1 = 27182 // UDP STUN port 1
|
DefaultSTUNUDP1 = 27182 // UDP STUN port 1
|
||||||
DefaultSTUNUDP2 = 27183 // UDP STUN port 2
|
DefaultSTUNUDP2 = 27183 // UDP STUN port 2
|
||||||
|
|||||||
Reference in New Issue
Block a user