Skip to content

Commit

Permalink
Merge pull request #64 from nathantypanski/ndt/basic-podman-support
Browse files Browse the repository at this point in the history
Add basic Podman support
  • Loading branch information
woodruffw committed Jun 29, 2022
2 parents 275bfc0 + 9c32759 commit 67dc3f4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion it_depends/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import subprocess
import sys
import os
from pathlib import Path
from tempfile import mkdtemp
from tqdm import tqdm
Expand Down Expand Up @@ -246,7 +247,8 @@ def rebuild(self, nocache: bool = False):
raise ValueError("Could not find the Dockerfile.")
# use the low-level APIClient so we can get streaming build status
try:
cli = docker.APIClient()
sock = self._try_podman_socket()
cli = docker.APIClient(base_url=sock)
except DockerException as e:
raise ValueError("Docker not installed. Try `sudo apt install docker`.") from e
with tqdm(desc="Archiving the build directory", unit=" steps", leave=False) as t:
Expand Down Expand Up @@ -281,3 +283,24 @@ def rebuild(self, nocache: bool = False):
t.update(new_line - last_line)
last_line = new_line
t.write(line["stream"].replace("\n", "").strip())

def _try_podman_socket(self):
"""Try to find a podman socket. If it fails, use Docker default.
First try to construct the Docker socket via the podman rootless
socket path. Failing that, fallback to Docker library defaults with
base_url=None.
This isn't as robust as it could be, but it should work on systems
using either rootless podman or Docker.
"""
runtime_dir = os.environ.get("XDG_RUNTIME_DIR", None)
if runtime_dir is None:
# We're not gonna find it without XDG's help; fallback to Docker.
return None
sock_path = Path(f'{runtime_dir}/podman/podman.sock')
if sock_path.exists():
sock = f'unix://{sock_path}'
if not sock_path.exists():
sock = None
return sock

0 comments on commit 67dc3f4

Please sign in to comment.