From 25ff9cc77e60225bc29d8fae379771a91bc506e2 Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Thu, 13 Jun 2024 19:05:14 +0200 Subject: [PATCH 1/2] support for non-default docker host added --- conan/internal/runner/docker.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/conan/internal/runner/docker.py b/conan/internal/runner/docker.py index 167e4ba4ef6..e50ef20f951 100644 --- a/conan/internal/runner/docker.py +++ b/conan/internal/runner/docker.py @@ -64,13 +64,28 @@ def __init__(self, conan_api, command, host_profile, build_profile, args, raw_ar import docker import docker.api.build try: - self.docker_client = docker.from_env() - self.docker_api = docker.APIClient() + try: + self.docker_client = docker.from_env() + self.docker_api = docker.APIClient() + except: + docker_base_urls = [ + os.environ.get('CONAN_RUNNER_DOCKER_HOST'), + os.environ.get('DOCKER_HOST'), + 'unix:///var/run/docker.sock', + f'unix://{os.path.expanduser("~")}/.rd/docker.sock' + ] + for base_url in docker_base_urls: + try: + self.docker_client = docker.DockerClient(base_url=base_url, version='auto') + break + except: + continue + self.docker_api = self.docker_client.api docker.api.build.process_dockerfile = lambda dockerfile, path: ('Dockerfile', dockerfile) except: raise ConanException("Docker Client failed to initialize." "\n - Check if docker is installed and running" - "\n - Run 'pip install pip install conan[runners]'") + "\n - Run 'pip install conan[runners]'") self.conan_api = conan_api self.build_profile = build_profile self.args = args From ad00df0aea94f65a8786948d0a63bf620569d26a Mon Sep 17 00:00:00 2001 From: David Sanchez Date: Tue, 2 Jul 2024 13:06:44 +0200 Subject: [PATCH 2/2] get docker client updated --- conan/internal/runner/docker.py | 32 ++++++++++++------------- test/integration/command/runner_test.py | 5 +++- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/conan/internal/runner/docker.py b/conan/internal/runner/docker.py index e50ef20f951..13c43674a3e 100644 --- a/conan/internal/runner/docker.py +++ b/conan/internal/runner/docker.py @@ -64,23 +64,21 @@ def __init__(self, conan_api, command, host_profile, build_profile, args, raw_ar import docker import docker.api.build try: - try: - self.docker_client = docker.from_env() - self.docker_api = docker.APIClient() - except: - docker_base_urls = [ - os.environ.get('CONAN_RUNNER_DOCKER_HOST'), - os.environ.get('DOCKER_HOST'), - 'unix:///var/run/docker.sock', - f'unix://{os.path.expanduser("~")}/.rd/docker.sock' - ] - for base_url in docker_base_urls: - try: - self.docker_client = docker.DockerClient(base_url=base_url, version='auto') - break - except: - continue - self.docker_api = self.docker_client.api + docker_base_urls = [ + None, # Default docker configuration, let the python library detect the socket + os.environ.get('DOCKER_HOST'), # Connect to socket defined in DOCKER_HOST + 'unix:///var/run/docker.sock', # Default linux socket + f'unix://{os.path.expanduser("~")}/.rd/docker.sock' # Rancher linux socket + ] + for base_url in docker_base_urls: + try: + ConanOutput().verbose(f'Trying to connect to docker "{base_url or "default"}" socket') + self.docker_client = docker.DockerClient(base_url=base_url, version='auto') + ConanOutput().verbose(f'Connected to docker "{base_url or "default"}" socket') + break + except: + continue + self.docker_api = self.docker_client.api docker.api.build.process_dockerfile = lambda dockerfile, path: ('Dockerfile', dockerfile) except: raise ConanException("Docker Client failed to initialize." diff --git a/test/integration/command/runner_test.py b/test/integration/command/runner_test.py index 6071b71098e..476f2cbbfc5 100644 --- a/test/integration/command/runner_test.py +++ b/test/integration/command/runner_test.py @@ -9,7 +9,10 @@ def docker_skip(test_image=None): try: - docker_client = docker.from_env() + try: + docker_client = docker.from_env() + except: + docker_client = docker.DockerClient(base_url=f'unix://{os.path.expanduser("~")}/.rd/docker.sock', version='auto') # Rancher if test_image: docker_client.images.pull(test_image) except docker.errors.DockerException: