Merge pull request #5886 from influxdata/5884/make_version

fix(server): report correct chronograf version
pull/5888/head
Pavel Závora 2022-03-17 11:16:28 +01:00 committed by GitHub
commit b4266a2838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 5 deletions

View File

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

View File

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

15
dist/dist.go vendored
View File

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