diff --git a/app/common.go b/app/common.go index c0d031df3..b123272ef 100644 --- a/app/common.go +++ b/app/common.go @@ -121,12 +121,24 @@ Usage: %s run [flags] Write process ID to a file. ` -const VERSION = `openGemini version info: +// Version information, the value is set by the build script +var ( + Version string + GitCommit string + GitBranch string + BuildTime string +) + +// FullVersion returns the full version string. +func FullVersion(app string) string { + const format = `openGemini version info: %s: %s git: %s %s os: %s -arch: %s -` +arch: %s` + + return fmt.Sprintf(format, app, Version, GitBranch, GitCommit, runtime.GOOS, runtime.GOARCH) +} // Options represents the command line options that can be parsed. type Options struct { @@ -279,8 +291,8 @@ type ServerInfo struct { BuildTime string } -func (i *ServerInfo) FullVersion() string { - return fmt.Sprintf(VERSION, i.App, i.Version, i.Branch, i.Commit, runtime.GOOS, runtime.GOARCH) +func (si *ServerInfo) FullVersion() string { + return FullVersion(string(si.App)) } func LogStarting(name string, info *ServerInfo) { diff --git a/app/ts-cli/cmd/root.go b/app/ts-cli/cmd/root.go index a4be31dc3..1f97de935 100644 --- a/app/ts-cli/cmd/root.go +++ b/app/ts-cli/cmd/root.go @@ -36,7 +36,6 @@ var ( // Execute executes the root command. func Execute() { - rootCmd.AddCommand() err := rootCmd.Execute() if err != nil { os.Exit(1) diff --git a/app/ts-cli/cmd/version.go b/app/ts-cli/cmd/version.go index 9f840b3dc..13bbcd1de 100644 --- a/app/ts-cli/cmd/version.go +++ b/app/ts-cli/cmd/version.go @@ -17,11 +17,12 @@ limitations under the License. package cmd import ( + "fmt" + + "github.com/openGemini/openGemini/app" "github.com/spf13/cobra" ) -const TsCli = "ts-cli" - func init() { rootCmd.AddCommand(versionCmd) } @@ -31,5 +32,6 @@ var versionCmd = &cobra.Command{ Short: "Display the version of openGemini CLI", Long: `Display the version of openGemini CLI.`, Run: func(cmd *cobra.Command, args []string) { + fmt.Println(app.FullVersion("ts-cli")) }, } diff --git a/app/ts-cli/geminicli/cli.go b/app/ts-cli/geminicli/cli.go index 0fd7db631..f4317c77b 100644 --- a/app/ts-cli/geminicli/cli.go +++ b/app/ts-cli/geminicli/cli.go @@ -33,13 +33,13 @@ import ( "github.com/influxdata/influxdb/client" "github.com/influxdata/influxdb/models" "github.com/olekukonko/tablewriter" + "github.com/openGemini/openGemini/app" "github.com/openGemini/openGemini/app/ts-cli/geminiql" "github.com/openGemini/openGemini/lib/util/lifted/influx/influxql" "golang.org/x/term" ) const ( - CLIENT_VERSION = "0.1.0" DEFAULT_FORMAT = "column" DEFAULT_HOST = "localhost" DEFAULT_PORT = 8086 @@ -150,7 +150,7 @@ func (c *CommandLine) Connect(addr string) error { config.URL = url } - config.UserAgent = "openGemini CLI/" + CLIENT_VERSION + config.UserAgent = "openGemini CLI/" + app.Version config.Proxy = http.ProxyFromEnvironment client, err := c.clientCreator(config) @@ -481,7 +481,7 @@ func (c *CommandLine) clientBatchPoints(db string, rp string, raw string) *clien } func (c *CommandLine) Run() error { - fmt.Printf("openGemini CLI %s (rev-%s)\n", CLIENT_VERSION, "revision") + fmt.Printf("openGemini CLI %s (rev-%s)\n", app.Version, "revision") fmt.Println("Please use `quit`, `exit` or `Ctrl-D` to exit this program.") completer := NewCompleter() p := prompt.New( diff --git a/app/ts-cli/main.go b/app/ts-cli/main.go index 0b238ad50..6629457d6 100644 --- a/app/ts-cli/main.go +++ b/app/ts-cli/main.go @@ -17,22 +17,13 @@ limitations under the License. package main import ( - "fmt" "os" - "runtime" parse "github.com/influxdata/influxdb/cmd" - "github.com/openGemini/openGemini/app" "github.com/openGemini/openGemini/app/ts-cli/analyzer" "github.com/openGemini/openGemini/app/ts-cli/cmd" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string -) - func main() { doRun(os.Args[1:]...) } @@ -40,8 +31,6 @@ func main() { func doRun(args ...string) { name, _ := parse.ParseCommandName(args) switch name { - case "version": - fmt.Printf(app.VERSION, cmd.TsCli, TsVersion, TsBranch, TsCommit, runtime.GOOS, runtime.GOARCH) case "analyze": az := analyzer.NewAnalyzer() az.Analyze(args[1]) diff --git a/app/ts-data/main.go b/app/ts-data/main.go index fbaa0e730..a6ca66b8f 100644 --- a/app/ts-data/main.go +++ b/app/ts-data/main.go @@ -26,23 +26,16 @@ import ( "github.com/openGemini/openGemini/lib/errno" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string - TsBuildTime string -) - func main() { app.InitParse() errno.SetNode(errno.NodeData) info := app.ServerInfo{ App: config.AppData, - Version: TsVersion, - Commit: TsCommit, - Branch: TsBranch, - BuildTime: TsBuildTime, + Version: app.Version, + Commit: app.GitCommit, + Branch: app.GitBranch, + BuildTime: app.BuildTime, } cmdStore := store.NewCommand(info, true) diff --git a/app/ts-meta/main.go b/app/ts-meta/main.go index 806bc551a..2526073ef 100644 --- a/app/ts-meta/main.go +++ b/app/ts-meta/main.go @@ -25,22 +25,15 @@ import ( "github.com/openGemini/openGemini/lib/errno" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string - TsBuildTime string -) - func main() { errno.SetNode(errno.NodeMeta) app.InitParse() info := app.ServerInfo{ App: config.AppMeta, - Version: TsVersion, - Commit: TsCommit, - Branch: TsBranch, - BuildTime: TsBuildTime, + Version: app.Version, + Commit: app.GitCommit, + Branch: app.GitBranch, + BuildTime: app.BuildTime, } app.Run(os.Args[1:], run.NewCommand(info, true)) diff --git a/app/ts-monitor/main.go b/app/ts-monitor/main.go index a5bbf044a..96c3ea8b6 100644 --- a/app/ts-monitor/main.go +++ b/app/ts-monitor/main.go @@ -19,7 +19,6 @@ package main import ( "fmt" "os" - "runtime" "github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil" "github.com/influxdata/influxdb/cmd" @@ -33,13 +32,6 @@ import ( "go.uber.org/zap" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string - TsBuildTime string -) - const TsMonitor = "ts-monitor" var ( @@ -69,10 +61,10 @@ func doRun(args ...string) error { mainCmd := app.NewCommand() info := app.ServerInfo{ App: config.AppMonitor, - Version: TsVersion, - Commit: TsCommit, - Branch: TsBranch, - BuildTime: TsBuildTime, + Version: app.Version, + Commit: app.GitCommit, + Branch: app.GitBranch, + BuildTime: app.BuildTime, } mainCmd.Info = info mainCmd.Logo = app.MONITORLOGO @@ -86,8 +78,8 @@ func doRun(args ...string) error { mainCmd.Logger = logger.NewLogger(errno.ModuleUnknown) mainCmd.Command = &cobra.Command{ Use: monitorUsage, - Version: TsVersion, - ValidArgs: []string{TsBranch, TsCommit, TsBuildTime}, + Version: app.Version, + ValidArgs: []string{app.GitBranch, app.GitCommit, app.BuildTime}, DisableFlagParsing: true, RunE: func(cmd *cobra.Command, args []string) error { fmt.Fprint(os.Stdout, app.MONITORLOGO) @@ -121,7 +113,7 @@ func doRun(args ...string) error { util.MustClose(mainCmd) mainCmd.Logger.Info("Monitor shutdown successfully!") case "version": - fmt.Printf(app.VERSION, TsMonitor, TsVersion, TsBranch, TsCommit, runtime.GOOS, runtime.GOARCH) + fmt.Println(app.FullVersion(TsMonitor)) default: return fmt.Errorf(monitorUsage) } diff --git a/app/ts-server/main.go b/app/ts-server/main.go index ae2a2463d..5e624b316 100644 --- a/app/ts-server/main.go +++ b/app/ts-server/main.go @@ -28,23 +28,16 @@ import ( "github.com/openGemini/openGemini/lib/errno" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string - TsBuildTime string -) - func main() { app.InitParse() errno.SetNode(errno.NodeServer) info := app.ServerInfo{ App: config.AppSingle, - Version: TsVersion, - Commit: TsCommit, - Branch: TsBranch, - BuildTime: TsBuildTime, + Version: app.Version, + Commit: app.GitCommit, + Branch: app.GitBranch, + BuildTime: app.BuildTime, } cmdMeta := meta.NewCommand(info, false) diff --git a/app/ts-sql/main.go b/app/ts-sql/main.go index d0cb6fba7..c839d1645 100644 --- a/app/ts-sql/main.go +++ b/app/ts-sql/main.go @@ -25,22 +25,15 @@ import ( "github.com/openGemini/openGemini/lib/errno" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string - TsBuildTime string -) - func main() { errno.SetNode(errno.NodeSql) app.InitParse() info := app.ServerInfo{ App: config.AppSql, - Version: TsVersion, - Commit: TsCommit, - Branch: TsBranch, - BuildTime: TsBuildTime, + Version: app.Version, + Commit: app.GitCommit, + Branch: app.GitBranch, + BuildTime: app.BuildTime, } app.Run(os.Args[1:], ingestserver.NewCommand(info)) diff --git a/app/ts-store/main.go b/app/ts-store/main.go index 6172cf787..2cfd91558 100644 --- a/app/ts-store/main.go +++ b/app/ts-store/main.go @@ -25,22 +25,15 @@ import ( "github.com/openGemini/openGemini/lib/errno" ) -var ( - TsVersion = "v1.1.0rc0" - TsCommit string - TsBranch string - TsBuildTime string -) - func main() { app.InitParse() errno.SetNode(errno.NodeStore) info := app.ServerInfo{ App: config.AppStore, - Version: TsVersion, - Commit: TsCommit, - Branch: TsBranch, - BuildTime: TsBuildTime, + Version: app.Version, + Commit: app.GitCommit, + Branch: app.GitBranch, + BuildTime: app.BuildTime, } app.Run(os.Args[1:], run.NewCommand(info, true)) diff --git a/build.py b/build.py index d3bee6c31..a07afbbe6 100644 --- a/build.py +++ b/build.py @@ -380,16 +380,17 @@ def build(version=None, if len(tags) > 0: build_command += "-tags {} ".format(','.join(tags)) - if static: - build_command += "-ldflags=\"-s -X main.TsVersion={} -X main.TsBranch={} -X main.TsCommit={}\" ".format(version, - get_current_branch(), - get_current_commit()) - else: - build_command += "-ldflags=\"-X main.TsVersion={} -X main.TsBranch={} -X main.TsCommit={}\" ".format(version, - get_current_branch(), - get_current_commit()) if static: build_command += "-a -installsuffix cgo " + ldflags = "-ldflags=\"-s -X {package}.Version={version} -X {package}.GitBranch={branch} -X {package}.GitCommit={commit}\" " + else: + ldflags = "-ldflags=\"-X {package}.Version={version} -X {package}.GitBranch={branch} -X {package}.GitCommit={commit}\" " + + build_command += ldflags.format( + package = "github.com/openGemini/openGemini/app", + version = version, + branch = get_current_branch(), + commit = get_current_commit()) build_command += path start_time = datetime.utcnow()