diff --git a/Makefile b/Makefile index b4aadae..547806b 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,14 @@ ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) BUILD_DIR=$(ROOT_DIR)/build BIN=$(BUILD_DIR)/sshpoke GO_VERSION=$(shell go version | sed -e 's/go version //') +VERSION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0.0-%h" -n 1 || echo "v0.0.0-unknown") +LDFLAGS="-X 'github.com/Neur0toxine/sshpoke/cmd.Version=${VERSION}'" .PHONY: run clean_backend build: generate deps fmt @echo " ► Building with ${GO_VERSION}" - @CGO_ENABLED=0 go build -tags=release -o $(BIN) . + @CGO_ENABLED=0 go build -tags=release -ldflags ${LDFLAGS} -o $(BIN) . @echo $(BIN) test: deps fmt diff --git a/cmd/root.go b/cmd/root.go index 9311b64..96a16b0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,12 +17,16 @@ import ( "github.com/spf13/viper" ) -var cfgFile string +var ( + cfgFile string + Version string +) var rootCmd = &cobra.Command{ - Use: "sshpoke", - Short: "Expose your Docker services to the Internet via SSH.", - Long: `sshpoke is a CLI application that listens to the docker socket and automatically exposes relevant services to the Internet.`, + Use: "sshpoke", + Version: Version, + Short: "Expose your Docker services to the Internet via SSH.", + Long: `sshpoke is a CLI application that listens to the docker socket and automatically exposes relevant services to the Internet.`, Run: func(cmd *cobra.Command, args []string) { go api.StartPluginAPI() var err error