Add version info command to signal server (#739)

Add version command to signal and management servers.

The version information will be filled during build time.
This commit is contained in:
Zoltan Papp 2023-03-15 07:54:51 +01:00 committed by GitHub
parent 2a1efbd0fd
commit 292ee260ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 93 additions and 69 deletions

View File

@ -25,7 +25,7 @@ builds:
- goos: windows - goos: windows
goarch: 386 goarch: 386
ldflags: ldflags:
- -s -w -X github.com/netbirdio/netbird/client/system.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser - -s -w -X github.com/netbirdio/netbird/version.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}' mod_timestamp: '{{ .CommitTimestamp }}'
tags: tags:
- load_wgnt_from_rsrc - load_wgnt_from_rsrc
@ -47,7 +47,7 @@ builds:
- arm64 - arm64
- arm - arm
ldflags: ldflags:
- -s -w -X github.com/netbirdio/netbird/client/system.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser - -s -w -X github.com/netbirdio/netbird/version.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}' mod_timestamp: '{{ .CommitTimestamp }}'
- id: netbird-signal - id: netbird-signal
@ -61,7 +61,7 @@ builds:
- arm64 - arm64
- arm - arm
ldflags: ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser - -s -w -X github.com/netbirdio/netbird/version.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}' mod_timestamp: '{{ .CommitTimestamp }}'
archives: archives:

View File

@ -10,7 +10,7 @@ builds:
goarch: goarch:
- amd64 - amd64
ldflags: ldflags:
- -s -w -X github.com/netbirdio/netbird/client/system.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser - -s -w -X github.com/netbirdio/netbird/version.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}' mod_timestamp: '{{ .CommitTimestamp }}'
- id: netbird-ui-windows - id: netbird-ui-windows
@ -24,7 +24,7 @@ builds:
goarch: goarch:
- amd64 - amd64
ldflags: ldflags:
- -s -w -X github.com/netbirdio/netbird/client/system.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser - -s -w -X github.com/netbirdio/netbird/version.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
- -H windowsgui - -H windowsgui
mod_timestamp: '{{ .CommitTimestamp }}' mod_timestamp: '{{ .CommitTimestamp }}'

View File

@ -14,7 +14,7 @@ builds:
- hardfloat - hardfloat
- softfloat - softfloat
ldflags: ldflags:
- -s -w -X github.com/netbirdio/netbird/client/system.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser - -s -w -X github.com/netbirdio/netbird/version.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser
mod_timestamp: '{{ .CommitTimestamp }}' mod_timestamp: '{{ .CommitTimestamp }}'
tags: tags:
- load_wgnt_from_rsrc - load_wgnt_from_rsrc

View File

