#!/usr/bin/env bash # deploy-haproxy - Deploy and manage HAProxy load balancing on an Incus cluster # # Deploys test backends (nginx), builds a HAProxy image via Aether, # deploys HA infrastructure (2x HAProxy + OVN LB), and creates an # HTTP service with health checks. # # Uses Aether session-based authentication (not JWT) for HAProxy # management endpoints that are not in the public API. # # Usage: deploy-haproxy [OPTIONS] # Run 'deploy-haproxy --help' for full usage information. set -euo pipefail readonly VERSION="0.1.0" readonly SCRIPT_NAME="deploy-haproxy" readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly ENV_FILE="${SCRIPT_DIR}/../env" # --------------------------------------------------------------------------- # Defaults (overridden by config file or CLI flags) # --------------------------------------------------------------------------- CLUSTER_REMOTE="oc-node-01" CLUSTER_ID="52" OVN_NETWORK="net-prod" VIP="192.168.103.200" HAPROXY_01_IP="10.10.10.50" HAPROXY_02_IP="10.10.10.51" HAPROXY_CPU="2" HAPROXY_MEMORY="1GB" BACKEND_IPS="10.10.10.60,10.10.10.61,10.10.10.62" BACKEND_PORT="80" SERVICE_NAME="web-test" SERVICE_MODE="http" SERVICE_BALANCE="roundrobin" IMAGE_VERSION="1.0.0" AETHER_URL="https://192.168.102.160:8443" AETHER_USER="admin" AETHER_PASSWORD="" # Runtime flags DRY_RUN=false VERBOSE=false QUIET=false CONFIG_FILE="" ACTION="" SKIP_BACKENDS=false SKIP_IMAGE=false # Session state COOKIE_JAR="" CSRF_TOKEN="" # --------------------------------------------------------------------------- # Color and formatting # --------------------------------------------------------------------------- setup_colors() { if [[ -t 1 ]] && [[ "${NO_COLOR:-}" != "1" ]] && [[ "${TERM:-}" != "dumb" ]]; then RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' CYAN='\033[0;36m' BOLD='\033[1m' DIM='\033[2m' RESET='\033[0m' else RED='' GREEN='' YELLOW='' BLUE='' CYAN='' BOLD='' DIM='' RESET='' fi } info() { [[ "$QUIET" == true ]] && return; echo -e "${BLUE}[info]${RESET} $*"; } success() { [[ "$QUIET" == true ]] && return; echo -e "${GREEN}[ok]${RESET} $*"; } warn() { echo -e "${YELLOW}[warn]${RESET} $*" >&2; } error() { echo -e "${RED}[error]${RESET} $*" >&2; } step() { [[ "$QUIET" == true ]] && return; echo -e "${CYAN}[step]${RESET} ${BOLD}$*${RESET}"; } detail() { [[ "$VERBOSE" != true ]] && return; echo -e "${DIM} $*${RESET}"; } dry_run_guard() { if [[ "$DRY_RUN" == true ]]; then info "(dry-run) $*" return 1 fi return 0 } # --------------------------------------------------------------------------- # Help # --------------------------------------------------------------------------- usage() { cat <