diff --git a/README.md b/README.md index fb2de80..2319792 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,43 @@ -# Cekit Behave steps +# Cekit Behave steps -- Podman edition -This repository contains test steps for the [Behave library](https://github.com/behave/behave) used in the [Cekit tool](https://github.com/cekit/cekit/). +This branch is intended to be a home for work to get behave-test-steps to work +with Podman. -## Why external repository? +Ideally we will continue to work with Docker as well, but the initial priority +is Podman support even at the expense of Docker. -Because the test steps are rapidly changing by adding new steps or adjusting existing ones -it does not make sense to combine it together with Cekit releases. These do have different lifecycle. We decided to separate these and so far it's working well. +## Preparation -## Dependencies (Cekit 3.0+) +Podman v2.x+ features a REST API which is docker-compatible but also extends it +with more stuff from the libpod API. -Because test steps have different requirements and these can change over time, Cekit introduced a weak dependency mechanism (see https://github.com/cekit/cekit/pull/357 for more information). In this steps library it is implemented in the `loader.py` file which defines what dependencies are required. +See -This information will let Cekit check **at runtime** if requirements are met and if not, user will be notified. If you are running on a known platform, in case a depenency is missing, you will be provided with a hint what to install to satisfy the requirement. +Starting the API endpoint as a user + + podman system service -t 5000 # lifetime in seconds. -t 0 = forever + +socket is `/run/user/$(id -u)/podman/podman.sock` + +Note: there are packages to set this up as a replacement for the docker daemon +socket (`podman-docker` RPM). We don't rely on this because we want to support +concurrent use of podman and docker. + +You *might* have systemd sockets and services defined to start the daemon + + systemctl --user enable podman.service + systemctl --user start podman.service + + +## Testing + +Set the environment variable `CTF_API_SOCK` to a URI corresponding to the Podman +socket, e.g. + + export CTF_API_SOCK=unix:///run/user/1000/podman/podman.sock + +Run a test using cekit, e.g. + + cekit --descriptor ubi8-openjdk-11.yaml test behave --wip \ + --steps-url https://github.com/jmtd/behave-test-steps \ + --steps-ref podman diff --git a/steps/container.py b/steps/container.py index 787303d..f4d551e 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("CTF_API_SOCK", '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..fe28157 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("CTF_API_SOCK", '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}') diff --git a/steps/s2i_steps.py b/steps/s2i_steps.py index ca13e6c..e7891ea 100644 --- a/steps/s2i_steps.py +++ b/steps/s2i_steps.py @@ -29,10 +29,21 @@ 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 "" - ) + docker_url = os.environ.get("CTF_API_SOCK", 'unix:///var/run/docker.sock') + + command = f"""s2i build --loglevel=5 --pull-policy if-not-present\ + --url {docker_url}\ + {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) output = _execute(command)