fix: source-based deploy.sh — clones repo, builds binary
Gitea server has strict HTTP body limits (~1MB) preventing binary uploads. deploy.sh now clones the repo and builds from source using Go (auto-installed if missing). Build takes ~30 seconds. Binary is ~7MB stripped, ~2MB with UPX.
This commit is contained in:
parent
67d9a6a7d8
commit
58faccbb27
2 changed files with 57 additions and 69 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -11,3 +11,4 @@ notes/
|
||||||
wallarm
|
wallarm
|
||||||
bin/
|
bin/
|
||||||
wallarm-upx
|
wallarm-upx
|
||||||
|
bin/
|
||||||
|
|
|
||||||
125
deploy.sh
125
deploy.sh
|
|
@ -1,15 +1,14 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Wallarm Deployment — Single Binary Bootstrap
|
# Wallarm Deployment — Source-based Bootstrap
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Downloads the wallarm binary from the Git repository and places it in
|
# Clones the repository and builds the wallarm binary from source.
|
||||||
# ~/deploy/. One command to get started:
|
# One command to get started:
|
||||||
#
|
#
|
||||||
# curl -fsSL ".../deploy.sh" | bash
|
# curl -fsSL ".../deploy.sh" | bash
|
||||||
# sudo ./deploy/wallarm
|
# sudo ./deploy/wallarm
|
||||||
#
|
#
|
||||||
# The binary handles everything: preflight → TUI wizard → deployment →
|
# Requires: git, go (auto-installed if missing on apt/yum systems)
|
||||||
# dashboard with multi-node management.
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
@ -21,83 +20,71 @@ YELLOW='\033[1;33m'
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
ARCH=$(uname -m)
|
REPO_URL="https://git.sechpoint.app/customer-engineering/wallarm.git"
|
||||||
case "$ARCH" in
|
|
||||||
x86_64|amd64) BIN_ARCH="amd64" ;;
|
|
||||||
aarch64|arm64) BIN_ARCH="arm64" ;;
|
|
||||||
*) echo -e "${RED}Unsupported architecture: $ARCH${NC}"; exit 1 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
REPO="https://git.sechpoint.app"
|
|
||||||
REPO_PATH="customer-engineering/wallarm"
|
|
||||||
API_URL="${REPO}/api/v1/repos/${REPO_PATH}/releases"
|
|
||||||
|
|
||||||
# Fetch latest release info
|
|
||||||
echo -e "${YELLOW}Checking latest release...${NC}"
|
|
||||||
if command -v curl >/dev/null 2>&1; then
|
|
||||||
RELEASE_JSON=$(curl -fsSL "${API_URL}?limit=1" 2>/dev/null)
|
|
||||||
elif command -v wget >/dev/null 2>&1; then
|
|
||||||
RELEASE_JSON=$(wget -qO- "${API_URL}?limit=1" 2>/dev/null)
|
|
||||||
else
|
|
||||||
echo -e "${RED}Neither curl nor wget found. Install one and re-run.${NC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Parse release tag and asset URL
|
|
||||||
RELEASE_TAG=$(echo "$RELEASE_JSON" | grep -o '"tag_name":"[^"]*"' | head -1 | cut -d'"' -f4)
|
|
||||||
if [[ -z "$RELEASE_TAG" ]]; then
|
|
||||||
echo -e "${RED}No release found. Create a Gitea release first.${NC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
BIN_URL="${REPO}/api/v1/repos/${REPO_PATH}/releases/tags/${RELEASE_TAG}/assets"
|
|
||||||
echo -e "${GREEN} Latest release: ${RELEASE_TAG}${NC}"
|
|
||||||
|
|
||||||
# Download the binary via release assets API
|
|
||||||
ASSETS_JSON=$(curl -fsSL "${REPO}/api/v1/repos/${REPO_PATH}/releases/tags/${RELEASE_TAG}" 2>/dev/null)
|
|
||||||
DOWNLOAD_URL=$(echo "$ASSETS_JSON" | grep -o "\"browser_download_url\":\"[^\"]*wallarm-linux-${BIN_ARCH}[^\"]*" | head -1 | cut -d'"' -f4)
|
|
||||||
DEPLOY_DIR="${HOME:-/root}/deploy"
|
DEPLOY_DIR="${HOME:-/root}/deploy"
|
||||||
BIN_PATH="${DEPLOY_DIR}/wallarm"
|
BUILD_DIR="/tmp/wallarm-build-$$"
|
||||||
|
|
||||||
mkdir -p "$DEPLOY_DIR"
|
cleanup() { rm -rf "$BUILD_DIR"; }
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
echo -e "${BOLD}Wallarm Deployment Bootstrap${NC}"
|
echo -e "${BOLD}Wallarm Deployment Bootstrap${NC}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Download the binary
|
# ── Ensure prerequisites ─────────────────────────────────────────────
|
||||||
if [[ -z "$DOWNLOAD_URL" ]]; then
|
install_go() {
|
||||||
echo -e "${RED}No linux-${BIN_ARCH} binary found in release ${RELEASE_TAG}.${NC}"
|
echo -e "${YELLOW}Installing Go...${NC}"
|
||||||
echo -e "${YELLOW}Available assets:${NC}"
|
if command -v apt-get >/dev/null 2>&1; then
|
||||||
echo "$ASSETS_JSON" | grep -o '"name":"[^"]*"' | cut -d'"' -f4
|
apt-get update -qq && apt-get install -y -qq golang-go
|
||||||
exit 1
|
elif command -v yum >/dev/null 2>&1; then
|
||||||
|
yum install -y golang
|
||||||
|
elif command -v dnf >/dev/null 2>&1; then
|
||||||
|
dnf install -y golang
|
||||||
|
elif command -v apk >/dev/null 2>&1; then
|
||||||
|
apk add --no-cache go
|
||||||
|
else
|
||||||
|
echo -e "${RED}Cannot install Go automatically. Install Go 1.21+ manually.${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensure git
|
||||||
|
if ! command -v git >/dev/null 2>&1; then
|
||||||
|
echo -e "${YELLOW}Installing git...${NC}"
|
||||||
|
apt-get update -qq 2>/dev/null && apt-get install -y -qq git 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${YELLOW}Downloading wallarm (${RELEASE_TAG}, linux-${BIN_ARCH})...${NC}"
|
# Ensure Go
|
||||||
if command -v curl >/dev/null 2>&1; then
|
if ! command -v go >/dev/null 2>&1; then
|
||||||
curl -fsSL --progress-bar "$DOWNLOAD_URL" -o "$BIN_PATH"
|
install_go
|
||||||
elif command -v wget >/dev/null 2>&1; then
|
|
||||||
wget -q --show-progress "$DOWNLOAD_URL" -O "$BIN_PATH"
|
|
||||||
else
|
|
||||||
echo -e "${RED}Neither curl nor wget found. Install one and re-run.${NC}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x "$BIN_PATH"
|
echo -e "${GREEN} git: $(git --version | cut -d' ' -f3)${NC}"
|
||||||
echo -e "${GREEN} Success: wallarm installed to ${BIN_PATH}${NC}"
|
echo -e "${GREEN} go: $(go version | cut -d' ' -f3)${NC}"
|
||||||
|
|
||||||
|
# ── Clone and build ───────────────────────────────────────────────────
|
||||||
echo
|
echo
|
||||||
|
echo -e "${YELLOW}Cloning repository...${NC}"
|
||||||
|
git clone --depth 1 "$REPO_URL" "$BUILD_DIR" 2>/dev/null
|
||||||
|
|
||||||
# Quick preflight (just to confirm binary works)
|
echo -e "${YELLOW}Building wallarm (this takes ~30 seconds)...${NC}"
|
||||||
echo -e "${YELLOW}Testing binary...${NC}"
|
cd "$BUILD_DIR"
|
||||||
if "$BIN_PATH" --version 2>/dev/null; then
|
go build -ldflags="-s -w -X main.version=$(git describe --tags --always 2>/dev/null || echo 'dev')" -o wallarm ./cmd/wallarm/
|
||||||
echo -e "${GREEN} Binary OK${NC}"
|
|
||||||
else
|
# Optional: compress with UPX if available
|
||||||
echo -e "${RED} Binary verification failed${NC}"
|
if command -v upx >/dev/null 2>&1; then
|
||||||
exit 1
|
upx --best --lzma wallarm -o wallarm.tmp 2>/dev/null && mv wallarm.tmp wallarm || true
|
||||||
fi
|
fi
|
||||||
echo
|
|
||||||
|
|
||||||
|
# ── Install ───────────────────────────────────────────────────────────
|
||||||
|
mkdir -p "$DEPLOY_DIR"
|
||||||
|
cp wallarm "$DEPLOY_DIR/wallarm"
|
||||||
|
chmod +x "$DEPLOY_DIR/wallarm"
|
||||||
|
|
||||||
|
echo
|
||||||
echo -e "${GREEN}${BOLD}Ready!${NC}"
|
echo -e "${GREEN}${BOLD}Ready!${NC}"
|
||||||
echo
|
echo
|
||||||
echo -e " ${CYAN}sudo ${BIN_PATH}${NC} — Start the TUI (wizard on first run, dashboard after)"
|
echo -e " ${CYAN}sudo ${DEPLOY_DIR}/wallarm${NC} — Start the TUI"
|
||||||
echo -e " ${CYAN}${BIN_PATH} --help${NC} — Show all commands"
|
echo -e " ${CYAN}${DEPLOY_DIR}/wallarm --help${NC} — Show all commands"
|
||||||
echo -e " ${CYAN}${BIN_PATH} --tunnel${NC} — Start remote access tunnel"
|
echo -e " ${CYAN}${DEPLOY_DIR}/wallarm --tunnel${NC} — Start remote tunnel"
|
||||||
|
echo
|
||||||
|
ls -lh "$DEPLOY_DIR/wallarm"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue