From 32e0de5a0f731aa31742c8e00f110952cadaacea Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 4 Oct 2021 17:10:33 +0200 Subject: [PATCH 1/4] added version information --- Makefile | 2 +- internal/app/wwctl/root.go | 2 ++ internal/app/wwctl/version/main.go | 16 ++++++++++++++++ internal/app/wwctl/version/root.go | 22 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 internal/app/wwctl/version/main.go create mode 100644 internal/app/wwctl/version/root.go diff --git a/Makefile b/Makefile index 3903dab4..fc5c6c7c 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ debfiles: debian cp wwclient $(DESTDIR)/var/warewulf/overlays/system/debian/warewulf/bin/ wwctl: - cd cmd/wwctl; GOOS=linux go build -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl + cd cmd/wwctl; GOOS=linux go build -ldflags="-X 'github.com/hpcng/warewulf/internal/app/wwctl/version/version.Version=$(VERSION)'" -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl wwclient: cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags '-extldflags -static' -o ../../wwclient diff --git a/internal/app/wwctl/root.go b/internal/app/wwctl/root.go index 10437f80..059b38db 100644 --- a/internal/app/wwctl/root.go +++ b/internal/app/wwctl/root.go @@ -9,6 +9,7 @@ import ( "github.com/hpcng/warewulf/internal/app/wwctl/power" "github.com/hpcng/warewulf/internal/app/wwctl/profile" "github.com/hpcng/warewulf/internal/app/wwctl/server" + "github.com/hpcng/warewulf/internal/app/wwctl/version" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/hpcng/warewulf/internal/pkg/help" "github.com/spf13/cobra" @@ -46,6 +47,7 @@ func init() { rootCmd.AddCommand(profile.GetCommand()) rootCmd.AddCommand(configure.GetCommand()) rootCmd.AddCommand(server.GetCommand()) + rootCmd.AddCommand(version.GetCommand()) } diff --git a/internal/app/wwctl/version/main.go b/internal/app/wwctl/version/main.go new file mode 100644 index 00000000..0658e986 --- /dev/null +++ b/internal/app/wwctl/version/main.go @@ -0,0 +1,16 @@ +package version + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var Version = "development" + +func CobraRunE(cmd *cobra.Command, args []string) error { + + fmt.Println("Version foo:\t", Version) + + return nil +} diff --git a/internal/app/wwctl/version/root.go b/internal/app/wwctl/version/root.go new file mode 100644 index 00000000..766d3b8f --- /dev/null +++ b/internal/app/wwctl/version/root.go @@ -0,0 +1,22 @@ +package version + +import "github.com/spf13/cobra" + +var ( + baseCmd = &cobra.Command{ + Use: "version", + Short: "Version information", + Long: "This command will print the Warewulf version.", + RunE: CobraRunE, + Args: cobra.ExactArgs(0), + Aliases: []string{"vers"}, + } +) + +func init() { +} + +// GetRootCommand returns the root cobra.Command for the application. +func GetCommand() *cobra.Command { + return baseCmd +} From 58c6adaff46ddc10935fddc646fe4a85cc3838d5 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 4 Oct 2021 19:23:11 +0200 Subject: [PATCH 2/4] using right syntax in Makefile --- Makefile | 8 +++++++- internal/app/wwctl/version/main.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fc5c6c7c..f772eec3 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,12 @@ RELEASE ?= 1 SRC ?= main +VERSION_FULL ?= $(shell test -e .git && git describe --tags --long) +ifeq ($(VERSION_FULL),) +VERSION_FULL := $(VERSION) +endif + + # auto installed tooling TOOLS_DIR := .tools TOOLS_BIN := $(TOOLS_DIR)/bin @@ -115,7 +121,7 @@ debfiles: debian cp wwclient $(DESTDIR)/var/warewulf/overlays/system/debian/warewulf/bin/ wwctl: - cd cmd/wwctl; GOOS=linux go build -ldflags="-X 'github.com/hpcng/warewulf/internal/app/wwctl/version/version.Version=$(VERSION)'" -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl + cd cmd/wwctl; GOOS=linux go build -ldflags="-X 'github.com/hpcng/warewulf/internal/app/wwctl/version.Version=$(VERSION_FULL)'" -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl wwclient: cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags '-extldflags -static' -o ../../wwclient diff --git a/internal/app/wwctl/version/main.go b/internal/app/wwctl/version/main.go index 0658e986..f977b662 100644 --- a/internal/app/wwctl/version/main.go +++ b/internal/app/wwctl/version/main.go @@ -10,7 +10,7 @@ var Version = "development" func CobraRunE(cmd *cobra.Command, args []string) error { - fmt.Println("Version foo:\t", Version) + fmt.Println("Version:\t", Version) return nil } From 0a6d8b39a6151310efdf98fc684396aa47bd6692 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Thu, 7 Oct 2021 11:01:59 +0200 Subject: [PATCH 3/4] on server start print version info --- Makefile | 2 +- internal/app/wwctl/version/main.go | 5 ++--- internal/pkg/version/version.go | 7 +++++++ internal/pkg/warewulfd/daemon.go | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 internal/pkg/version/version.go diff --git a/Makefile b/Makefile index f772eec3..d431dbeb 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ debfiles: debian cp wwclient $(DESTDIR)/var/warewulf/overlays/system/debian/warewulf/bin/ wwctl: - cd cmd/wwctl; GOOS=linux go build -ldflags="-X 'github.com/hpcng/warewulf/internal/app/wwctl/version.Version=$(VERSION_FULL)'" -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl + cd cmd/wwctl; GOOS=linux go build -ldflags="-X 'github.com/hpcng/warewulf/internal/pkg/version.Version=$(VERSION_FULL)'" -mod vendor -tags "$(WW_BUILD_GO_BUILD_TAGS)" -o ../../wwctl wwclient: cd cmd/wwclient; CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -ldflags '-extldflags -static' -o ../../wwclient diff --git a/internal/app/wwctl/version/main.go b/internal/app/wwctl/version/main.go index f977b662..08e48d09 100644 --- a/internal/app/wwctl/version/main.go +++ b/internal/app/wwctl/version/main.go @@ -3,14 +3,13 @@ package version import ( "fmt" + "github.com/hpcng/warewulf/internal/pkg/version" "github.com/spf13/cobra" ) -var Version = "development" - func CobraRunE(cmd *cobra.Command, args []string) error { - fmt.Println("Version:\t", Version) + fmt.Println("Version:\t", version.GetVersion()) return nil } diff --git a/internal/pkg/version/version.go b/internal/pkg/version/version.go new file mode 100644 index 00000000..0e8e1a5a --- /dev/null +++ b/internal/pkg/version/version.go @@ -0,0 +1,7 @@ +package version + +var Version string = "development" + +func GetVersion() string { + return Version +} diff --git a/internal/pkg/warewulfd/daemon.go b/internal/pkg/warewulfd/daemon.go index 042808d0..acb04ac8 100644 --- a/internal/pkg/warewulfd/daemon.go +++ b/internal/pkg/warewulfd/daemon.go @@ -9,6 +9,7 @@ import ( "syscall" "github.com/hpcng/warewulf/internal/pkg/util" + "github.com/hpcng/warewulf/internal/pkg/version" "github.com/pkg/errors" ) @@ -53,7 +54,7 @@ func DaemonStart() error { fmt.Fprintf(p, "%d", pid) - fmt.Printf("Started Warewulf server at PID: %d\n", pid) + fmt.Printf("Started Warewulf (%s) server at PID: %d\n", version.GetVersion(), pid) } From 2a6ba9799244cf00a6c7269f5ca81e57d55117eb Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Mon, 8 Nov 2021 09:30:08 +0100 Subject: [PATCH 4/4] using --first-parent option to describe git version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d431dbeb..a8c28836 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ RELEASE ?= 1 SRC ?= main -VERSION_FULL ?= $(shell test -e .git && git describe --tags --long) +VERSION_FULL ?= $(shell test -e .git && git describe --tags --long --first-parent) ifeq ($(VERSION_FULL),) VERSION_FULL := $(VERSION) endif