@ -17,8 +17,8 @@ import (
"github.com/netbirdio/netbird/client/internal" "github.com/netbirdio/netbird/client/internal"
"github.com/netbirdio/netbird/client/internal/peer" "github.com/netbirdio/netbird/client/internal/peer"
"github.com/netbirdio/netbird/client/proto" "github.com/netbirdio/netbird/client/proto"
"github.com/netbirdio/netbird/client/system"
"github.com/netbirdio/netbird/util" "github.com/netbirdio/netbird/util"
"github.com/netbirdio/netbird/version"
) )
type peerStateDetailOutput struct { type peerStateDetailOutput struct {
@ -209,7 +209,7 @@ func convertToStatusOutputOverview(resp *proto.StatusResponse) statusOutputOverv
overview := statusOutputOverview{ overview := statusOutputOverview{
Peers: peersOverview, Peers: peersOverview,
CliVersion: system.NetbirdVersion(), CliVersion: version.NetbirdVersion(),
DaemonVersion: resp.GetDaemonVersion(), DaemonVersion: resp.GetDaemonVersion(),
ManagementState: managementOverview, ManagementState: managementOverview,
SignalState: signalOverview, SignalState: signalOverview,
@ -345,7 +345,7 @@ func parseGeneralSummary(overview statusOutputOverview, showURL bool) string {
"Interface type: %s\n"+ "Interface type: %s\n"+
"Peers count: %s\n", "Peers count: %s\n",
overview.DaemonVersion, overview.DaemonVersion,
system.NetbirdVersion(), version.NetbirdVersion(),
managementConnString, managementConnString,
signalConnString, signalConnString,
overview.FQDN, overview.FQDN,

View File

@ -8,7 +8,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
"github.com/netbirdio/netbird/client/proto" "github.com/netbirdio/netbird/client/proto"
"github.com/netbirdio/netbird/client/system" "github.com/netbirdio/netbird/version"
) )
var resp = &proto.StatusResponse{ var resp = &proto.StatusResponse{
@ -89,7 +89,7 @@ var overview = statusOutputOverview{
}, },
}, },
}, },
CliVersion: system.NetbirdVersion(), CliVersion: version.NetbirdVersion(),
DaemonVersion: "0.14.1", DaemonVersion: "0.14.1",
ManagementState: managementStateOutput{ ManagementState: managementStateOutput{
URL: "my-awesome-management.com:443", URL: "my-awesome-management.com:443",

View File

@ -1,8 +1,9 @@
package cmd package cmd
import ( import (
"github.com/netbirdio/netbird/client/system"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/netbirdio/netbird/version"
) )
var ( var (
@ -11,7 +12,7 @@ var (
Short: "prints Netbird version", Short: "prints Netbird version",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cmd.SetOut(cmd.OutOrStdout()) cmd.SetOut(cmd.OutOrStdout())
cmd.Println(system.NetbirdVersion()) cmd.Println(version.NetbirdVersion())
}, },
} }
) )

View File

