Explorar el Código

fix merge conflict

nallux hace 2 años
padre
commit
e2916448f8

+ 36 - 49
broadcast/broadcast.go

@@ -9,9 +9,7 @@ import (
 	"goseg/structs"
 	"log/slog"
 	"math"
-	"io/ioutil"
 	"os"
-	"path/filepath"
 	"reflect"
 	"strings"
 	"sync"
@@ -93,7 +91,7 @@ func bootstrapBroadcastState(config structs.SysConfig) (structs.AuthBroadcast, e
 					},
 				},
 			},
-		}		
+		}
 		err := UpdateBroadcastState(updates)
 		if err != nil {
 			errmsg := fmt.Sprintf("Error updating broadcast state:", err)
@@ -123,8 +121,9 @@ func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
 	}
 	// convert the running status into bools
 	for pier, status := range pierStatus {
+		// pull urbit info from json
+		dockerConfig := docker.Conf(pier)
 		// pull docker info from json
-		var dockerConfig structs.UrbitDocker
 		var dockerStats structs.ContainerStats
 		dockerStats, err := docker.GetContainerStats(pier)
 		if err != nil {
@@ -132,18 +131,6 @@ func constructPierInfo(piers []string) (map[string]structs.Urbit, error) {
 			logger.Error(errmsg)
 			continue
 		}
-		confPath := filepath.Join(config.BasePath, "settings", "pier", pier+".json")
-		file, err := ioutil.ReadFile(confPath)
-		if err != nil {
-			errmsg := fmt.Sprintf("Unable to load %s config: %v", pier, err)
-			logger.Error(errmsg)
-			continue
-		}
-		if err := json.Unmarshal(file, &dockerConfig); err != nil {
-			errmsg := fmt.Sprintf("Error decoding %s JSON: %v", pier, err)
-			logger.Error(errmsg)
-			continue
-		}
 		urbit := structs.Urbit{}
 		if existingUrbit, exists := currentState.Urbits[pier]; exists {
 			// If the ship already exists in broadcastState, use its current state
@@ -180,7 +167,7 @@ func GetContainerNetworks(containers []string) map[string]string {
 	for _, container := range containers {
 		network, err := docker.GetContainerNetwork(container)
 		if err != nil {
-			errmsg := fmt.Sprintf("Error getting container network: %v",err)
+			errmsg := fmt.Sprintf("Error getting container network: %v", err)
 			logger.Error(errmsg)
 			continue
 		} else {
@@ -207,17 +194,17 @@ func UpdateBroadcastState(values map[string]interface{}) error {
 		if err := recursiveUpdate(field, val); err != nil {
 			return err
 		}
-	}	
+	}
 	BroadcastToClients()
 	return nil
 }
 
 // this allows us to insert stuff into nested structs/keys and not overwrite the existing contents
 func recursiveUpdate(dst, src reflect.Value) error {
-    if !dst.CanSet() {
-        return fmt.Errorf("field is not settable")
-    }
-    // If dst is a struct and src is a map, handle them field by field
+	if !dst.CanSet() {
+		return fmt.Errorf("field is not settable")
+	}
+	// If dst is a struct and src is a map, handle them field by field
 	if dst.Kind() == reflect.Struct && src.Kind() == reflect.Map {
 		for _, key := range src.MapKeys() {
 			dstField := dst.FieldByName(key.String())
@@ -241,33 +228,33 @@ func recursiveUpdate(dst, src reflect.Value) error {
 		}
 		return nil
 	}
-    // If both dst and src are maps, handle them recursively
-    if dst.Kind() == reflect.Map && src.Kind() == reflect.Map {
-        for _, key := range src.MapKeys() {
-            srcVal := src.MapIndex(key)
-            // If the key doesn't exist in dst, initialize it
-            dstVal := dst.MapIndex(key)
-            if !dstVal.IsValid() {
-                dstVal = reflect.New(dst.Type().Elem()).Elem()
-            }
-            // Recursive call to handle potential nested maps or structs
-            if err := recursiveUpdate(dstVal, srcVal); err != nil {
-                return err
-            }
-            // Initialize the map if it's nil
-            if dst.IsNil() {
-                dst.Set(reflect.MakeMap(dst.Type()))
-            }
-            dst.SetMapIndex(key, dstVal)
-        }
-        return nil
-    }
-    // For non-map or non-struct fields, or for direct updates
-    if dst.Type() != src.Type() {
-        return fmt.Errorf("type mismatch: expected %s, got %s", dst.Type(), src.Type())
-    }
-    dst.Set(src)
-    return nil
+	// If both dst and src are maps, handle them recursively
+	if dst.Kind() == reflect.Map && src.Kind() == reflect.Map {
+		for _, key := range src.MapKeys() {
+			srcVal := src.MapIndex(key)
+			// If the key doesn't exist in dst, initialize it
+			dstVal := dst.MapIndex(key)
+			if !dstVal.IsValid() {
+				dstVal = reflect.New(dst.Type().Elem()).Elem()
+			}
+			// Recursive call to handle potential nested maps or structs
+			if err := recursiveUpdate(dstVal, srcVal); err != nil {
+				return err
+			}
+			// Initialize the map if it's nil
+			if dst.IsNil() {
+				dst.Set(reflect.MakeMap(dst.Type()))
+			}
+			dst.SetMapIndex(key, dstVal)
+		}
+		return nil
+	}
+	// For non-map or non-struct fields, or for direct updates
+	if dst.Type() != src.Type() {
+		return fmt.Errorf("type mismatch: expected %s, got %s", dst.Type(), src.Type())
+	}
+	dst.Set(src)
+	return nil
 }
 
 // return broadcast state

+ 52 - 1
docker/urbit.go

@@ -1,9 +1,60 @@
 package docker
 
+import (
+	"encoding/json"
+	"fmt"
+	"goseg/config"
+	"goseg/structs"
+	"io/ioutil"
+	"path/filepath"
+	"sync"
+)
+
+var (
+	urbitsConfig = make(map[string]structs.UrbitDocker)
+	urbitMutex   sync.RWMutex
+)
+
 func LoadUrbits() error {
 	logger.Info("Loading Urbit ships")
-	// load config from each pier
+	// Config struct
+	conf := config.Conf()
+	// Loop through pier list
+	for _, pier := range conf.Piers {
+		// load config
+		if err := loadConfig(pier); err != nil {
+			logger.Error(fmt.Sprintf("%v", err))
+			continue
+		}
+	}
 	// apply latest version info (if automated updates)
 	// start containers
 	return nil
 }
+
+func Conf(pier string) structs.UrbitDocker {
+	urbitMutex.Lock()
+	defer urbitMutex.Unlock()
+	return urbitsConfig[pier]
+}
+
+func loadConfig(pier string) error {
+	urbitMutex.Lock()
+	defer urbitMutex.Unlock()
+	// pull docker info from json
+	confPath := filepath.Join(config.BasePath, "settings", "pier", pier+".json")
+	file, err := ioutil.ReadFile(confPath)
+	if err != nil {
+		errmsg := fmt.Sprintf("Unable to load %s config: %v", pier, err)
+		return fmt.Errorf(errmsg) // Return an error instead of a string
+	}
+	// Unmarshal JSON
+	var targetStruct structs.UrbitDocker
+	if err := json.Unmarshal(file, &targetStruct); err != nil {
+		errmsg := fmt.Sprintf("Error decoding %s JSON: %v", pier, err)
+		return fmt.Errorf(errmsg)
+	}
+	// Store in var
+	urbitsConfig[pier] = targetStruct
+	return nil
+}

+ 32 - 0
settings/pier/bilder-nallux-dozryl.json

@@ -0,0 +1,32 @@
+{
+    "pier_name": "bilder-nallux-dozryl",
+    "http_port": 8090,
+    "ames_port": 34353,
+    "loom_size": 31,
+    "urbit_version": "v2.11",
+    "minio_version": "latest",
+    "urbit_repo": "registry.hub.docker.com/nativeplanet/urbit",
+    "minio_repo": "registry.hub.docker.com/minio/minio",
+    "urbit_amd64_sha256": "7dc0a1f97214101482d9c329a5108471bcf23fafea421e1ae2662c6c20377037",
+    "urbit_arm64_sha256": "1dbded539bd99cd789bfe5cbe11bb89baa598e213881389e8138da8fc0a27fa9",
+    "minio_amd64_sha256": "f6a3001a765dc59a8e365149ade0ea628494230e984891877ead016eb24ba9a9",
+    "minio_arm64_sha256": "567779c9f29aca670f84d066051290faeaae6c3ad3a3b7062de4936aaab2a29d",
+    "minio_password": "",
+    "network": "none",
+    "wg_url": "bilder-nallux-dozryl.nativeplanet.live",
+    "wg_http_port": "null",
+    "wg_ames_port": "null",
+    "wg_s3_port": "null",
+    "wg_console_port": "null",
+    "meld_schedule": false,
+    "meld_frequency": 7,
+    "meld_time": "0000",
+    "meld_last": "0",
+    "meld_next": "0",
+    "boot_status": "boot",
+    "custom_urbit_web": "",
+    "custom_s3_web": "",
+    "show_urbit_web": "default",
+    "dev_mode": false,
+    "click": true
+}

+ 32 - 0
settings/pier/hocfur-wicnym-nallux-dozryl.json

@@ -0,0 +1,32 @@
+{
+    "pier_name": "hocfur-wicnym-nallux-dozryl",
+    "http_port": 8083,
+    "ames_port": 34346,
+    "loom_size": 31,
+    "urbit_version": "v2.11",
+    "minio_version": "latest",
+    "urbit_repo": "registry.hub.docker.com/nativeplanet/urbit",
+    "minio_repo": "registry.hub.docker.com/minio/minio",
+    "urbit_amd64_sha256": "7dc0a1f97214101482d9c329a5108471bcf23fafea421e1ae2662c6c20377037",
+    "urbit_arm64_sha256": "1dbded539bd99cd789bfe5cbe11bb89baa598e213881389e8138da8fc0a27fa9",
+    "minio_amd64_sha256": "f6a3001a765dc59a8e365149ade0ea628494230e984891877ead016eb24ba9a9",
+    "minio_arm64_sha256": "567779c9f29aca670f84d066051290faeaae6c3ad3a3b7062de4936aaab2a29d",
+    "minio_password": "",
+    "network": "none",
+    "wg_url": "hocfur-wicnym-nallux-dozryl.nativeplanet.live",
+    "wg_http_port": "null",
+    "wg_ames_port": "null",
+    "wg_s3_port": "null",
+    "wg_console_port": "null",
+    "meld_schedule": false,
+    "meld_frequency": 7,
+    "meld_time": "0000",
+    "meld_last": "0",
+    "meld_next": "0",
+    "boot_status": "boot",
+    "custom_urbit_web": "",
+    "custom_s3_web": "",
+    "show_urbit_web": "default",
+    "dev_mode": false,
+    "click": true
+}

+ 32 - 0
settings/pier/nimsum-hanlyx-nallux-dozryl.json

@@ -0,0 +1,32 @@
+{
+    "pier_name": "nimsum-hanlyx-nallux-dozryl",
+    "http_port": 8089,
+    "ames_port": 34352,
+    "loom_size": 31,
+    "urbit_version": "v2.11",
+    "minio_version": "latest",
+    "urbit_repo": "registry.hub.docker.com/nativeplanet/urbit",
+    "minio_repo": "registry.hub.docker.com/minio/minio",
+    "urbit_amd64_sha256": "7dc0a1f97214101482d9c329a5108471bcf23fafea421e1ae2662c6c20377037",
+    "urbit_arm64_sha256": "1dbded539bd99cd789bfe5cbe11bb89baa598e213881389e8138da8fc0a27fa9",
+    "minio_amd64_sha256": "f6a3001a765dc59a8e365149ade0ea628494230e984891877ead016eb24ba9a9",
+    "minio_arm64_sha256": "567779c9f29aca670f84d066051290faeaae6c3ad3a3b7062de4936aaab2a29d",
+    "minio_password": "",
+    "network": "none",
+    "wg_url": "nimsum-hanlyx-nallux-dozryl.nativeplanet.live",
+    "wg_http_port": "null",
+    "wg_ames_port": "null",
+    "wg_s3_port": "null",
+    "wg_console_port": "null",
+    "meld_schedule": false,
+    "meld_frequency": 7,
+    "meld_time": "0000",
+    "meld_last": "0",
+    "meld_next": "0",
+    "boot_status": "boot",
+    "custom_urbit_web": "",
+    "custom_s3_web": "",
+    "show_urbit_web": "default",
+    "dev_mode": false,
+    "click": true
+}

+ 32 - 0
settings/pier/nopmul-pollyt.json

@@ -0,0 +1,32 @@
+{
+    "pier_name": "nopmul-pollyt",
+    "http_port": 8087,
+    "ames_port": 34350,
+    "loom_size": 31,
+    "urbit_version": "v2.11",
+    "minio_version": "latest",
+    "urbit_repo": "registry.hub.docker.com/nativeplanet/urbit",
+    "minio_repo": "registry.hub.docker.com/minio/minio",
+    "urbit_amd64_sha256": "7dc0a1f97214101482d9c329a5108471bcf23fafea421e1ae2662c6c20377037",
+    "urbit_arm64_sha256": "1dbded539bd99cd789bfe5cbe11bb89baa598e213881389e8138da8fc0a27fa9",
+    "minio_amd64_sha256": "f6a3001a765dc59a8e365149ade0ea628494230e984891877ead016eb24ba9a9",
+    "minio_arm64_sha256": "567779c9f29aca670f84d066051290faeaae6c3ad3a3b7062de4936aaab2a29d",
+    "minio_password": "",
+    "network": "none",
+    "wg_url": "nopmul-pollyt.nativeplanet.live",
+    "wg_http_port": 0,
+    "wg_ames_port": "null",
+    "wg_s3_port": "null",
+    "wg_console_port": "null",
+    "meld_schedule": false,
+    "meld_frequency": 7,
+    "meld_time": "0000",
+    "meld_last": "0",
+    "meld_next": "0",
+    "boot_status": "boot",
+    "custom_urbit_web": "",
+    "custom_s3_web": "",
+    "show_urbit_web": "default",
+    "dev_mode": false,
+    "click": false
+}

+ 32 - 0
settings/pier/widwet-mornev-nallux-dozryl.json

@@ -0,0 +1,32 @@
+{
+    "pier_name": "widwet-mornev-nallux-dozryl",
+    "http_port": 8081,
+    "ames_port": 34344,
+    "loom_size": 31,
+    "urbit_version": "v2.11",
+    "minio_version": "latest",
+    "urbit_repo": "registry.hub.docker.com/nativeplanet/urbit",
+    "minio_repo": "registry.hub.docker.com/minio/minio",
+    "urbit_amd64_sha256": "7dc0a1f97214101482d9c329a5108471bcf23fafea421e1ae2662c6c20377037",
+    "urbit_arm64_sha256": "1dbded539bd99cd789bfe5cbe11bb89baa598e213881389e8138da8fc0a27fa9",
+    "minio_amd64_sha256": "f6a3001a765dc59a8e365149ade0ea628494230e984891877ead016eb24ba9a9",
+    "minio_arm64_sha256": "567779c9f29aca670f84d066051290faeaae6c3ad3a3b7062de4936aaab2a29d",
+    "minio_password": "",
+    "network": "none",
+    "wg_url": "widwet-mornev-nallux-dozryl.nativeplanet.live",
+    "wg_http_port": "null",
+    "wg_ames_port": "null",
+    "wg_s3_port": "null",
+    "wg_console_port": "null",
+    "meld_schedule": false,
+    "meld_frequency": 7,
+    "meld_time": "0000",
+    "meld_last": "0",
+    "meld_next": "0",
+    "boot_status": "boot",
+    "custom_urbit_web": "",
+    "custom_s3_web": "",
+    "show_urbit_web": "default",
+    "dev_mode": false,
+    "click": true
+}

+ 7 - 1
settings/system.json

@@ -2,7 +2,13 @@
     "setup": "start",
     "endpointUrl": "api.startram.io",
     "apiVersion": "v1",
-    "piers": [],
+    "piers": [
+      "bilder-nallux-dozryl",
+      "nimsum-hanlyx-nallux-dozryl",
+      "widwet-mornev-nallux-dozryl",
+      "hocfur-wicnym-nallux-dozryl",
+      "nopmul-pollyt"
+    ],
     "netCheck": "1.1.1.1:53",
     "updateMode": "auto",
     "updateUrl": "https://version.groundseg.app",