#!/usr/bin/env bash # Usage: tests/installer/run.sh [image] [amd64|arm64] e.g. fedora:41 or ubuntu:24.04 arm64 # Integration test of the installer scripts in a throwaway Ubuntu container (needs Docker). # tests/installer/run.sh # It builds the server and a linux agent, serves the installer from a local server, and runs # container-test.sh inside a container image. Nothing on this machine is changed. set -euo pipefail IMAGE="${1:-ubuntu:24.04}"; PLAT="${2:-amd64}" cd "$(dirname "$0")/../.." ROOT="$(pwd)" WORK="$(mktemp -d)" trap 'kill $(cat "$WORK/server.pid" 2>/dev/null) 2>/dev/null || true; sleep 1; rm -rf "$WORK" 2>/dev/null || true' EXIT echo "building..." mkdir -p "$WORK/dl" GOOS=linux GOARCH="$PLAT" go build -o "$WORK/dl/wxch-agent-$PLAT" ./cmd/wxch-agent go build -o "$WORK/wxch-server" ./cmd/wxch-server cd "$WORK" ./wxch-server -init -config config.json -password testpw-123456 >/dev/null PY=""; for c in python3 python; do "$c" -c "import sys" >/dev/null 2>&1 && { PY="$c"; break; }; done [ -n "$PY" ] || { echo "python is required to run this test" >&2; exit 1; } "$PY" - <<'PY' import json c = json.load(open("config.json")) c["listen"] = "0.0.0.0:8099" json.dump(c, open("config.json", "w"), indent=2) print(c["agent_tokens"]["pgx"], file=open("token.txt", "w")) PY ./wxch-server -config config.json >server.log 2>&1 & echo $! > server.pid sleep 2 TOKEN="$(cat token.txt)" # on Windows (Git Bash) paths for docker need converting if command -v cygpath >/dev/null 2>&1; then TESTDIR="$(cygpath -w "$ROOT/tests/installer")"; else TESTDIR="$ROOT/tests/installer"; fi MSYS_NO_PATHCONV=1 docker run --rm --platform "linux/$PLAT" --add-host host.docker.internal:host-gateway \ -v "$TESTDIR:/t:ro" "$IMAGE" \ bash /t/container-test.sh "http://host.docker.internal:8099" "$TOKEN"