From 0fd987b9ec3001c3c461ecdc98cada312f2ed1c7 Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Fri, 22 Mar 2024 11:36:57 +0000 Subject: [PATCH 1/3] configurable docker API socket via DOCKER_HOST MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DOCKER_HOST is an environment variable to describe the URI to connect to. It was originally defined and honoured by /usr/bin/docker and some bits of the python docker API (the Client API, but not the low-level API we use, alas). It's also supported by s2i. BY honouring it in behave-tests-steps, the end-user can use Podman instead of Docker, e.g. $ systemctl --user start podman.service $ export DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock $ cekit … test behave Signed-off-by: Jonathan Dowland --- steps/container.py | 3 ++- steps/image_steps.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/steps/container.py b/steps/container.py index 787303d..f7d4c8f 100644 --- a/steps/container.py +++ b/steps/container.py @@ -35,7 +35,8 @@ # A future version of Cekit will expose this to us, for now we hard-code DOCKER_API_VERSION = "1.35" -d = docker.APIClient(version=DOCKER_API_VERSION) +base_url = os.environ.get("DOCKER_HOST", 'unix:///var/run/docker.sock') +d = docker.APIClient(version=DOCKER_API_VERSION, base_url=base_url) class ExecException(Exception): diff --git a/steps/image_steps.py b/steps/image_steps.py index 01ff4a0..098bac1 100644 --- a/steps/image_steps.py +++ b/steps/image_steps.py @@ -1,3 +1,4 @@ +import os import docker @@ -6,7 +7,8 @@ # A future version of Cekit will expose this to us, for now we hard-code DOCKER_API_VERSION = "1.35" -DOCKER_CLIENT = docker.APIClient(version=DOCKER_API_VERSION) +base_url = os.environ.get("DOCKER_HOST", 'unix:///var/run/docker.sock') +DOCKER_CLIENT = docker.APIClient(version=DOCKER_API_VERSION, base_url=base_url) @then(u'the image should contain label {label}') @then(u'the image should contain label {label} {check} value {value}') From 36f8f8bac169344e04d54c20a16db6def096c035 Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Mon, 11 Nov 2024 09:43:06 +0000 Subject: [PATCH 2/3] Reformat s2i command string for clarity Use python3 f-strings so we can use the variable name directly at the substitution site and not have to keep count of the number of '%s' we've put in. Signed-off-by: Jonathan Dowland --- steps/s2i_steps.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/steps/s2i_steps.py b/steps/s2i_steps.py index ca894b4..d561237 100644 --- a/steps/s2i_steps.py +++ b/steps/s2i_steps.py @@ -29,10 +29,19 @@ def s2i_inner(context, application, path='.', env="", incremental=False, tag="ma mirror = "-e 'MAVEN_MIRROR_URL=%s'" % os.getenv("MAVEN_MIRROR_URL") image_id = "integ-" + context.image - command = "s2i build --loglevel=5 --pull-policy if-not-present %s --context-dir=%s -r=%s %s %s %s %s %s %s" % ( - mirror, path, tag, env, application, context.image, image_id, "--incremental" if incremental else "", - "--runtime-image="+runtime_image if runtime_image else "" - ) + + command = f"""s2i build --loglevel=5 --pull-policy if-not-present\ + {mirror}\ + --context-dir={path}\ + -r={tag}\ + {env}\ + {application}\ + {context.image}\ + {image_id}\ + {"--incremental" if incremental else ""}\ + {"--runtime-image="+runtime_image if runtime_image else ""}\ + """ + logger.info("Executing new S2I build with the command [%s]..." % command) success, output = _execute(command) From ac4b3a2ce1907bb569958b562b604aef8e5a058d Mon Sep 17 00:00:00 2001 From: Jonathan Dowland Date: Wed, 28 May 2025 11:25:17 +0100 Subject: [PATCH 3/3] use docker.constants.DEFAULT_UNIX_SOCKET Signed-off-by: Jonathan Dowland --- steps/container.py | 2 +- steps/image_steps.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/steps/container.py b/steps/container.py index f7d4c8f..7473868 100644 --- a/steps/container.py +++ b/steps/container.py @@ -35,7 +35,7 @@ # A future version of Cekit will expose this to us, for now we hard-code DOCKER_API_VERSION = "1.35" -base_url = os.environ.get("DOCKER_HOST", 'unix:///var/run/docker.sock') +base_url = os.environ.get("DOCKER_HOST", docker.constants.DEFAULT_UNIX_SOCKET) d = docker.APIClient(version=DOCKER_API_VERSION, base_url=base_url) diff --git a/steps/image_steps.py b/steps/image_steps.py index 098bac1..4dfbdf6 100644 --- a/steps/image_steps.py +++ b/steps/image_steps.py @@ -7,7 +7,7 @@ # A future version of Cekit will expose this to us, for now we hard-code DOCKER_API_VERSION = "1.35" -base_url = os.environ.get("DOCKER_HOST", 'unix:///var/run/docker.sock') +base_url = os.environ.get("DOCKER_HOST", docker.constants.DEFAULT_UNIX_SOCKET) DOCKER_CLIENT = docker.APIClient(version=DOCKER_API_VERSION, base_url=base_url) @then(u'the image should contain label {label}')