diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 06b352348..8abd81cb9 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -25,7 +25,7 @@ builds: - goos: windows goarch: 386 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 }}' tags: - load_wgnt_from_rsrc @@ -47,7 +47,7 @@ builds: - arm64 - arm 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 }}' - id: netbird-signal @@ -61,7 +61,7 @@ builds: - arm64 - arm 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 }}' archives: diff --git a/.goreleaser_ui.yaml b/.goreleaser_ui.yaml index 0b3a94c8f..197eab3f8 100644 --- a/.goreleaser_ui.yaml +++ b/.goreleaser_ui.yaml @@ -10,7 +10,7 @@ builds: goarch: - amd64 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 }}' - id: netbird-ui-windows @@ -24,7 +24,7 @@ builds: goarch: - amd64 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 mod_timestamp: '{{ .CommitTimestamp }}' diff --git a/.goreleaser_ui_darwin.yaml b/.goreleaser_ui_darwin.yaml index 910c9187a..cde09cda1 100644 --- a/.goreleaser_ui_darwin.yaml +++ b/.goreleaser_ui_darwin.yaml @@ -14,7 +14,7 @@ builds: - hardfloat - softfloat 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 }}' tags: - load_wgnt_from_rsrc diff --git a/client/cmd/status.go b/client/cmd/status.go index 5a667e6ee..d090f4dda 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -17,8 +17,8 @@ import ( "github.com/netbirdio/netbird/client/internal" "github.com/netbirdio/netbird/client/internal/peer" "github.com/netbirdio/netbird/client/proto" - "github.com/netbirdio/netbird/client/system" "github.com/netbirdio/netbird/util" + "github.com/netbirdio/netbird/version" ) type peerStateDetailOutput struct { @@ -209,7 +209,7 @@ func convertToStatusOutputOverview(resp *proto.StatusResponse) statusOutputOverv overview := statusOutputOverview{ Peers: peersOverview, - CliVersion: system.NetbirdVersion(), + CliVersion: version.NetbirdVersion(), DaemonVersion: resp.GetDaemonVersion(), ManagementState: managementOverview, SignalState: signalOverview, @@ -345,7 +345,7 @@ func parseGeneralSummary(overview statusOutputOverview, showURL bool) string { "Interface type: %s\n"+ "Peers count: %s\n", overview.DaemonVersion, - system.NetbirdVersion(), + version.NetbirdVersion(), managementConnString, signalConnString, overview.FQDN, diff --git a/client/cmd/status_test.go b/client/cmd/status_test.go index 7281a1f12..c4510b11a 100644 --- a/client/cmd/status_test.go +++ b/client/cmd/status_test.go @@ -8,7 +8,7 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" "github.com/netbirdio/netbird/client/proto" - "github.com/netbirdio/netbird/client/system" + "github.com/netbirdio/netbird/version" ) var resp = &proto.StatusResponse{ @@ -89,7 +89,7 @@ var overview = statusOutputOverview{ }, }, }, - CliVersion: system.NetbirdVersion(), + CliVersion: version.NetbirdVersion(), DaemonVersion: "0.14.1", ManagementState: managementStateOutput{ URL: "my-awesome-management.com:443", diff --git a/client/cmd/version.go b/client/cmd/version.go index 2b432ec5f..99f2da698 100644 --- a/client/cmd/version.go +++ b/client/cmd/version.go @@ -1,8 +1,9 @@ package cmd import ( - "github.com/netbirdio/netbird/client/system" "github.com/spf13/cobra" + + "github.com/netbirdio/netbird/version" ) var ( @@ -11,7 +12,7 @@ var ( Short: "prints Netbird version", Run: func(cmd *cobra.Command, args []string) { cmd.SetOut(cmd.OutOrStdout()) - cmd.Println(system.NetbirdVersion()) + cmd.Println(version.NetbirdVersion()) }, } ) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 1d0e95f59..658b5dd28 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -12,8 +12,8 @@ import ( "golang.zx2c4.com/wireguard/wgctrl" "github.com/netbirdio/netbird/client/internal/proxy" - "github.com/netbirdio/netbird/client/system" "github.com/netbirdio/netbird/iface" + "github.com/netbirdio/netbird/version" ) // ConnConfig is a peer Connection configuration @@ -500,7 +500,7 @@ func (conn *Conn) sendAnswer() error { err = conn.signalAnswer(OfferAnswer{ IceCredentials: IceCredentials{localUFrag, localPwd}, WgListenPort: conn.config.LocalWgPort, - Version: system.NetbirdVersion(), + Version: version.NetbirdVersion(), }) if err != nil { return err @@ -521,7 +521,7 @@ func (conn *Conn) sendOffer() error { err = conn.signalOffer(OfferAnswer{ IceCredentials: IceCredentials{localUFrag, localPwd}, WgListenPort: conn.config.LocalWgPort, - Version: system.NetbirdVersion(), + Version: version.NetbirdVersion(), }) if err != nil { return err diff --git a/client/internal/routemanager/manager.go b/client/internal/routemanager/manager.go index 8b2b04d53..b52d97e97 100644 --- a/client/internal/routemanager/manager.go +++ b/client/internal/routemanager/manager.go @@ -9,9 +9,9 @@ import ( log "github.com/sirupsen/logrus" "github.com/netbirdio/netbird/client/internal/peer" - "github.com/netbirdio/netbird/client/system" "github.com/netbirdio/netbird/iface" "github.com/netbirdio/netbird/route" + "github.com/netbirdio/netbird/version" ) // Manager is a route manager interface @@ -171,7 +171,7 @@ func (m *DefaultManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Ro // we skip this route management if newRoute.Network.Bits() < 7 { 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 } newClientRoutesIDMap[networkID] = append(newClientRoutesIDMap[networkID], newRoute) diff --git a/client/server/server.go b/client/server/server.go index ce326410c..2531dc97e 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -15,7 +15,7 @@ import ( "github.com/netbirdio/netbird/client/internal" "github.com/netbirdio/netbird/client/internal/peer" "github.com/netbirdio/netbird/client/proto" - "github.com/netbirdio/netbird/client/system" + "github.com/netbirdio/netbird/version" ) // Server for service control. @@ -427,7 +427,7 @@ func (s *Server) Status( 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 { s.statusRecorder = peer.NewRecorder() diff --git a/client/system/info.go b/client/system/info.go index 4d85abba6..d948a185f 100644 --- a/client/system/info.go +++ b/client/system/info.go @@ -2,15 +2,14 @@ package system import ( "context" - "google.golang.org/grpc/metadata" "strings" + + "google.golang.org/grpc/metadata" + + "github.com/netbirdio/netbird/version" ) -// this is the wiretrustee version -// will be replaced with the release version when using goreleaser -var version = "development" - -//Info is an object that contains machine information +// Info is an object that contains machine information // Most of the code is taken from https://github.com/matishsiao/goInfo type Info struct { GoOS string @@ -25,11 +24,6 @@ type Info struct { 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 func extractUserAgent(ctx context.Context) string { md, hasMeta := metadata.FromOutgoingContext(ctx) @@ -48,5 +42,5 @@ func extractUserAgent(ctx context.Context) string { // GetDesktopUIUserAgent returns the Desktop ui user agent func GetDesktopUIUserAgent() string { - return "netbird-desktop-ui/" + NetbirdVersion() + return "netbird-desktop-ui/" + version.NetbirdVersion() } diff --git a/client/system/info_darwin.go b/client/system/info_darwin.go index edf4886b6..82e3d94ca 100644 --- a/client/system/info_darwin.go +++ b/client/system/info_darwin.go @@ -4,12 +4,16 @@ import ( "bytes" "context" "fmt" - log "github.com/sirupsen/logrus" - "golang.org/x/sys/unix" "os" "os/exec" "runtime" "strings" + + "golang.org/x/sys/unix" + + log "github.com/sirupsen/logrus" + + "github.com/netbirdio/netbird/version" ) // 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]) machine := string(bytes.Split(utsname.Machine[:], []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 { 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.WiretrusteeVersion = NetbirdVersion() + gio.WiretrusteeVersion = version.NetbirdVersion() gio.UIVersion = extractUserAgent(ctx) return gio diff --git a/client/system/info_freebsd.go b/client/system/info_freebsd.go index a96806d1c..de4537f1d 100644 --- a/client/system/info_freebsd.go +++ b/client/system/info_freebsd.go @@ -9,6 +9,8 @@ import ( "runtime" "strings" "time" + + "github.com/netbirdio/netbird/version" ) // GetInfo retrieves and parses the system information @@ -23,7 +25,7 @@ func GetInfo(ctx context.Context) *Info { 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.Hostname, _ = os.Hostname() - gio.WiretrusteeVersion = NetbirdVersion() + gio.WiretrusteeVersion = version.NetbirdVersion() gio.UIVersion = extractUserAgent(ctx) return gio diff --git a/client/system/info_linux.go b/client/system/info_linux.go index b7c55a65a..e0546cf88 100644 --- a/client/system/info_linux.go +++ b/client/system/info_linux.go @@ -9,6 +9,8 @@ import ( "runtime" "strings" "time" + + "github.com/netbirdio/netbird/version" ) // 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.Hostname, _ = os.Hostname() - gio.WiretrusteeVersion = NetbirdVersion() + gio.WiretrusteeVersion = version.NetbirdVersion() gio.UIVersion = extractUserAgent(ctx) return gio diff --git a/client/system/info_windows.go b/client/system/info_windows.go index 052313a20..b4548a74b 100644 --- a/client/system/info_windows.go +++ b/client/system/info_windows.go @@ -3,10 +3,13 @@ package system import ( "context" "fmt" - log "github.com/sirupsen/logrus" - "golang.org/x/sys/windows/registry" "os" "runtime" + + log "github.com/sirupsen/logrus" + "golang.org/x/sys/windows/registry" + + "github.com/netbirdio/netbird/version" ) // GetInfo retrieves and parses the system information @@ -14,7 +17,7 @@ func GetInfo(ctx context.Context) *Info { ver := getOSVersion() gio := &Info{Kernel: "windows", OSVersion: ver, Core: ver, Platform: "unknown", OS: "windows", GoOS: runtime.GOOS, CPUs: runtime.NumCPU()} gio.Hostname, _ = os.Hostname() - gio.WiretrusteeVersion = NetbirdVersion() + gio.WiretrusteeVersion = version.NetbirdVersion() gio.UIVersion = extractUserAgent(ctx) return gio @@ -32,7 +35,7 @@ func getOSVersion() string { log.Error(deferErr) } }() - + major, _, err := k.GetIntegerValue("CurrentMajorVersionNumber") if err != nil { log.Error(err) diff --git a/client/ui/client_ui.go b/client/ui/client_ui.go index ab6ca0c19..e6b4394e8 100644 --- a/client/ui/client_ui.go +++ b/client/ui/client_ui.go @@ -6,6 +6,7 @@ package main import ( "context" + _ "embed" "flag" "fmt" "os" @@ -17,25 +18,22 @@ import ( "syscall" "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" - - _ "embed" - "github.com/getlantern/systray" - "github.com/netbirdio/netbird/client/internal" - "github.com/netbirdio/netbird/client/proto" log "github.com/sirupsen/logrus" "github.com/skratchdot/open-golang/open" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "fyne.io/fyne/v2" - "fyne.io/fyne/v2/app" - "fyne.io/fyne/v2/dialog" - "fyne.io/fyne/v2/widget" + "github.com/netbirdio/netbird/client/internal" + "github.com/netbirdio/netbird/client/proto" + "github.com/netbirdio/netbird/client/system" + "github.com/netbirdio/netbird/version" ) const ( @@ -373,7 +371,7 @@ func (s *serviceClient) onTrayReady() { systray.AddSeparator() s.mSettings = systray.AddMenuItem("Settings", "Settings of the application") systray.AddSeparator() - v := systray.AddMenuItem("v"+system.NetbirdVersion(), "Client Version: "+system.NetbirdVersion()) + v := systray.AddMenuItem("v"+version.NetbirdVersion(), "Client Version: "+version.NetbirdVersion()) v.Disable() systray.AddSeparator() s.mQuit = systray.AddMenuItem("Quit", "Quit the client app") diff --git a/management/cmd/root.go b/management/cmd/root.go index 6115b1782..5a1c52d31 100644 --- a/management/cmd/root.go +++ b/management/cmd/root.go @@ -2,9 +2,12 @@ package cmd import ( "fmt" - "github.com/spf13/cobra" "os" "os/signal" + + "github.com/spf13/cobra" + + "github.com/netbirdio/netbird/version" ) const ( @@ -25,6 +28,7 @@ var ( Use: "netbird-mgmt", Short: "", Long: "", + Version: version.NetbirdVersion(), SilenceUsage: true, } diff --git a/management/server/metrics/selfhosted.go b/management/server/metrics/selfhosted.go index bea9d05e9..2c7e943ac 100644 --- a/management/server/metrics/selfhosted.go +++ b/management/server/metrics/selfhosted.go @@ -5,16 +5,18 @@ import ( "context" "encoding/json" "fmt" - "github.com/hashicorp/go-version" - "github.com/netbirdio/netbird/client/system" - "github.com/netbirdio/netbird/management/server" - log "github.com/sirupsen/logrus" "io" "net/http" "regexp" "sort" "strings" "time" + + "github.com/hashicorp/go-version" + log "github.com/sirupsen/logrus" + + "github.com/netbirdio/netbird/management/server" + nbversion "github.com/netbirdio/netbird/version" ) const ( @@ -176,7 +178,7 @@ func (w *Worker) generateProperties() properties { osUIClients = make(map[string]int) uptime = time.Since(w.startupTime).Seconds() connections := w.connManager.GetAllConnectedPeers() - version = system.NetbirdVersion() + version = nbversion.NetbirdVersion() for _, account := range w.dataSource.GetAllAccounts() { accounts++ diff --git a/signal/client/client.go b/signal/client/client.go index 9d1ef2cf9..6aa99e4fe 100644 --- a/signal/client/client.go +++ b/signal/client/client.go @@ -2,11 +2,13 @@ package client import ( "fmt" - "github.com/netbirdio/netbird/client/system" - "github.com/netbirdio/netbird/signal/proto" - "golang.zx2c4.com/wireguard/wgctrl/wgtypes" "io" "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. @@ -50,7 +52,7 @@ func MarshalCredential(myKey wgtypes.Key, myPort int, remoteKey wgtypes.Key, cre Type: t, Payload: fmt.Sprintf("%s:%s", credential.UFrag, credential.Pwd), WgListenPort: uint32(myPort), - NetBirdVersion: system.NetbirdVersion(), + NetBirdVersion: version.NetbirdVersion(), }, }, nil } diff --git a/signal/cmd/root.go b/signal/cmd/root.go index cede8d5eb..479579c7e 100644 --- a/signal/cmd/root.go +++ b/signal/cmd/root.go @@ -7,6 +7,8 @@ import ( "runtime" "github.com/spf13/cobra" + + "github.com/netbirdio/netbird/version" ) const ( @@ -20,9 +22,10 @@ var ( logFile string rootCmd = &cobra.Command{ - Use: "netbird-signal", - Short: "", - Long: "", + Use: "netbird-signal", + Short: "", + Long: "", + Version: version.NetbirdVersion(), } // Execution control channel for stopCh signal diff --git a/version/version.go b/version/version.go new file mode 100644 index 000000000..d9c119f90 --- /dev/null +++ b/version/version.go @@ -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 +}