From b44da10ae76c30d96fc3ff50137c2105f0ea947e Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 1 Aug 2026 16:55:53 +0000 Subject: [PATCH] fix: preflight URL, /opt/fw/ refactor complete --- cmd/deploy/main.go | 10 ++++---- internal/native/native.go | 42 ++++++++++++++++++--------------- internal/preflight/preflight.go | 4 ++-- internal/state/state.go | 2 +- setup.sh | 5 ++-- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/cmd/deploy/main.go b/cmd/deploy/main.go index e75520a..47db651 100644 --- a/cmd/deploy/main.go +++ b/cmd/deploy/main.go @@ -125,8 +125,8 @@ func runDeployFlow(r preflight.Result) { return } - baseDir := "/opt/wallarm" - instanceDir := baseDir + "/" + nodeName + baseDir := "/opt/fw" + instanceDir := baseDir + "/" + nodeName + "/wallarm" portNum, _ := strconv.Atoi(upstreamPort) s.Nodes = append(s.Nodes, state.Node{ @@ -181,11 +181,11 @@ WALLARM_REGION=%s fmt.Println() fmt.Println("✅ Deployment complete!") fmt.Println() - fmt.Printf(" Binary: /opt/wallarm/deploy\n") + fmt.Printf(" Binary: /opt/fw/deploy\n") fmt.Printf(" Instance: %s\n", instanceDir) - fmt.Printf(" State: /opt/wallarm/state.json\n") + fmt.Printf(" State: /opt/fw/state.json\n") fmt.Println() - fmt.Println("Run 'sudo /opt/wallarm/deploy' for the dashboard.") + fmt.Println("Run 'sudo /opt/fw/deploy' for the dashboard.") } func runTunnelFlow() { fmt.Println() diff --git a/internal/native/native.go b/internal/native/native.go index 78dde33..7c45a96 100644 --- a/internal/native/native.go +++ b/internal/native/native.go @@ -11,10 +11,10 @@ import ( ) const ( - BaseDir = "/opt/wallarm" - NodesDir = BaseDir + "/nodes" - NginxDir = BaseDir + "/nginx" - SystemdTemplate = "/etc/systemd/system/wallarm-node@.service" + BaseDir = "/opt/fw" + Symlink = "/opt/wallarm" + NginxDir = BaseDir + "/nginx" + NodesDir = BaseDir ) func installerURL() string { @@ -29,13 +29,14 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error { return fmt.Errorf("API token required") } - archiveDir := BaseDir - installerPath := filepath.Join(archiveDir, "wallarm-aio.sh") + instanceDir := filepath.Join(BaseDir, node.Name, "wallarm") + installerPath := filepath.Join(BaseDir, "wallarm-aio.sh") + _ = labels - // 1. Install NGINX + // 1. Install NGINX (shared) installNginx() - // 2. Download AIO + // 2. Download AIO once if _, err := os.Stat(installerPath); os.IsNotExist(err) { fmt.Printf("[%s] Downloading installer...\n", node.Name) cmd := exec.Command("curl", "-fsSL", "-o", installerPath, installerURL()) @@ -45,22 +46,25 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error { os.Chmod(installerPath, 0755) } - // 3. Extract once - if _, err := os.Stat(filepath.Join(archiveDir, "setup.sh")); os.IsNotExist(err) { - fmt.Printf("[%s] Extracting...\n", node.Name) - cmd := exec.Command("bash", installerPath, "--noexec", "--keep", "--target", archiveDir, "--noprogress", "--accept") - if out, err := cmd.CombinedOutput(); err != nil { - return fmt.Errorf("extract: %w\n%s", err, string(out)) - } + // 3. Create instance dir + symlink (setup.sh hardcodes /opt/wallarm) + os.MkdirAll(instanceDir, 0755) + os.Remove(Symlink) + os.Symlink(instanceDir, Symlink) + + // 4. Extract AIO to instance via symlink + fmt.Printf("[%s] Extracting...\n", node.Name) + cmd := exec.Command("bash", installerPath, "--noexec", "--keep", "--target", instanceDir, "--noprogress", "--accept") + if out, err := cmd.CombinedOutput(); err != nil { + return fmt.Errorf("extract: %w\n%s", err, string(out)) } - // 4. Run setup + // 5. Run setup.sh (sees /opt/wallarm → instance dir) fmt.Printf("[%s] Running setup...\n", node.Name) - cmd := exec.Command("bash", filepath.Join(archiveDir, "setup.sh"), + cmd = exec.Command("bash", filepath.Join(instanceDir, "setup.sh"), "--batch", "--token", apiToken, "--cloud", cloudFromHost(apiHost), ) - logFile, _ := os.Create(filepath.Join(archiveDir, "install.log")) + logFile, _ := os.Create(filepath.Join(instanceDir, "install.log")) if logFile != nil { cmd.Stdout = logFile cmd.Stderr = logFile @@ -70,7 +74,7 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error { logFile.Close() } if runErr != nil { - if data, _ := os.ReadFile(filepath.Join(archiveDir, "install.log")); len(data) > 0 { + if data, _ := os.ReadFile(filepath.Join(instanceDir, "install.log")); len(data) > 0 { lines := strings.Split(string(data), "\n") s := len(lines) - 5 if s < 0 { diff --git a/internal/preflight/preflight.go b/internal/preflight/preflight.go index 7420629..ec66dee 100644 --- a/internal/preflight/preflight.go +++ b/internal/preflight/preflight.go @@ -88,10 +88,10 @@ func Run() Result { } // 6. Installer reachability - installerOk := shared.HTTPHead("https://storage.googleapis.com/meganode_storage/") + installerOk := shared.HTTPHead("https://storage.googleapis.com/meganode_storage/6.13/") r.Checks = append(r.Checks, Check{ Name: "installer_reachable", Passed: installerOk, - Detail: "repo.wallarm.com", + Detail: "storage.googleapis.com", }) if !installerOk { r.Checks[len(r.Checks)-1].Warning = true diff --git a/internal/state/state.go b/internal/state/state.go index 0b3bfeb..16df18e 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -8,7 +8,7 @@ import ( ) // StateDir is where wallarm stores its state (under /opt/wallarm/). -const StateDir = "/opt/wallarm" +const StateDir = "/opt/fw" // State represents the persistent deployment state. type State struct { diff --git a/setup.sh b/setup.sh index 9aa76ba..8cb5cd7 100644 --- a/setup.sh +++ b/setup.sh @@ -20,7 +20,7 @@ RED='\033[0;31m' NC='\033[0m' REPO_URL="https://git.sechpoint.app/customer-engineering/wallarm.git" -WALLARM_DIR="/opt/wallarm" +WALLARM_DIR="/opt/fw" SOURCE_DIR="${WALLARM_DIR}/source" BUILD_DIR="/tmp/wallarm-build-$$" @@ -59,8 +59,7 @@ echo -e "${GREEN}git: $(git --version | cut -d' ' -f3) go: $(go version | cut - # ── Create /opt/wallarm/ ────────────────────────────────────────────── echo echo -e "${YELLOW}Creating /opt/wallarm/ directory structure...${NC}" -mkdir -p "${WALLARM_DIR}/nodes" -mkdir -p "${SOURCE_DIR}" +mkdir -p "${WALLARM_DIR}" cd "${WALLARM_DIR}" echo -e "${GREEN} Done.${NC}"