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
This commit is contained in:
parent
ed9655ee79
commit
d0ad1c5243
2 changed files with 64 additions and 11 deletions
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -82,11 +83,26 @@ func runDeployFlow(r preflight.Result) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Listen address [0.0.0.0:8081]: ")
|
fmt.Print("Listen port [8081]: ")
|
||||||
address, _ := reader.ReadString('\n')
|
port, _ := reader.ReadString('\n')
|
||||||
address = strings.TrimSpace(address)
|
port = strings.TrimSpace(port)
|
||||||
if address == "" {
|
if port == "" {
|
||||||
address = "0.0.0.0:8081"
|
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 + "]: ")
|
fmt.Print("Labels [group=" + nodeName + "]: ")
|
||||||
|
|
@ -96,10 +112,29 @@ func runDeployFlow(r preflight.Result) {
|
||||||
labels = "group=" + nodeName
|
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{
|
s.Nodes = append(s.Nodes, state.Node{
|
||||||
Name: nodeName,
|
Name: nodeName,
|
||||||
Type: "native",
|
Type: "native",
|
||||||
Address: address,
|
Address: address,
|
||||||
|
UpstreamIP: upstreamIP,
|
||||||
|
UpstreamPort: portNum,
|
||||||
Status: "deploying",
|
Status: "deploying",
|
||||||
CreatedAt: time.Now().Format(time.RFC3339),
|
CreatedAt: time.Now().Format(time.RFC3339),
|
||||||
})
|
})
|
||||||
|
|
@ -108,6 +143,20 @@ func runDeployFlow(r preflight.Result) {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Starting deployment...")
|
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 {
|
if err := native.CreateNodesDir(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,13 @@ connector:
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Download installer if missing
|
// 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) {
|
if _, err := os.Stat(installerPath); os.IsNotExist(err) {
|
||||||
fmt.Printf("[%s] Downloading installer...\n", node.Name)
|
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 {
|
if out, err := cmd.CombinedOutput(); err != nil {
|
||||||
return fmt.Errorf("download installer: %w\n%s", err, string(out))
|
return fmt.Errorf("download installer: %w\n%s", err, string(out))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue