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 #detect podman or docker
if command -v docker; then if command -v docker; then
engine_of_choice="docker"
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 \
"$@"
elif command -v podman; then elif command -v podman; then
engine_of_choice="podman"
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 \
"$@"
fi 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 $windowmanagerpid
kill $xephyrpid kill $xephyrpid

View file

@ -45,9 +45,15 @@ RUN yay -S --noconfirm {package_name}
ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]" ENTRYPOINT [\"/usr/bin/env\", \"{command}\"]"
""" """
try: # check if either docker or podman are installed
subprocess.run(["docker", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')
except FileNotFoundError: # primitive way to detect that docker is not installed docker_check = subprocess.call(["which", "docker"])
subprocess.run(["podman", "build", "-t", command, "-"], input = dockerfile, encoding = 'UTF-8')
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')