#!/bin/bash # build-update-agent.sh — Compile the KubeSolo OS update agent # # Builds a static Linux binary for the update agent. # Output: build/cache/kubesolo-update set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" UPDATE_DIR="$PROJECT_ROOT/update" CACHE_DIR="$PROJECT_ROOT/build/cache" OUTPUT="$CACHE_DIR/kubesolo-update" echo "=== Building KubeSolo Update Agent ===" # Ensure output dir exists mkdir -p "$CACHE_DIR" # Run tests first echo "--- Running tests ---" (cd "$UPDATE_DIR" && go test ./... -count=1) # Build static binary echo "--- Compiling static binary ---" (cd "$UPDATE_DIR" && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ go build -ldflags='-s -w' -o "$OUTPUT" .) SIZE=$(ls -lh "$OUTPUT" | awk '{print $5}') echo "--- Update agent built: $OUTPUT ($SIZE) ---"