#!/usr/bin/env python3 """Run GoOmni's repeatable Linux checks inside a pinned Go Docker image.""" import argparse from pathlib import Path import shutil import shlex import subprocess import sys def workspace_output(root: Path, value: str) -> tuple[Path, str]: requested = Path(value) host_path = requested if requested.is_absolute() else root / requested host_path = host_path.resolve() try: relative = host_path.relative_to(root) except ValueError as exc: raise SystemExit("--output must be inside the repository") from exc host_path.parent.mkdir(parents=True, exist_ok=True) return host_path, "/workspace/" + relative.as_posix() def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--image", default="golang:1.25", help="Docker image (default: golang:1.25)") parser.add_argument("--gomaxprocs", type=int, default=4) parser.add_argument("--load", action="store_true", help="also run the isolated server matrix") parser.add_argument("--tls", action="store_true", help="run the load matrix over TLS") parser.add_argument("--duration", default="2s", help="duration per traffic case (up to 30m)") parser.add_argument("--count", type=int, default=3) parser.add_argument("--concurrency", default="1,32,128") parser.add_argument("--idle", default="128,1024") parser.add_argument("--output", help="JSON report path inside the repository") args = parser.parse_args() if args.gomaxprocs < 1 or args.count < 1: parser.error("--gomaxprocs and --count must be positive") if args.tls and not args.load: parser.error("--tls requires --load") root = Path(__file__).resolve().parent.parent docker = shutil.which("docker") if docker is None: raise SystemExit("docker is required for Linux verification") commands = [ "go test -race ./...", "go vet ./...", "go build ./...", ] if args.load: load = [ "go", "run", "./internal/perfcheck", "--duration", args.duration, "--count", str(args.count), "--concurrency", args.concurrency, "--idle", args.idle, ] if args.tls: load.append("--tls") if args.output: _, container_path = workspace_output(root, args.output) load += ["--output", container_path] commands.append(" ".join(shlex.quote(part) for part in load)) command = " && ".join(commands) docker_args = [ docker, "run", "--rm", "--pull=missing", "-v", f"{root}:/workspace", "-w", "/workspace", "-e", "GOWORK=off", "-e", f"GOMAXPROCS={args.gomaxprocs}", args.image, "sh", "-c", command, ] print(f"Linux verification image: {args.image}", flush=True) print(f"Linux verification command: {command}", flush=True) result = subprocess.run(docker_args, cwd=root) if result.returncode != 0: raise SystemExit(f"Linux verification failed with exit code {result.returncode}") print("PASS Linux verification", flush=True) if __name__ == "__main__": main()