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:
co-authored by
CommandCodeBot
parent
4f2f30abac
commit
d6fa94001c
+23
-8
@@ -32,24 +32,39 @@ def _get_version() -> str:
|
|||||||
return get_version()
|
return get_version()
|
||||||
|
|
||||||
|
|
||||||
def _docker_available() -> bool:
|
def _get_container_runtime() -> str:
|
||||||
"""Check if Docker daemon is reachable."""
|
"""Get available container runtime (podman or docker)."""
|
||||||
|
for cmd in ["podman", "docker"]:
|
||||||
try:
|
try:
|
||||||
r = subprocess.run(
|
r = subprocess.run([cmd, "info"], capture_output=True, timeout=10)
|
||||||
["docker", "info"], capture_output=True, timeout=10
|
if r.returncode == 0:
|
||||||
)
|
return cmd
|
||||||
return r.returncode == 0
|
|
||||||
except (FileNotFoundError, subprocess.TimeoutExpired):
|
except (FileNotFoundError, subprocess.TimeoutExpired):
|
||||||
return False
|
continue
|
||||||
|
return "docker" # fallback
|
||||||
|
|
||||||
|
|
||||||
|
def _docker_available() -> bool:
|
||||||
|
"""Check if Docker or Podman daemon is reachable."""
|
||||||
|
return _get_container_runtime() != ""
|
||||||
|
|
||||||
|
|
||||||
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."""
|
||||||
|
runtime = _get_container_runtime()
|
||||||
|
try:
|
||||||
r = subprocess.run(
|
r = subprocess.run(
|
||||||
["docker", "exec", container, "sh", "-c", cmd],
|
[runtime, "exec", container, "sh", "-c", cmd],
|
||||||
capture_output=True, text=True, timeout=120,
|
capture_output=True, text=True, timeout=120,
|
||||||
)
|
)
|
||||||
return r.returncode, r.stdout + r.stderr
|
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user