[#1587] Do not print build time in version

This makes our build more reproducible.
Also print `Component` and `GoVersion`.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-07-08 15:45:21 +03:00 committed by fyrchik
parent b3272e7cf1
commit 5569ff82ef
7 changed files with 21 additions and 37 deletions

View file

@ -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 $@)

View file

@ -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
}

View file

@ -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
}

View file

@ -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),
)

View file

@ -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
}

View file

@ -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),
)

View file

@ -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,
)
}