cleaned up podman/docker detection

This commit is contained in:
Stefano C. Coronado 2019-12-28 19:38:58 -05:00
parent 65725888c7
commit acdbb116fb
2 changed files with 24 additions and 27 deletions

View file

@ -43,32 +43,23 @@ windowmanagerpid=$!
#detect podman or docker
if command -v docker; then
docker run --net=host \
--rm \
-e DISPLAY=:$DNum \
-v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \
--user $(id -u):$(id -g) \
--group-add audio \
--cap-drop=ALL \
--shm-size 2g \
"$@"
engine_of_choice="docker"
elif command -v podman; then
podman run --net=host \
--rm \
-e DISPLAY=:$DNum \
-v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \
--user $(id -u):$(id -g) \
--group-add audio \
--cap-drop=ALL \
--shm-size 2g \
"$@"
engine_of_choice="podman"
fi
# then run the detected container engine
$engine_of_choice run --net=host \
--rm \
-e DISPLAY=:$DNum \
-v /tmp/.X11-unix/X$DNum:/tmp/.X11-unix/X$DNum:rw \
--user $(id -u):$(id -g) \
--group-add audio \
--cap-drop=ALL \
--shm-size 2g \
"$@"
kill $windowmanagerpid
kill $xephyrpid

View file

@ -45,9 +45,15 @@ RUN yay -S --noconfirm {package_name}
ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]"
"""
try:
subprocess.run(["docker", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')
# check if either docker or podman are installed
except FileNotFoundError: # primitive way to detect that docker is not installed
subprocess.run(["podman", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')
docker_check = subprocess.call(["which", "docker"])
if docker_check != 0:
print("Docker not installed, building with Podman")
engine = "podman"
else:
engine = "docker"
subprocess.run([engine, "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')