Skip to content

Commit f1caac3

Browse files
authored
v2.6.1 (#750)
* add offline rustfs ports * add s3 tests * add custom flag inputs * add custom flag inputs * clean up extra flag ui * web shellA * webshell * fix modal * allow offline s3 domains; make sure wg conf gets written * add offline s3 domains; make sure wg conf gets written * Fix startram shutoff; fix allow you to enter custom s3 domain for offline * fix local s3 domain again * fix local s3 domain again * correct behavior for offline * recreate on alias
1 parent 588ac48 commit f1caac3

21 files changed

Lines changed: 659 additions & 97 deletions

goseg/broadcast/broadcast.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,12 @@ func ConstructPierInfo() (map[string]structs.Urbit, error) {
256256
}
257257
}
258258
}
259-
urbitAlias := dockerConfig.CustomUrbitWeb
260-
minIOAlias := dockerConfig.CustomS3Web
259+
urbitAlias := strings.TrimSpace(dockerConfig.CustomUrbitWeb)
260+
if strings.EqualFold(urbitAlias, "null") {
261+
urbitAlias = ""
262+
}
263+
minIOAlias := docker.ObjectStoreCustomDomain(conf, dockerConfig)
264+
minIOAliasMode := docker.ObjectStoreCustomDomainMode(conf, dockerConfig)
261265
showUrbAlias := false
262266
if dockerConfig.ShowUrbitWeb == "custom" {
263267
showUrbAlias = true
@@ -352,6 +356,7 @@ func ConstructPierInfo() (map[string]structs.Urbit, error) {
352356
urbit.Info.MinIOPwd = minIOPwd
353357
urbit.Info.UrbitAlias = urbitAlias
354358
urbit.Info.MinIOAlias = minIOAlias
359+
urbit.Info.MinIOAliasMode = minIOAliasMode
355360
urbit.Info.ShowUrbAlias = showUrbAlias
356361
urbit.Info.MinIOLinked = minioLinked
357362
urbit.Info.PackScheduleActive = dockerConfig.MeldSchedule

goseg/config/urbit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func LoadUrbitConfig(pier string) error {
6767
if targetStruct.SnapTime == 0 {
6868
targetStruct.SnapTime = 60
6969
}
70+
structs.SyncCustomS3Domains(&targetStruct)
7071
// Store in var
7172
UrbitsConfig[pier] = targetStruct
7273
return nil
@@ -89,6 +90,7 @@ func UpdateUrbitConfig(inputConfig map[string]structs.UrbitDocker) error {
8990
defer urbitMutex.Unlock()
9091
// update UrbitsConfig with the values from inputConfig
9192
for pier, config := range inputConfig {
93+
structs.SyncCustomS3Domains(&config)
9294
ver, err := getImageTagByContainerName(pier)
9395
if err == nil {
9496
config.UrbitVersion = ver

goseg/config/urbit_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package config
2+
3+
import (
4+
"encoding/json"
5+
"os"
6+
"path/filepath"
7+
"testing"
8+
9+
"groundseg/structs"
10+
)
11+
12+
func TestLoadAndUpdateUrbitConfigKeepsLegacyCustomS3Field(t *testing.T) {
13+
oldBasePath := BasePath
14+
oldConfigs := UrbitsConfig
15+
t.Cleanup(func() {
16+
BasePath = oldBasePath
17+
UrbitsConfig = oldConfigs
18+
})
19+
20+
BasePath = t.TempDir()
21+
UrbitsConfig = make(map[string]structs.UrbitDocker)
22+
23+
pier := "zod"
24+
path := filepath.Join(BasePath, "settings", "pier", pier+".json")
25+
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
26+
t.Fatalf("failed to create pier config dir: %v", err)
27+
}
28+
29+
initial := map[string]any{
30+
"custom_s3_web": "legacy.storage.example.com",
31+
}
32+
initialJSON, err := json.Marshal(initial)
33+
if err != nil {
34+
t.Fatalf("failed to encode legacy config: %v", err)
35+
}
36+
if err := os.WriteFile(path, initialJSON, 0o644); err != nil {
37+
t.Fatalf("failed to write legacy config: %v", err)
38+
}
39+
40+
if err := LoadUrbitConfig(pier); err != nil {
41+
t.Fatalf("failed to load config: %v", err)
42+
}
43+
44+
conf := UrbitConf(pier)
45+
if conf.CustomS3WebLocal != "legacy.storage.example.com" {
46+
t.Fatalf("expected local custom domain to inherit legacy value, got %q", conf.CustomS3WebLocal)
47+
}
48+
if conf.CustomS3WebRemote != "legacy.storage.example.com" {
49+
t.Fatalf("expected remote custom domain to inherit legacy value, got %q", conf.CustomS3WebRemote)
50+
}
51+
if conf.CustomS3Web != "legacy.storage.example.com" {
52+
t.Fatalf("expected legacy compatibility field to remain populated, got %q", conf.CustomS3Web)
53+
}
54+
55+
conf.CustomS3WebLocal = "local.storage.example.com"
56+
conf.CustomS3WebRemote = "remote.storage.example.com"
57+
if err := UpdateUrbitConfig(map[string]structs.UrbitDocker{pier: conf}); err != nil {
58+
t.Fatalf("failed to update config: %v", err)
59+
}
60+
61+
raw, err := os.ReadFile(path)
62+
if err != nil {
63+
t.Fatalf("failed to read updated config: %v", err)
64+
}
65+
66+
var saved structs.UrbitDocker
67+
if err := json.Unmarshal(raw, &saved); err != nil {
68+
t.Fatalf("failed to decode updated config: %v", err)
69+
}
70+
71+
if saved.CustomS3Web != "local.storage.example.com" {
72+
t.Fatalf("expected legacy field to stay populated with local/default domain, got %q", saved.CustomS3Web)
73+
}
74+
if saved.CustomS3WebLocal != "local.storage.example.com" {
75+
t.Fatalf("expected local field to persist, got %q", saved.CustomS3WebLocal)
76+
}
77+
if saved.CustomS3WebRemote != "remote.storage.example.com" {
78+
t.Fatalf("expected remote field to persist, got %q", saved.CustomS3WebRemote)
79+
}
80+
}

goseg/defaults/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ var (
4242
CustomPierLocation: nil,
4343
CustomUrbitWeb: "",
4444
CustomS3Web: "",
45+
CustomS3WebLocal: "",
46+
CustomS3WebRemote: "",
4547
ShowUrbitWeb: "",
4648
DevMode: false,
4749
Click: true,

goseg/docker/minio.go

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,78 @@ func objectStoreStarTramEnabled(conf structs.SysConfig) bool {
196196
return conf.WgRegistered && conf.WgOn
197197
}
198198

199+
func normalizedObjectStoreCustomDomain(domain string) string {
200+
domain = strings.TrimSpace(domain)
201+
if strings.EqualFold(domain, "null") {
202+
return ""
203+
}
204+
return domain
205+
}
206+
207+
func ObjectStoreUsesRemoteDomain(conf structs.SysConfig, shipConf structs.UrbitDocker) bool {
208+
return objectStoreStarTramEnabled(conf) &&
209+
shipConf.Network == "wireguard" &&
210+
strings.TrimSpace(shipConf.WgURL) != ""
211+
}
212+
213+
func ObjectStoreCustomDomainMode(conf structs.SysConfig, shipConf structs.UrbitDocker) string {
214+
if ObjectStoreUsesRemoteDomain(conf, shipConf) {
215+
return "remote"
216+
}
217+
return "local"
218+
}
219+
220+
func objectStoreCustomDomainForMode(shipConf structs.UrbitDocker, mode string) string {
221+
switch mode {
222+
case "remote":
223+
if domain := normalizedObjectStoreCustomDomain(shipConf.CustomS3WebRemote); domain != "" {
224+
return domain
225+
}
226+
default:
227+
if domain := normalizedObjectStoreCustomDomain(shipConf.CustomS3WebLocal); domain != "" {
228+
return domain
229+
}
230+
}
231+
return normalizedObjectStoreCustomDomain(shipConf.CustomS3Web)
232+
}
233+
234+
func ObjectStoreCustomDomain(conf structs.SysConfig, shipConf structs.UrbitDocker) string {
235+
return objectStoreCustomDomainForMode(shipConf, ObjectStoreCustomDomainMode(conf, shipConf))
236+
}
237+
238+
func ObjectStoreCustomDomains(shipConf structs.UrbitDocker) []string {
239+
domains := []string{}
240+
for _, candidate := range []string{
241+
normalizedObjectStoreCustomDomain(shipConf.CustomS3WebLocal),
242+
normalizedObjectStoreCustomDomain(shipConf.CustomS3WebRemote),
243+
normalizedObjectStoreCustomDomain(shipConf.CustomS3Web),
244+
} {
245+
if candidate != "" && !contains(domains, candidate) {
246+
domains = append(domains, candidate)
247+
}
248+
}
249+
return domains
250+
}
251+
252+
func SetObjectStoreCustomDomain(conf structs.SysConfig, shipConf *structs.UrbitDocker, domain string) {
253+
domain = normalizedObjectStoreCustomDomain(domain)
254+
switch ObjectStoreCustomDomainMode(conf, *shipConf) {
255+
case "remote":
256+
shipConf.CustomS3WebRemote = domain
257+
default:
258+
shipConf.CustomS3WebLocal = domain
259+
}
260+
structs.SyncCustomS3Domains(shipConf)
261+
}
262+
199263
func objectStoreOfflineHostPorts(shipConf structs.UrbitDocker) (int, int) {
200264
consolePort := shipConf.HTTPPort + offlineRustFSConsoleOffset
201265
s3Port := shipConf.HTTPPort + offlineRustFSS3Offset
202266
return s3Port, consolePort
203267
}
204268

205269
func objectStorePorts(conf structs.SysConfig, shipConf structs.UrbitDocker) objectStorePortConfig {
206-
if objectStoreStarTramEnabled(conf) {
270+
if ObjectStoreUsesRemoteDomain(conf, shipConf) {
207271
return objectStorePortConfig{
208272
useWireguard: true,
209273
listenS3Port: shipConf.WgS3Port,
@@ -231,10 +295,10 @@ func objectStoreAdminEndpoint(conf structs.SysConfig, patp string, shipConf stru
231295
}
232296

233297
func objectStoreLinkEndpoint(conf structs.SysConfig, shipConf structs.UrbitDocker) string {
234-
if endpoint := strings.TrimSpace(shipConf.CustomS3Web); endpoint != "" {
298+
if endpoint := strings.TrimSpace(ObjectStoreCustomDomain(conf, shipConf)); endpoint != "" {
235299
return endpoint
236300
}
237-
if objectStoreStarTramEnabled(conf) && strings.TrimSpace(shipConf.WgURL) != "" {
301+
if ObjectStoreUsesRemoteDomain(conf, shipConf) {
238302
return fmt.Sprintf("s3.%s", shipConf.WgURL)
239303
}
240304
hostS3Port, _ := objectStoreOfflineHostPorts(shipConf)
@@ -249,7 +313,7 @@ func GetObjectStoreLinkEndpoint(patp string) (string, error) {
249313
}
250314

251315
func ObjectStoreConsoleURL(hostName string, conf structs.SysConfig, shipConf structs.UrbitDocker) string {
252-
if objectStoreStarTramEnabled(conf) && strings.TrimSpace(shipConf.WgURL) != "" {
316+
if ObjectStoreUsesRemoteDomain(conf, shipConf) {
253317
return fmt.Sprintf("https://console.s3.%s/rustfs/console/index.html", shipConf.WgURL)
254318
}
255319
_, hostConsolePort := objectStoreOfflineHostPorts(shipConf)
@@ -399,7 +463,7 @@ func minioContainerConf(containerName string) (container.Config, container.HostC
399463
return containerConfig, hostConfig, fmt.Errorf("invalid offline RustFS host ports for %s", shipName)
400464
}
401465

402-
serverDomains := objectStoreServerDomains(shipConf)
466+
serverDomains := objectStoreServerDomains(conf, shipConf)
403467
environment := []string{
404468
fmt.Sprintf("RUSTFS_ACCESS_KEY=%s", shipName),
405469
fmt.Sprintf("RUSTFS_SECRET_KEY=%s", storePwd),
@@ -500,18 +564,20 @@ func normalizeObjectStoreDomain(domain string) string {
500564
return strings.TrimSpace(strings.Trim(domain, "/"))
501565
}
502566

503-
func objectStoreServerDomains(shipConf structs.UrbitDocker) string {
567+
func objectStoreServerDomains(conf structs.SysConfig, shipConf structs.UrbitDocker) string {
504568
var domains []string
505569
baseDomain := strings.TrimSpace(shipConf.WgURL)
506-
if baseDomain != "" {
570+
if ObjectStoreUsesRemoteDomain(conf, shipConf) && baseDomain != "" {
507571
defaultDomain := normalizeObjectStoreDomain(fmt.Sprintf("s3.%s", baseDomain))
508572
if defaultDomain != "" {
509573
domains = append(domains, defaultDomain)
510574
}
511575
}
512-
customDomain := normalizeObjectStoreDomain(shipConf.CustomS3Web)
513-
if customDomain != "" && !contains(domains, customDomain) {
514-
domains = append(domains, customDomain)
576+
for _, customDomain := range ObjectStoreCustomDomains(shipConf) {
577+
normalized := normalizeObjectStoreDomain(customDomain)
578+
if normalized != "" && !contains(domains, normalized) {
579+
domains = append(domains, normalized)
580+
}
515581
}
516582
return strings.Join(domains, ",")
517583
}

0 commit comments

Comments
 (0)