Skip to content

Commit

Permalink
chore: move buildInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Jul 13, 2023
1 parent 33051a4 commit 073f2ae
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL=/usr/bin/env bash
PROJECTNAME=$(shell basename "$(PWD)")
versioningPath := "github.com/celestiaorg/celestia-node/cmd/version"
versioningPath := "github.com/celestiaorg/celestia-node/nodebuilder/node"
LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versioningPath).lastCommit=$(shell git rev-parse HEAD)' -X '$(versioningPath).semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'"
ifeq (${PREFIX},)
PREFIX := /usr/local
Expand Down
4 changes: 1 addition & 3 deletions cmd/celestia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
"os"

"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/cmd/version"
)

func init() {
rootCmd.AddCommand(
bridgeCmd,
lightCmd,
fullCmd,
version.Cmd,
versionCmd,
)
rootCmd.SetHelpCommand(&cobra.Command{})
}
Expand Down
8 changes: 0 additions & 8 deletions cmd/celestia/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/spf13/cobra"

cmdnode "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/cmd/version"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
"github.com/celestiaorg/celestia-node/nodebuilder/gateway"
"github.com/celestiaorg/celestia-node/nodebuilder/header"
Expand All @@ -27,13 +26,6 @@ func persistentPreRunEnv(cmd *cobra.Command, nodeType node.Type, _ []string) err
return err
}
ctx = cmdnode.WithNetwork(ctx, parsedNetwork)
buildInfo := version.GetBuildInfo()
ctx = cmdnode.WithNodeBuildInfo(ctx, &node.BuildInfo{
LastCommit: buildInfo.LastCommit,
SemanticVersion: buildInfo.SemanticVersion,
SystemVersion: buildInfo.SystemVersion,
GolangVersion: buildInfo.GolangVersion,
})

// loads existing config into the environment
ctx, err = cmdnode.ParseNodeFlags(ctx, cmd, cmdnode.Network(ctx))
Expand Down
25 changes: 25 additions & 0 deletions cmd/celestia/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"fmt"

"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/nodebuilder/node"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Show information about the current binary build",
Args: cobra.NoArgs,
Run: printBuildInfo,
}

func printBuildInfo(_ *cobra.Command, _ []string) {
buildInfo := node.GetBuildInfo()
fmt.Printf("Semantic version: %s\n", buildInfo.SemanticVersion)
fmt.Printf("Commit: %s\n", buildInfo.LastCommit)
fmt.Printf("Build Date: %s\n", buildInfo.BuildTime)
fmt.Printf("System version: %s\n", buildInfo.SystemVersion)
fmt.Printf("Golang version: %s\n", buildInfo.GolangVersion)
}
11 changes: 0 additions & 11 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func NodeConfig(ctx context.Context) nodebuilder.Config {
return cfg
}

// NodeInfo reads the node build inforamtion from the context.
func NodeInfo(ctx context.Context) node.BuildInfo {
return ctx.Value(buildInfo{}).(node.BuildInfo)
}

// WithNodeType sets the node type in the given context.
func WithNodeType(ctx context.Context, tp node.Type) context.Context {
return context.WithValue(ctx, nodeTypeKey{}, tp)
Expand Down Expand Up @@ -78,16 +73,10 @@ func WithNodeConfig(ctx context.Context, config *nodebuilder.Config) context.Con
return context.WithValue(ctx, configKey{}, *config)
}

// WithNodeBuildInfo sets the node config build information.
func WithNodeBuildInfo(ctx context.Context, info *node.BuildInfo) context.Context {
return context.WithValue(ctx, node.BuildInfo{}, *info)
}

type (
optionsKey struct{}
configKey struct{}
storePathKey struct{}
nodeTypeKey struct{}
networkKey struct{}
buildInfo struct{}
)
3 changes: 2 additions & 1 deletion cmd/flags_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/celestiaorg/celestia-node/logs"
"github.com/celestiaorg/celestia-node/nodebuilder"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p"
)

Expand Down Expand Up @@ -264,7 +265,7 @@ func ParseMiscFlags(ctx context.Context, cmd *cobra.Command) (context.Context, e
opts = append(opts, otlpmetrichttp.WithInsecure())
}

ctx = WithNodeOptions(ctx, nodebuilder.WithMetrics(opts, NodeType(ctx), NodeInfo(ctx)))
ctx = WithNodeOptions(ctx, nodebuilder.WithMetrics(opts, NodeType(ctx), node.GetBuildInfo()))
}

ok, err = cmd.Flags().GetBool(p2pMetrics)
Expand Down
52 changes: 0 additions & 52 deletions cmd/version/version.go

This file was deleted.

28 changes: 27 additions & 1 deletion nodebuilder/node/buildInfo.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
package node

// BuildInfo stores all necessary information for the current build.
import (
"fmt"
"runtime"
)

var (
buildTime string
lastCommit string
semanticVersion string

systemVersion = fmt.Sprintf("%s/%s", runtime.GOARCH, runtime.GOOS)
golangVersion = runtime.Version()
)

// BuildInfo represents all necessary information about current build.
type BuildInfo struct {
BuildTime string
LastCommit string
SemanticVersion string
SystemVersion string
GolangVersion string
}

// GetBuildInfo returns information about current build.
func GetBuildInfo() *BuildInfo {
return &BuildInfo{
buildTime,
lastCommit,
semanticVersion,
systemVersion,
golangVersion,
}
}
5 changes: 2 additions & 3 deletions nodebuilder/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/celestiaorg/go-fraud"

"github.com/celestiaorg/celestia-node/cmd/version"
"github.com/celestiaorg/celestia-node/nodebuilder/das"
modheader "github.com/celestiaorg/celestia-node/nodebuilder/header"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
Expand Down Expand Up @@ -63,7 +62,7 @@ func WithPyroscope(endpoint string, nodeType node.Type) fx.Option {
}

// WithMetrics enables metrics exporting for the node.
func WithMetrics(metricOpts []otlpmetrichttp.Option, nodeType node.Type, buildInfo node.BuildInfo) fx.Option {
func WithMetrics(metricOpts []otlpmetrichttp.Option, nodeType node.Type, buildInfo *node.BuildInfo) fx.Option {
baseComponents := fx.Options(
fx.Supply(metricOpts),
fx.Supply(buildInfo),
Expand Down Expand Up @@ -112,7 +111,7 @@ func initializeMetrics(
lc fx.Lifecycle,
peerID peer.ID,
nodeType node.Type,
buildInfo version.BuildInfo,
buildInfo node.BuildInfo,
opts []otlpmetrichttp.Option,
) error {
exp, err := otlpmetrichttp.New(ctx, opts...)
Expand Down

0 comments on commit 073f2ae

Please sign in to comment.