mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
build: move version to a single place
Instead of trying to copy Akvorado version around, move it to a single place, which can be imported by everything else.
This commit is contained in:
2
Makefile
2
Makefile
@@ -35,7 +35,7 @@ GENERATED = \
|
||||
all: fmt lint $(GENERATED) | $(BIN) ; $(info $(M) building executable…) @ ## Build program binary
|
||||
$Q $(GO) build \
|
||||
-tags release \
|
||||
-ldflags '-X $(MODULE)/cmd.Version=$(VERSION)' \
|
||||
-ldflags '-X $(MODULE)/helpers.AkvoradoVersion=$(VERSION)' \
|
||||
-o $(BIN)/$(basename $(MODULE)) main.go
|
||||
|
||||
.PHONY: all_js
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/reporter"
|
||||
)
|
||||
|
||||
@@ -33,7 +34,7 @@ func StartStopComponents(r *reporter.Reporter, daemonComponent daemon.Component,
|
||||
}
|
||||
|
||||
r.Info().
|
||||
Str("version", Version).
|
||||
Str("version", helpers.AkvoradoVersion).
|
||||
Msg("akvorado has started")
|
||||
|
||||
<-daemonComponent.Terminated()
|
||||
|
||||
@@ -63,7 +63,6 @@ manage collected flows.`,
|
||||
if err := ConsoleOptions.Parse(cmd.OutOrStdout(), "console", &config); err != nil {
|
||||
return err
|
||||
}
|
||||
config.Console.Version = Version
|
||||
|
||||
r, err := reporter.New(config.Reporting)
|
||||
if err != nil {
|
||||
|
||||
@@ -11,19 +11,13 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"akvorado/common/clickhousedb"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/reporter"
|
||||
"akvorado/common/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version contains the current version.
|
||||
Version = "dev"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(versionCmd)
|
||||
clickhousedb.AkvoradoVersion = Version
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
@@ -31,7 +25,7 @@ var versionCmd = &cobra.Command{
|
||||
Short: "Print version",
|
||||
Long: `Display version and build information about akvorado.`,
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
cmd.Printf("akvorado %s\n", Version)
|
||||
cmd.Printf("akvorado %s\n", helpers.AkvoradoVersion)
|
||||
cmd.Printf(" Built with: %s\n", runtime.Version())
|
||||
cmd.Println()
|
||||
|
||||
@@ -64,7 +58,7 @@ var versionCmd = &cobra.Command{
|
||||
|
||||
func versionHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"version": Version,
|
||||
"version": helpers.AkvoradoVersion,
|
||||
"compiler": runtime.Version(),
|
||||
})
|
||||
}
|
||||
@@ -74,5 +68,5 @@ func versionMetrics(r *reporter.Reporter) {
|
||||
Name: "info",
|
||||
Help: "Akvorado build information",
|
||||
}, []string{"version", "compiler"}).
|
||||
WithLabelValues(Version, runtime.Version()).Set(1)
|
||||
WithLabelValues(helpers.AkvoradoVersion, runtime.Version()).Set(1)
|
||||
}
|
||||
|
||||
@@ -12,12 +12,10 @@ import (
|
||||
"gopkg.in/tomb.v2"
|
||||
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/reporter"
|
||||
)
|
||||
|
||||
// AkvoradoVersion is the current version for Akvorado.
|
||||
var AkvoradoVersion = "dev"
|
||||
|
||||
// Component represents the ClickHouse wrapper
|
||||
type Component struct {
|
||||
r *reporter.Reporter
|
||||
@@ -61,7 +59,7 @@ func New(r *reporter.Reporter, config Configuration, dependencies Dependencies)
|
||||
Name string
|
||||
Version string
|
||||
}{
|
||||
{Name: "akvorado", Version: AkvoradoVersion},
|
||||
{Name: "akvorado", Version: helpers.AkvoradoVersion},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
7
common/helpers/version.go
Normal file
7
common/helpers/version.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2024 Free Mobile
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package helpers
|
||||
|
||||
// AkvoradoVersion contains the current version of Akvorado
|
||||
var AkvoradoVersion = "dev"
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/console/query"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -16,8 +17,6 @@ import (
|
||||
type Configuration struct {
|
||||
// ServeLiveFS serve files from the filesystem instead of the embedded versions.
|
||||
ServeLiveFS bool `yaml:"-"`
|
||||
// Version is the version to display to the user.
|
||||
Version string `yaml:"-"`
|
||||
// DefaultVisualizeOptions define some defaults for the "visualize" tab.
|
||||
DefaultVisualizeOptions VisualizeOptionsConfiguration
|
||||
// HomepageTopWidgets defines the list of widgets to display on the home page.
|
||||
@@ -80,7 +79,7 @@ func (c *Component) configHandlerFunc(gc *gin.Context) {
|
||||
}
|
||||
}
|
||||
gc.JSON(http.StatusOK, gin.H{
|
||||
"version": c.config.Version,
|
||||
"version": helpers.AkvoradoVersion,
|
||||
"defaultVisualizeOptions": c.config.DefaultVisualizeOptions,
|
||||
"dimensionsLimit": c.config.DimensionsLimit,
|
||||
"dimensions": dimensions,
|
||||
|
||||
@@ -13,13 +13,12 @@ import (
|
||||
|
||||
func TestConfigHandler(t *testing.T) {
|
||||
config := DefaultConfiguration()
|
||||
config.Version = "1.2.3"
|
||||
_, h, _, _ := NewMock(t, config)
|
||||
helpers.TestHTTPEndpoints(t, h.LocalAddr(), helpers.HTTPEndpointCases{
|
||||
{
|
||||
URL: "/api/v0/console/configuration",
|
||||
JSONOutput: gin.H{
|
||||
"version": "1.2.3",
|
||||
"version": "dev",
|
||||
"defaultVisualizeOptions": gin.H{
|
||||
"graphType": "stacked",
|
||||
"start": "24 hours ago",
|
||||
|
||||
Reference in New Issue
Block a user