From d0ad1c52437f6d07cf59ecdccdb72a48e1f1cea2 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 1 Aug 2026 15:21:04 +0000 Subject: [PATCH] fix: installer URL overridable, simplified deploy form - WALLARM_INSTALLER_URL env var overrides the native node installer URL - Address simplified: default IP 0.0.0.0, only ask for port - Added upstream IP/port prompts - Per-instance .env file saved to /opt/wallarm/{name}/.env (allows resuming/reinstalling from saved state) - Confirmation summary before deploying --- cmd/wallarm/main.go | 69 +++++++++++++++++++++++++++++++++------ internal/native/native.go | 6 +++- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/cmd/wallarm/main.go b/cmd/wallarm/main.go index 2a044e4..eae5fb5 100644 --- a/cmd/wallarm/main.go +++ b/cmd/wallarm/main.go @@ -14,6 +14,7 @@ import ( "flag" "fmt" "os" + "strconv" "strings" "time" @@ -82,11 +83,26 @@ func runDeployFlow(r preflight.Result) { return } - fmt.Print("Listen address [0.0.0.0:8081]: ") - address, _ := reader.ReadString('\n') - address = strings.TrimSpace(address) - if address == "" { - address = "0.0.0.0:8081" + fmt.Print("Listen port [8081]: ") + port, _ := reader.ReadString('\n') + port = strings.TrimSpace(port) + if port == "" { + port = "8081" + } + address := "0.0.0.0:" + port + + fmt.Print("Upstream IP [127.0.0.1]: ") + upstreamIP, _ := reader.ReadString('\n') + upstreamIP = strings.TrimSpace(upstreamIP) + if upstreamIP == "" { + upstreamIP = "127.0.0.1" + } + + fmt.Print("Upstream port [80]: ") + upstreamPort, _ := reader.ReadString('\n') + upstreamPort = strings.TrimSpace(upstreamPort) + if upstreamPort == "" { + upstreamPort = "80" } fmt.Print("Labels [group=" + nodeName + "]: ") @@ -96,18 +112,51 @@ func runDeployFlow(r preflight.Result) { labels = "group=" + nodeName } + fmt.Println() + fmt.Printf(" Node: %s\n", nodeName) + fmt.Printf(" Listen: %s\n", address) + fmt.Printf(" Upstream: %s:%s\n", upstreamIP, upstreamPort) + fmt.Printf(" Region: %s (%s)\n", s.CloudRegion, s.APIHost) + fmt.Print("\nProceed with deployment? [Y/n]: ") + confirm, _ := reader.ReadString('\n') + confirm = strings.TrimSpace(strings.ToLower(confirm)) + if confirm != "" && confirm != "y" && confirm != "yes" { + fmt.Println("Cancelled.") + return + } + + baseDir := "/opt/wallarm" + instanceDir := baseDir + "/" + nodeName + + portNum, _ := strconv.Atoi(upstreamPort) s.Nodes = append(s.Nodes, state.Node{ - Name: nodeName, - Type: "native", - Address: address, - Status: "deploying", - CreatedAt: time.Now().Format(time.RFC3339), + Name: nodeName, + Type: "native", + Address: address, + UpstreamIP: upstreamIP, + UpstreamPort: portNum, + Status: "deploying", + CreatedAt: time.Now().Format(time.RFC3339), }) // Step 4: Deploy fmt.Println() fmt.Println("Starting deployment...") + // Create instance directory and .env file + os.MkdirAll(instanceDir+"/etc", 0755) + os.MkdirAll(instanceDir+"/var/log", 0755) + os.MkdirAll(instanceDir+"/var/run", 0755) + + envContent := fmt.Sprintf(`WALLARM_API_TOKEN=%s +WALLARM_API_HOST=%s +WALLARM_LABELS=%s +WALLARM_LISTEN=%s +WALLARM_UPSTREAM=%s:%s +WALLARM_REGION=%s +`, s.APIToken, s.APIHost, labels, address, upstreamIP, upstreamPort, s.CloudRegion) + os.WriteFile(instanceDir+"/.env", []byte(envContent), 0600) + if err := native.CreateNodesDir(); err != nil { fmt.Fprintf(os.Stderr, "Error: %v\n", err) return diff --git a/internal/native/native.go b/internal/native/native.go index c344c94..abd9ec0 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -59,9 +59,13 @@ connector: } // 3. Download installer if missing + installerURL := InstallerURL + if u := os.Getenv("WALLARM_INSTALLER_URL"); u != "" { + installerURL = u + } if _, err := os.Stat(installerPath); os.IsNotExist(err) { fmt.Printf("[%s] Downloading installer...\n", node.Name) - cmd := exec.Command("curl", "-fsSL", "-o", installerPath, InstallerURL) + cmd := exec.Command("curl", "-fsSL", "-o", installerPath, installerURL) if out, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("download installer: %w\n%s", err, string(out)) }