build-unit-test-docker: support podman
Some of our systems utilize podman so ensure this script works for both
docker and podman based systems.
Tested:
- Confirmed still builds on a docker installed Ubuntu server
- Confirmed it now builds on a podman installed Red Hat server
Change-Id: I6f72cf43b32e7f6b9b600b027189a2dcf985f364
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/scripts/build-unit-test-docker b/scripts/build-unit-test-docker
index 79e75dd..1f23413 100755
--- a/scripts/build-unit-test-docker
+++ b/scripts/build-unit-test-docker
@@ -35,7 +35,21 @@
# typing.Dict is used for type-hints.
from typing import Any, Callable, Dict, Iterable, Optional # noqa: F401
-from sh import docker, git, nproc # type: ignore
+from sh import git, nproc # type: ignore
+
+try:
+ # System may have docker or it may have podman, try docker first
+ from sh import docker
+
+ container = docker
+except ImportError:
+ try:
+ from sh import podman
+
+ container = podman
+ except Exception:
+ print("No docker or podman found on system")
+ exit(1)
try:
# Python before 3.8 doesn't have TypedDict, so reroute to standard 'dict'.
@@ -661,7 +675,9 @@
# If we're not forcing builds, check if it already exists and skip.
if not force_build:
- if docker.image.ls(tag, "--format", '"{{.Repository}}:{{.Tag}}"'):
+ if container.image.ls(
+ tag, "--format", '"{{.Repository}}:{{.Tag}}"'
+ ):
print(
f"Image {tag} already exists. Skipping.", file=sys.stderr
)
@@ -676,7 +692,7 @@
# Other unusual flags:
# --no-cache: Bypass the Docker cache if 'force_build'.
# --force-rm: Clean up Docker processes if they fail.
- docker.build(
+ container.build(
proxy_args,
"--network=host",
"--force-rm",