Browse Source

adding OS and Version

afeiszli 3 years ago
parent
commit
9400209d97

+ 2 - 1
controllers/node_grpc.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"errors"
+	"log"
 	"time"
 
 	"github.com/gravitl/netmaker/functions"
@@ -62,7 +63,7 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.Object)
 	if err != nil {
 		return nil, err
 	}
-
+	log.Println("DELETE ME: Operating System = " + node.OS)
 	if !validKey {
 		if node.NetworkSettings.AllowManualSignUp == "yes" {
 			node.IsPending = "yes"

+ 1 - 1
models/node.go

@@ -46,7 +46,7 @@ type Node struct {
 	ExpirationDateTime  int64    `json:"expdatetime" bson:"expdatetime" yaml:"expdatetime"`
 	LastPeerUpdate      int64    `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
 	LastCheckIn         int64    `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
-	MacAddress          string   `json:"macaddress" bson:"macaddress" yaml:"macaddress"`
+	MacAddress          string   `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"macaddress_unique"`
 	// checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL
 	CheckInInterval     int32       `json:"checkininterval" bson:"checkininterval" yaml:"checkininterval"`
 	Password            string      `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`

+ 4 - 2
netclient/functions/daemon.go

@@ -120,7 +120,6 @@ func MessageQueue(ctx context.Context, network string) {
 	ncutils.Log("netclient go routine started for " + network)
 	var cfg config.ClientConfig
 	cfg.Network = network
-	ncutils.Log("pulling latest config for " + cfg.Network)
 	var configPath = fmt.Sprintf("%snetconfig-%s", ncutils.GetNetclientPathSpecific(), network)
 	fileInfo, err := os.Stat(configPath)
 	if err != nil {
@@ -129,10 +128,13 @@ func MessageQueue(ctx context.Context, network string) {
 	// speed up UDP rest
 	if time.Now().After(fileInfo.ModTime().Add(time.Minute)) {
 		sleepTime := 2
+		ncutils.Log("pulling latest config for " + cfg.Network)
 		for {
 			_, err := Pull(network, true)
 			if err == nil {
 				break
+			} else {
+				ncutils.PrintLog("error pulling config for "+network+": "+err.Error(), 1)
 			}
 			if sleepTime > 3600 {
 				sleepTime = 3600
@@ -511,7 +513,7 @@ func PublishNodeUpdate(cfg *config.ClientConfig) {
 
 // Hello -- ping the broker to let server know node is alive and doing fine
 func Hello(cfg *config.ClientConfig, network string) {
-	if err := publish(cfg, fmt.Sprintf("ping/%s", cfg.Node.ID), []byte("hello world!")); err != nil {
+	if err := publish(cfg, fmt.Sprintf("ping/%s", cfg.Node.ID), []byte(ncutils.Version)); err != nil {
 		ncutils.Log(fmt.Sprintf("error publishing ping, %v", err))
 		ncutils.Log("running pull on " + cfg.Node.Network + " to reconnect")
 		_, err := Pull(cfg.Node.Network, true)

+ 3 - 1
netclient/functions/join.go

@@ -145,6 +145,8 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
 		SaveConfig:          cfg.Node.SaveConfig,
 		UDPHolePunch:        cfg.Node.UDPHolePunch,
 		TrafficKeys:         cfg.Node.TrafficKeys,
+		OS:                  runtime.GOOS,
+		Version:             ncutils.Version,
 	}
 
 	ncutils.Log("joining " + cfg.Network + " at " + cfg.Server.GRPCAddress)
@@ -210,7 +212,7 @@ func JoinNetwork(cfg config.ClientConfig, privateKey string) error {
 	if err = json.Unmarshal([]byte(nodeData), &node); err != nil {
 		return err
 	}
-	node.OS = runtime.GOOS
+
 	cfg.Node = node
 	err = config.ModConfig(&node)
 	if err != nil {

+ 1 - 1
netclient/main.go

@@ -17,7 +17,7 @@ func main() {
 	app := cli.NewApp()
 	app.Name = "Netclient CLI"
 	app.Usage = "Netmaker's netclient agent and CLI. Used to perform interactions with Netmaker server and set local WireGuard config."
-	app.Version = "v0.10.0"
+	app.Version = ncutils.Version
 
 	cliFlags := cli_options.GetFlags(ncutils.GetHostname())
 	app.Commands = cli_options.GetCommands(cliFlags[:])

+ 3 - 0
netclient/ncutils/netclientutils.go

@@ -29,6 +29,9 @@ import (
 	"google.golang.org/grpc/credentials"
 )
 
+// Version - version of the netclient
+var Version = "dev"
+
 // MAX_NAME_LENGTH - maximum node name length
 const MAX_NAME_LENGTH = 62
 

+ 18 - 12
scripts/build-binaries.sh

@@ -1,14 +1,20 @@
 #!/bin/bash
+
+#server build
+env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-X 'github.com/gravitl/netmaker/servercfg/serverconf.Version=$VERSION'" -o netclient/build/netmaker main.go
+
 cd netclient
-env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/netclient main.go
-env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -o build/netclient-arm5 main.go
-env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o build/netclient-arm6 main.go
-env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -o build/netclient-arm7 main.go
-env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o build/netclient-arm64 main.go
-env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w" -o build/netclient-mipsle main.go && upx build/netclient-mipsle
-env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o build/netclient-freebsd main.go
-env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=5 go build -o build/netclient-freebsd-arm5 main.go
-env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=6 go build -o build/netclient-freebsd-arm6 main.go
-env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=7 go build -o build/netclient-freebsd-arm7 main.go
-env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o build/netclient-freebsd-arm64 main.go
-env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o build/netclient-darwmin main.go
+
+#client build
+env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient main.go
+env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-arm5 main.go
+env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-arm6 main.go
+env CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-arm7 main.go
+env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-arm64 main.go
+env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags "-s -w -X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-mipsle main.go && upx build/netclient-mipsle
+env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build  -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-freebsd main.go
+env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=5 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-freebsd-arm5 main.go
+env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=6 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-freebsd-arm6 main.go
+env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm GOARM=7 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-freebsd-arm7 main.go
+env CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-freebsd-arm64 main.go
+env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'github.com/gravitl/netmaker/netclient/ncutils/netclientutils.Version=$VERSION'" -o build/netclient-darwin main.go

+ 3 - 5
servercfg/serverconf.go

@@ -12,6 +12,8 @@ import (
 	"github.com/gravitl/netmaker/config"
 )
 
+var Version = "dev"
+
 // SetHost - sets the host ip
 func SetHost() error {
 	remoteip, err := GetPublicIP()
@@ -118,11 +120,7 @@ func GetAPIConnString() string {
 
 // GetVersion - version of netmaker
 func GetVersion() string {
-	version := "0.10.0"
-	if config.Config.Server.Version != "" {
-		version = config.Config.Server.Version
-	}
-	return version
+	return Version
 }
 
 // GetDB - gets the database type