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