From 5569ff82ef0cf5951d53345cb5452a0687fd06c0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 8 Jul 2022 15:45:21 +0300 Subject: [PATCH] [#1587] Do not print build time in `version` This makes our build more reproducible. Also print `Component` and `GoVersion`. Signed-off-by: Evgenii Stratonikov --- Makefile | 2 -- cmd/neofs-adm/internal/modules/root.go | 7 +------ cmd/neofs-cli/modules/root.go | 7 +------ cmd/neofs-ir/main.go | 8 +------- cmd/neofs-lens/root.go | 8 ++------ cmd/neofs-node/main.go | 8 +------- misc/build.go | 18 +++++++++++++++--- 7 files changed, 21 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 990e57227..bef55b135 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ SHELL = bash REPO ?= $(shell go list -m) VERSION ?= $(shell git describe --tags --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "develop") -BUILD ?= $(shell date -u --iso=seconds) DEBUG ?= false HUB_IMAGE ?= nspccdev/neofs @@ -36,7 +35,6 @@ $(BINS): $(DIRS) dep CGO_ENABLED=0 \ go build -v -trimpath \ -ldflags "-X $(REPO)/misc.Version=$(VERSION) \ - -X $(REPO)/misc.Build=$(BUILD) \ -X $(REPO)/misc.Debug=$(DEBUG)" \ -o $@ ./cmd/$(notdir $@) diff --git a/cmd/neofs-adm/internal/modules/root.go b/cmd/neofs-adm/internal/modules/root.go index 2234fc3d6..5c2cde674 100644 --- a/cmd/neofs-adm/internal/modules/root.go +++ b/cmd/neofs-adm/internal/modules/root.go @@ -1,7 +1,6 @@ package modules import ( - "fmt" "os" "github.com/nspcc-dev/neofs-node/cmd/neofs-adm/internal/modules/config" @@ -53,11 +52,7 @@ func Execute() error { func entryPoint(cmd *cobra.Command, args []string) error { printVersion, err := cmd.Flags().GetBool("version") if err == nil && printVersion { - fmt.Printf("Version: %s \nBuild: %s \nDebug: %s\n", - misc.Version, - misc.Build, - misc.Debug, - ) + cmd.Print(misc.BuildInfo("NeoFS Adm")) return nil } diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 1f1f2b440..8191ac397 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -87,12 +87,7 @@ func init() { func entryPoint(cmd *cobra.Command, _ []string) { printVersion, _ := cmd.Flags().GetBool("version") if printVersion { - cmd.Printf( - "Version: %s \nBuild: %s \nDebug: %s\n", - misc.Version, - misc.Build, - misc.Debug, - ) + cmd.Print(misc.BuildInfo("NeoFS CLI")) return } diff --git a/cmd/neofs-ir/main.go b/cmd/neofs-ir/main.go index 3c2105b75..824bef413 100644 --- a/cmd/neofs-ir/main.go +++ b/cmd/neofs-ir/main.go @@ -39,12 +39,7 @@ func main() { flag.Parse() if *versionFlag { - fmt.Printf( - "Version: %s \nBuild: %s \nDebug: %s\n", - misc.Version, - misc.Build, - misc.Debug, - ) + fmt.Print(misc.BuildInfo("NeoFS Inner Ring node")) os.Exit(SuccessReturnCode) } @@ -85,7 +80,6 @@ func main() { exitErr(err) log.Info("application started", - zap.String("build_time", misc.Build), zap.String("version", misc.Version), zap.String("debug", misc.Debug), ) diff --git a/cmd/neofs-lens/root.go b/cmd/neofs-lens/root.go index 8cfdd9c39..b82df64f3 100644 --- a/cmd/neofs-lens/root.go +++ b/cmd/neofs-lens/root.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/commands/inspect" @@ -22,11 +21,8 @@ var command = &cobra.Command{ func entryPoint(cmd *cobra.Command, _ []string) error { printVersion, err := cmd.Flags().GetBool("version") if err == nil && printVersion { - fmt.Printf("Version: %s \nBuild: %s \nDebug: %s\n", - misc.Version, - misc.Build, - misc.Debug, - ) + cmd.Print(misc.BuildInfo("NeoFS Lens")) + return nil } diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index a38eec6b2..74440ea6c 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -39,12 +39,7 @@ func main() { flag.Parse() if *versionFlag { - fmt.Printf( - "Version: %s \nBuild: %s \nDebug: %s\n", - misc.Version, - misc.Build, - misc.Debug, - ) + fmt.Print(misc.BuildInfo("NeoFS Storage node")) os.Exit(SuccessReturnCode) } @@ -115,7 +110,6 @@ func bootUp(c *cfg) { func wait(c *cfg) { c.log.Info("application started", - zap.String("build_time", misc.Build), zap.String("version", misc.Version), zap.String("debug", misc.Debug), ) diff --git a/misc/build.go b/misc/build.go index 198c4a433..710229df7 100644 --- a/misc/build.go +++ b/misc/build.go @@ -1,13 +1,25 @@ package misc +import ( + "fmt" + "runtime" +) + // These variables are changed in compile time. var ( - // Build is an application build time. - Build = "now" - // Version is an application version. Version = "dev" // Debug is an application debug mode flag. Debug = "false" ) + +// BuildInfo returns human-readable information about this binary. +func BuildInfo(component string) string { + return fmt.Sprintf("%s\nVersion: %s \nGoVersion: %s\nDebug: %s\n", + component, + Version, + runtime.Version(), + Debug, + ) +}