@ -12,8 +12,8 @@ import (
"golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl"
"github.com/netbirdio/netbird/client/internal/proxy" "github.com/netbirdio/netbird/client/internal/proxy"
"github.com/netbirdio/netbird/client/system"
"github.com/netbirdio/netbird/iface" "github.com/netbirdio/netbird/iface"
"github.com/netbirdio/netbird/version"
) )
// ConnConfig is a peer Connection configuration // ConnConfig is a peer Connection configuration
@ -500,7 +500,7 @@ func (conn *Conn) sendAnswer() error {
err = conn.signalAnswer(OfferAnswer{ err = conn.signalAnswer(OfferAnswer{
IceCredentials: IceCredentials{localUFrag, localPwd}, IceCredentials: IceCredentials{localUFrag, localPwd},
WgListenPort: conn.config.LocalWgPort, WgListenPort: conn.config.LocalWgPort,
Version: system.NetbirdVersion(), Version: version.NetbirdVersion(),
}) })
if err != nil { if err != nil {
return err return err
@ -521,7 +521,7 @@ func (conn *Conn) sendOffer() error {
err = conn.signalOffer(OfferAnswer{ err = conn.signalOffer(OfferAnswer{
IceCredentials: IceCredentials{localUFrag, localPwd}, IceCredentials: IceCredentials{localUFrag, localPwd},
WgListenPort: conn.config.LocalWgPort, WgListenPort: conn.config.LocalWgPort,
Version: system.NetbirdVersion(), Version: version.NetbirdVersion(),
}) })
if err != nil { if err != nil {
return err return err

View File

@ -9,9 +9,9 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/netbirdio/netbird/client/internal/peer" "github.com/netbirdio/netbird/client/internal/peer"
"github.com/netbirdio/netbird/client/system"
"github.com/netbirdio/netbird/iface" "github.com/netbirdio/netbird/iface"
"github.com/netbirdio/netbird/route" "github.com/netbirdio/netbird/route"
"github.com/netbirdio/netbird/version"
) )
// Manager is a route manager interface // Manager is a route manager interface
@ -171,7 +171,7 @@ func (m *DefaultManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Ro
// we skip this route management // we skip this route management
if newRoute.Network.Bits() < 7 { if newRoute.Network.Bits() < 7 {
log.Errorf("this agent version: %s, doesn't support default routes, received %s, skiping this route", log.Errorf("this agent version: %s, doesn't support default routes, received %s, skiping this route",
system.NetbirdVersion(), newRoute.Network) version.NetbirdVersion(), newRoute.Network)
continue continue
} }
newClientRoutesIDMap[networkID] = append(newClientRoutesIDMap[networkID], newRoute) newClientRoutesIDMap[networkID] = append(newClientRoutesIDMap[networkID], newRoute)

View File

@ -15,7 +15,7 @@ import (
"github.com/netbirdio/netbird/client/internal" "github.com/netbirdio/netbird/client/internal"
"github.com/netbirdio/netbird/client/internal/peer" "github.com/netbirdio/netbird/client/internal/peer"
"github.com/netbirdio/netbird/client/proto" "github.com/netbirdio/netbird/client/proto"
"github.com/netbirdio/netbird/client/system" "github.com/netbirdio/netbird/version"
) )
// Server for service control. // Server for service control.
@ -427,7 +427,7 @@ func (s *Server) Status(
return nil, err return nil, err
} }
statusResponse := proto.StatusResponse{Status: string(status), DaemonVersion: system.NetbirdVersion()} statusResponse := proto.StatusResponse{Status: string(status), DaemonVersion: version.NetbirdVersion()}
if s.statusRecorder == nil { if s.statusRecorder == nil {
s.statusRecorder = peer.NewRecorder() s.statusRecorder = peer.NewRecorder()

View File

@ -2,15 +2,14 @@ package system
import ( import (
"context" "context"
"google.golang.org/grpc/metadata"
"strings" "strings"
"google.golang.org/grpc/metadata"
"github.com/netbirdio/netbird/version"
) )
// this is the wiretrustee version // Info is an object that contains machine information
// will be replaced with the release version when using goreleaser
var version = "development"
//Info is an object that contains machine information
// Most of the code is taken from https://github.com/matishsiao/goInfo // Most of the code is taken from https://github.com/matishsiao/goInfo
type Info struct { type Info struct {
GoOS string GoOS string
@ -25,11 +24,6 @@ type Info struct {
UIVersion string UIVersion string
} }
// NetbirdVersion returns the Netbird version
func NetbirdVersion() string {
return version
}
// extractUserAgent extracts Netbird's agent (client) name and version from the outgoing context // extractUserAgent extracts Netbird's agent (client) name and version from the outgoing context
func extractUserAgent(ctx context.Context) string { func extractUserAgent(ctx context.Context) string {
md, hasMeta := metadata.FromOutgoingContext(ctx) md, hasMeta := metadata.FromOutgoingContext(ctx)
@ -48,5 +42,5 @@ func extractUserAgent(ctx context.Context) string {
// GetDesktopUIUserAgent returns the Desktop ui user agent // GetDesktopUIUserAgent returns the Desktop ui user agent
func GetDesktopUIUserAgent() string { func GetDesktopUIUserAgent() string {
return "netbird-desktop-ui/" + NetbirdVersion() return "netbird-desktop-ui/" + version.NetbirdVersion()
} }

View File

@ -4,12 +4,16 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
"strings" "strings"
"golang.org/x/sys/unix"
log "github.com/sirupsen/logrus"
"github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information // GetInfo retrieves and parses the system information
@ -22,14 +26,14 @@ func GetInfo(ctx context.Context) *Info {
sysName := string(bytes.Split(utsname.Sysname[:], []byte{0})[0]) sysName := string(bytes.Split(utsname.Sysname[:], []byte{0})[0])
machine := string(bytes.Split(utsname.Machine[:], []byte{0})[0]) machine := string(bytes.Split(utsname.Machine[:], []byte{0})[0])
release := string(bytes.Split(utsname.Release[:], []byte{0})[0]) release := string(bytes.Split(utsname.Release[:], []byte{0})[0])
version, err := exec.Command("sw_vers", "-productVersion").Output() swVersion, err := exec.Command("sw_vers", "-productVersion").Output()
if err != nil { if err != nil {
log.Warnf("got an error while retrieving macOS version with sw_vers, error: %s. Using darwin version instead.\n", err) log.Warnf("got an error while retrieving macOS version with sw_vers, error: %s. Using darwin version instead.\n", err)
version = []byte(release) swVersion = []byte(release)
} }
gio := &Info{Kernel: sysName, OSVersion: strings.TrimSpace(string(version)), Core: release, Platform: machine, OS: sysName, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()} gio := &Info{Kernel: sysName, OSVersion: strings.TrimSpace(string(swVersion)), Core: release, Platform: machine, OS: sysName, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname() gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = NetbirdVersion() gio.WiretrusteeVersion = version.NetbirdVersion()
gio.UIVersion = extractUserAgent(ctx) gio.UIVersion = extractUserAgent(ctx)
return gio return gio

View File

@ -9,6 +9,8 @@ import (
"runtime" "runtime"
"strings" "strings"
"time" "time"
"github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information // GetInfo retrieves and parses the system information
@ -23,7 +25,7 @@ func GetInfo(ctx context.Context) *Info {
osInfo := strings.Split(osStr, " ") osInfo := strings.Split(osStr, " ")
gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU()} gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: runtime.GOARCH, OS: osInfo[2], GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname() gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = NetbirdVersion() gio.WiretrusteeVersion = version.NetbirdVersion()
gio.UIVersion = extractUserAgent(ctx) gio.UIVersion = extractUserAgent(ctx)
return gio return gio

View File

@ -9,6 +9,8 @@ import (
"runtime" "runtime"
"strings" "strings"
"time" "time"
"github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information // GetInfo retrieves and parses the system information
@ -46,7 +48,7 @@ func GetInfo(ctx context.Context) *Info {
} }
gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: osInfo[2], OS: osName, OSVersion: osVer, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()} gio := &Info{Kernel: osInfo[0], Core: osInfo[1], Platform: osInfo[2], OS: osName, OSVersion: osVer, GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname() gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = NetbirdVersion() gio.WiretrusteeVersion = version.NetbirdVersion()
gio.UIVersion = extractUserAgent(ctx) gio.UIVersion = extractUserAgent(ctx)
return gio return gio

View File

@ -3,10 +3,13 @@ package system
import ( import (
"context" "context"
"fmt" "fmt"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows/registry"
"os" "os"
"runtime" "runtime"
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows/registry"
"github.com/netbirdio/netbird/version"
) )
// GetInfo retrieves and parses the system information // GetInfo retrieves and parses the system information
@ -14,7 +17,7 @@ func GetInfo(ctx context.Context) *Info {
ver := getOSVersion() ver := getOSVersion()
gio := &Info{Kernel: "windows", OSVersion: ver, Core: ver, Platform: "unknown", OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()} gio := &Info{Kernel: "windows", OSVersion: ver, Core: ver, Platform: "unknown", OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()}
gio.Hostname, _ = os.Hostname() gio.Hostname, _ = os.Hostname()
gio.WiretrusteeVersion = NetbirdVersion() gio.WiretrusteeVersion = version.NetbirdVersion()
gio.UIVersion = extractUserAgent(ctx) gio.UIVersion = extractUserAgent(ctx)
return gio return gio

View File

@ -6,6 +6,7 @@ package main
import ( import (
"context" "context"
_ "embed"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -17,25 +18,22 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/netbirdio/netbird/client/system" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"github.com/cenkalti/backoff/v4" "github.com/cenkalti/backoff/v4"
_ "embed"
"github.com/getlantern/systray" "github.com/getlantern/systray"
"github.com/netbirdio/netbird/client/internal"
"github.com/netbirdio/netbird/client/proto"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/skratchdot/open-golang/open" "github.com/skratchdot/open-golang/open"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
"fyne.io/fyne/v2" "github.com/netbirdio/netbird/client/internal"
"fyne.io/fyne/v2/app" "github.com/netbirdio/netbird/client/proto"
"fyne.io/fyne/v2/dialog" "github.com/netbirdio/netbird/client/system"
"fyne.io/fyne/v2/widget" "github.com/netbirdio/netbird/version"
) )
const ( const (
@ -373,7 +371,7 @@ func (s *serviceClient) onTrayReady() {
systray.AddSeparator() systray.AddSeparator()
s.mSettings = systray.AddMenuItem("Settings", "Settings of the application") s.mSettings = systray.AddMenuItem("Settings", "Settings of the application")
systray.AddSeparator() systray.AddSeparator()
v := systray.AddMenuItem("v"+system.NetbirdVersion(), "Client Version: "+system.NetbirdVersion()) v := systray.AddMenuItem("v"+version.NetbirdVersion(), "Client Version: "+version.NetbirdVersion())
v.Disable() v.Disable()
systray.AddSeparator() systray.AddSeparator()
s.mQuit = systray.AddMenuItem("Quit", "Quit the client app") s.mQuit = systray.AddMenuItem("Quit", "Quit the client app")

View File

@ -2,9 +2,12 @@ package cmd
import ( import (
"fmt" "fmt"
"github.com/spf13/cobra"
"os" "os"
"os/signal" "os/signal"
"github.com/spf13/cobra"
"github.com/netbirdio/netbird/version"
) )
const ( const (
@ -25,6 +28,7 @@ var (
Use: "netbird-mgmt", Use: "netbird-mgmt",
Short: "", Short: "",
Long: "", Long: "",
Version: version.NetbirdVersion(),
SilenceUsage: true, SilenceUsage: true,
} }

View File

@ -5,16 +5,18 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/hashicorp/go-version"
"github.com/netbirdio/netbird/client/system"
"github.com/netbirdio/netbird/management/server"
log "github.com/sirupsen/logrus"
"io" "io"
"net/http" "net/http"
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"time" "time"
"github.com/hashicorp/go-version"
log "github.com/sirupsen/logrus"
"github.com/netbirdio/netbird/management/server"
nbversion "github.com/netbirdio/netbird/version"
) )
const ( const (
@ -176,7 +178,7 @@ func (w *Worker) generateProperties() properties {
osUIClients = make(map[string]int) osUIClients = make(map[string]int)
uptime = time.Since(w.startupTime).Seconds() uptime = time.Since(w.startupTime).Seconds()
connections := w.connManager.GetAllConnectedPeers() connections := w.connManager.GetAllConnectedPeers()
version = system.NetbirdVersion() version = nbversion.NetbirdVersion()
for _, account := range w.dataSource.GetAllAccounts() { for _, account := range w.dataSource.GetAllAccounts() {
accounts++ accounts++

View File

@ -2,11 +2,13 @@ package client
import ( import (
"fmt" "fmt"
"github.com/netbirdio/netbird/client/system"
"github.com/netbirdio/netbird/signal/proto"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"io" "io"
"strings" "strings"
"github.com/netbirdio/netbird/signal/proto"
"github.com/netbirdio/netbird/version"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
) )
// A set of tools to exchange connection details (Wireguard endpoints) with the remote peer. // A set of tools to exchange connection details (Wireguard endpoints) with the remote peer.
@ -50,7 +52,7 @@ func MarshalCredential(myKey wgtypes.Key, myPort int, remoteKey wgtypes.Key, cre
Type: t, Type: t,
Payload: fmt.Sprintf("%s:%s", credential.UFrag, credential.Pwd), Payload: fmt.Sprintf("%s:%s", credential.UFrag, credential.Pwd),
WgListenPort: uint32(myPort), WgListenPort: uint32(myPort),
NetBirdVersion: system.NetbirdVersion(), NetBirdVersion: version.NetbirdVersion(),
}, },
}, nil }, nil
} }

View File

@ -7,6 +7,8 @@ import (
"runtime" "runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/netbirdio/netbird/version"
) )
const ( const (
@ -23,6 +25,7 @@ var (
Use: "netbird-signal", Use: "netbird-signal",
Short: "", Short: "",
Long: "", Long: "",
Version: version.NetbirdVersion(),
} }
// Execution control channel for stopCh signal // Execution control channel for stopCh signal

9
version/version.go Normal file
View File

@ -0,0 +1,9 @@
package version
// will be replaced with the release version when using goreleaser
var version = "development"
// NetbirdVersion returns the Netbird version
func NetbirdVersion() string {
return version
}