From d0c0d4a1b4badd20f9d2642451a5b238729c233d Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Thu, 17 Mar 2022 09:32:24 +0100 Subject: [PATCH 1/4] feat(server/bindata): add version to bindata --- dist/dist.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dist/dist.go b/dist/dist.go index 0ba009eb1..268535c38 100644 --- a/dist/dist.go +++ b/dist/dist.go @@ -1,10 +1,11 @@ package dist -//go:generate go-bindata -o dist_gen.go -ignore 'map|go' -pkg dist ../ui/build/... +//go:generate go-bindata -o dist_gen.go -ignore 'map|go' -pkg dist ../ui/build/... ../ui/package.json import ( "fmt" "net/http" + "regexp" "strings" assetfs "github.com/elazarl/go-bindata-assetfs" @@ -98,3 +99,15 @@ func (b *BindataAssets) ServeHTTP(w http.ResponseWriter, r *http.Request) { } http.FileServer(dir).ServeHTTP(w, r) } + +var re = regexp.MustCompile(`"version"\s*:\s*"(.*)"`) + +// GetVersion returns version of the assets +func GetVersion() string { + if data, err := Asset("../ui/package.json"); err == nil { + if matches := re.FindStringSubmatch(string(data)); matches != nil { + return matches[1] + } + } + return "" +} From 57c601d9e3bb23773c4ba5fc961d7f4171f53ead Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Thu, 17 Mar 2022 09:35:56 +0100 Subject: [PATCH 2/4] fix(server): read chronograf version from UI dist by default --- cmd/chronograf/main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd/chronograf/main.go b/cmd/chronograf/main.go index a7eac638d..46252fec7 100644 --- a/cmd/chronograf/main.go +++ b/cmd/chronograf/main.go @@ -6,16 +6,29 @@ import ( "os" "github.com/influxdata/chronograf" + "github.com/influxdata/chronograf/dist" "github.com/influxdata/chronograf/server" flags "github.com/jessevdk/go-flags" ) // Build flags var ( - version = "1.8.0" - commit = "" + version = "" + commit = "" + fullVersion = "" ) +func init() { + if version == "" { + // read version from bindata files + version = dist.GetVersion() + } + fullVersion = version + if commit != "" { + fullVersion = fmt.Sprintf("%s (git: %s)", version, commit) + } +} + func main() { srv := server.Server{ BuildInfo: chronograf.BuildInfo{ @@ -39,7 +52,7 @@ func main() { } if srv.ShowVersion { - fmt.Printf("Chronograf %s (git: %s)\n", version, commit) + fmt.Printf("Chronograf %s\n", fullVersion) os.Exit(0) } From d192f9896fccb17b75c2e2eba953b0f08f8da0b3 Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Thu, 17 Mar 2022 09:52:02 +0100 Subject: [PATCH 3/4] chore: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a751b1170..45637fde7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ 1. [#5874](https://github.com/influxdata/chronograf/pull/5874): Propagate InfluxQL errors to UI. 1. [#5878](https://github.com/influxdata/chronograf/pull/5878): Rename Flux Query to Flux Script. 1. [#5885](https://github.com/influxdata/chronograf/pull/5885): Repair time zone selector on Host page. - +1. [#5886](https://github.com/influxdata/chronograf/pull/5886): Report correct chronograf version. ### Other From b10aa7ab1d26c1b7510f01eb31b2ee2889c9fb45 Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Thu, 17 Mar 2022 09:54:04 +0100 Subject: [PATCH 4/4] chore: improve docs --- dist/dist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/dist.go b/dist/dist.go index 268535c38..effa3c28e 100644 --- a/dist/dist.go +++ b/dist/dist.go @@ -102,7 +102,7 @@ func (b *BindataAssets) ServeHTTP(w http.ResponseWriter, r *http.Request) { var re = regexp.MustCompile(`"version"\s*:\s*"(.*)"`) -// GetVersion returns version of the assets +// GetVersion returns version of the packed assets func GetVersion() string { if data, err := Asset("../ui/package.json"); err == nil { if matches := re.FindStringSubmatch(string(data)); matches != nil {