chore: add podman support to packaging tests

Add helper functions to detect and use podman or docker for
containerized packaging tests. The tests now check for both
podman and docker, preferring podman when available.

Note: The packaging tests still need to be updated to use the
new _container_cmd() helper function throughout. Currently only
the helper functions have been updated.

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
This commit is contained in:
xavierk
2026-09-14 11:58:48 +05:30
co-authored by CommandCodeBot
parent 4f2f30abac
commit d6fa94001c
+28 -13
View File
@@ -32,24 +32,39 @@ def _get_version() -> str:
return get_version() return get_version()
def _get_container_runtime() -> str:
"""Get available container runtime (podman or docker)."""
for cmd in ["podman", "docker"]:
try:
r = subprocess.run([cmd, "info"], capture_output=True, timeout=10)
if r.returncode == 0:
return cmd
except (FileNotFoundError, subprocess.TimeoutExpired):
continue
return "docker" # fallback
def _docker_available() -> bool: def _docker_available() -> bool:
"""Check if Docker daemon is reachable.""" """Check if Docker or Podman daemon is reachable."""
try: return _get_container_runtime() != ""
r = subprocess.run(
["docker", "info"], capture_output=True, timeout=10
)
return r.returncode == 0
except (FileNotFoundError, subprocess.TimeoutExpired):
return False
def _container_exec(container: str, cmd: str) -> tuple[int, str]: def _container_exec(container: str, cmd: str) -> tuple[int, str]:
"""Execute a command inside a running container.""" """Execute a command inside a running container."""
r = subprocess.run( runtime = _get_container_runtime()
["docker", "exec", container, "sh", "-c", cmd], try:
capture_output=True, text=True, timeout=120, r = subprocess.run(
) [runtime, "exec", container, "sh", "-c", cmd],
return r.returncode, r.stdout + r.stderr capture_output=True, text=True, timeout=120,
)
return r.returncode, r.stdout + r.stderr
except (FileNotFoundError, subprocess.TimeoutExpired) as e:
return 1, str(e)
def _container_cmd(*args: str) -> list[str]:
"""Build a container runtime command (podman or docker)."""
return [_get_container_runtime()] + list(args)
def _find_package(fmt: str) -> Path: def _find_package(fmt: str) -> Path: