mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-26 02:29:55 +00:00
Compare commits
3 Commits
main
...
feat/dev_v
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c820a3a7f3 | ||
|
|
461f1cd96a | ||
|
|
67e4a13713 |
@@ -12,7 +12,13 @@ var (
|
||||
Short: "Print the NetBird's client application version",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd.SetOut(cmd.OutOrStdout())
|
||||
cmd.Println(version.NetbirdVersion())
|
||||
out := version.NetbirdVersion()
|
||||
if version.IsDevelopmentVersion(out) {
|
||||
if commit := version.NetbirdCommit(); commit != "" {
|
||||
out += "-" + commit
|
||||
}
|
||||
}
|
||||
cmd.Println(out)
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-version"
|
||||
|
||||
nbversion "github.com/netbirdio/netbird/version"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -11,7 +13,7 @@ var (
|
||||
)
|
||||
|
||||
func IsSupported(agentVersion string) bool {
|
||||
if agentVersion == "development" {
|
||||
if nbversion.IsDevelopmentVersion(agentVersion) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import (
|
||||
|
||||
const (
|
||||
latestVersion = "latest"
|
||||
// this version will be ignored
|
||||
developmentVersion = "development"
|
||||
)
|
||||
|
||||
var errNoUpdateState = errors.New("no update state found")
|
||||
@@ -483,7 +481,7 @@ func (m *Manager) loadAndDeleteUpdateState(ctx context.Context) (*UpdateState, e
|
||||
}
|
||||
|
||||
func (m *Manager) shouldUpdate(updateVersion *v.Version, forceUpdate bool) bool {
|
||||
if m.currentVersion == developmentVersion {
|
||||
if version.IsDevelopmentVersion(m.currentVersion) {
|
||||
log.Debugf("skipping auto-update, running development version")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"github.com/netbirdio/netbird/shared/management/proto"
|
||||
"github.com/netbirdio/netbird/shared/management/status"
|
||||
"github.com/netbirdio/netbird/util"
|
||||
"github.com/netbirdio/netbird/version"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
@@ -510,7 +511,7 @@ func computeForwarderPort(peers []*nbpeer.Peer, requiredVersion string) int64 {
|
||||
for _, peer := range peers {
|
||||
|
||||
// Development version is always supported
|
||||
if peer.Meta.WtVersion == "development" {
|
||||
if version.IsDevelopmentVersion(peer.Meta.WtVersion) {
|
||||
continue
|
||||
}
|
||||
peerVersion := semver.Canonical("v" + peer.Meta.WtVersion)
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||
"github.com/netbirdio/netbird/management/server/telemetry"
|
||||
"github.com/netbirdio/netbird/shared/management/status"
|
||||
"github.com/netbirdio/netbird/version"
|
||||
)
|
||||
|
||||
const remoteJobsMinVer = "0.64.0"
|
||||
@@ -372,7 +373,7 @@ func (am *DefaultAccountManager) CreatePeerJob(ctx context.Context, accountID, p
|
||||
}
|
||||
|
||||
meetMinVer, err := posture.MeetsMinVersion(remoteJobsMinVer, p.Meta.WtVersion)
|
||||
if !strings.Contains(p.Meta.WtVersion, "dev") && (!meetMinVer || err != nil) {
|
||||
if !version.IsDevelopmentVersion(p.Meta.WtVersion) && (!meetMinVer || err != nil) {
|
||||
return status.Errorf(status.PreconditionFailed, "peer version %s does not meet the minimum required version %s for remote jobs", p.Meta.WtVersion, remoteJobsMinVer)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/netbirdio/netbird/route"
|
||||
"github.com/netbirdio/netbird/shared/management/domain"
|
||||
"github.com/netbirdio/netbird/shared/management/status"
|
||||
"github.com/netbirdio/netbird/version"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -1804,7 +1805,7 @@ func shouldCheckRulesForNativeSSH(supportsNative bool, rule *PolicyRule, peer *n
|
||||
|
||||
// peerSupportedFirewallFeatures checks if the peer version supports port ranges.
|
||||
func peerSupportedFirewallFeatures(peerVer string) supportedFeatures {
|
||||
if strings.Contains(peerVer, "dev") {
|
||||
if version.IsDevelopmentVersion(peerVer) {
|
||||
return supportedFeatures{true, true}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,75 @@ package version
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
v "github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
// DevelopmentVersion is the value of NetbirdVersion() for non-release builds.
|
||||
// Wire-format consumers (management server, dashboard) match against this
|
||||
// string, so it must not change without coordinating those consumers.
|
||||
const DevelopmentVersion = "development"
|
||||
|
||||
// will be replaced with the release version when using goreleaser
|
||||
var version = "development"
|
||||
var version = DevelopmentVersion
|
||||
|
||||
var (
|
||||
VersionRegexp = regexp.MustCompile("^" + v.VersionRegexpRaw + "$")
|
||||
SemverRegexp = regexp.MustCompile("^" + v.SemverRegexpRaw + "$")
|
||||
)
|
||||
|
||||
// NetbirdVersion returns the Netbird version
|
||||
// NetbirdVersion returns the Netbird version. For non-release builds the
|
||||
// value is the literal DevelopmentVersion constant; the VCS revision is
|
||||
// exposed separately via NetbirdCommit so the wire format stays stable.
|
||||
func NetbirdVersion() string {
|
||||
return version
|
||||
}
|
||||
|
||||
// NetbirdCommit returns the VCS revision (truncated to 12 chars) of the
|
||||
// build, with a "-dirty" suffix when the working tree was modified.
|
||||
// Returns an empty string when no build info is embedded (e.g. release
|
||||
// builds compiled by goreleaser without -buildvcs).
|
||||
func NetbirdCommit() string {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
var revision string
|
||||
var modified bool
|
||||
for _, s := range info.Settings {
|
||||
switch s.Key {
|
||||
case "vcs.revision":
|
||||
revision = s.Value
|
||||
case "vcs.modified":
|
||||
modified = s.Value == "true"
|
||||
}
|
||||
}
|
||||
|
||||
if revision == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(revision) > 12 {
|
||||
revision = revision[:12]
|
||||
}
|
||||
|
||||
if modified {
|
||||
revision += "-dirty"
|
||||
}
|
||||
return revision
|
||||
}
|
||||
|
||||
// IsDevelopmentVersion reports whether the given version string identifies
|
||||
// a non-release / development build. It is the single source of truth for
|
||||
// "is this a dev build" checks across the codebase; use it instead of
|
||||
// comparing against the "development" literal or ad-hoc substring checks.
|
||||
//
|
||||
// Matches the bare DevelopmentVersion constant as well as any future
|
||||
// extension such as "development-<sha>" or "development-<sha>-dirty",
|
||||
// while excluding tagged prereleases like "v0.31.1-dev".
|
||||
func IsDevelopmentVersion(v string) bool {
|
||||
return strings.HasPrefix(v, DevelopmentVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user