diff --git a/Dockerfile b/Dockerfile index 7413f3b3..5b084f55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN set -eux; \ fi; \ if [ -n "$TAGS" ]; then TAGS="-tags $TAGS"; fi; \ CGO_ENABLED=0 GOOS=linux \ - go build -ldflags="-s -w -X main.version=${VERSION}" \ + go build -ldflags="-s -w -X github.com/nextlevelbuilder/goclaw/cmd.Version=${VERSION}" \ ${TAGS} -o /out/goclaw . # ── Stage 2: Runtime ── diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ba95c72a --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev) +LDFLAGS = -s -w -X github.com/nextlevelbuilder/goclaw/cmd.Version=$(VERSION) +BINARY = goclaw + +.PHONY: build run clean version + +build: + CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BINARY) . + +run: build + ./$(BINARY) + +clean: + rm -f $(BINARY) + +version: + @echo $(VERSION) diff --git a/cmd/root.go b/cmd/root.go index ede7b880..bb6d1534 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,6 +9,9 @@ import ( "github.com/nextlevelbuilder/goclaw/pkg/protocol" ) +// Version is set at build time via -ldflags "-X github.com/nextlevelbuilder/goclaw/cmd.Version=v1.0.0" +var Version = "dev" + var ( cfgFile string verbose bool @@ -46,7 +49,7 @@ func versionCmd() *cobra.Command { Use: "version", Short: "Print version information", Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("goclaw v0.2.0 (protocol %d)\n", protocol.ProtocolVersion) + fmt.Printf("goclaw %s (protocol %d)\n", Version, protocol.ProtocolVersion) }, } }