Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container support in buildspecs for docker, podman and singularity #1642

Merged
merged 9 commits into from
Oct 13, 2023
Merged
32 changes: 31 additions & 1 deletion buildtest/builders/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,37 @@ def generate_script(self):
lines += self.compiler_settings["modules"]

lines.append("# Content of run section")

if "container" in self.recipe:
container = self.recipe["container"]
container_platform = container["platform"]
container_command = []
if container_platform in ["docker", "podman"]:
container_command.extend(
[container_platform, "run", "-v", f"{self.stage_dir}:/buildtest"]
)

elif container_platform in ["singularity"]:
container_command.extend(
[f"{container_platform}", "exec", f"-B {self.stage_dir}:/buildtest"]
)

if container.get("mounts"):
if container_platform in ["singularity"]:
container_command.extend(["-B", container["mounts"]])
else:
container_command.extend(["-v", container["mounts"]])

if container.get("options"):
container_command.append(container["options"])

container_command.append(container["image"])

if container.get("command"):
container_command.append(container["command"])

lines.append(" ".join(container_command))

# Add run section
lines += [self.recipe["run"]]

return lines
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
buildspecs:
invalid_container_platform:
type: script
executor: generic.local.bash
description: invalid container platform
container:
platform: "containerd"
image: hello-world
run: echo 'Test Complete!'
34 changes: 34 additions & 0 deletions buildtest/schemas/script.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,40 @@
}
}
}
},
"container": {
"type": "object",
"required": [
"image",
"platform"
],
"properties": {
"platform": {
"type": "string",
"description": "Specify a container platform to use when running test. This is used for running commands inside container.",
"enum": [
"docker",
"podman",
"singularity"
]
},
"image": {
"type": "string",
"description": "Specify a container image to use when running test. This is used for running commands inside container."
},
"mounts": {
"type": "string",
"description": "Specify a list of directory paths to bind mount into the container"
},
"options": {
"type": "string",
"description": "Specify a list of options to pass to container runtime. "
},
"command": {
"type": "string",
"description": "Specify a list of commands to run inside container. This is used for running commands inside container."
}
}
}
},
"definitions": {
Expand Down
8 changes: 5 additions & 3 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ Shown below is a sample output where we query 5 records from the buildspec cache

.. command-output:: buildtest buildspec find --format name --terse --no-header --count=5

To get all tests in buildspec cache, consider setting to any negative value `--count=-1` or a really high number.
To get all tests in buildspec cache, consider setting to any negative value ``--count=-1`` or a really high number.

Unable to query test details
------------------------------

Let's say you are trying to query a test name `hello_world`, and you get an error message such as following
Let's say you are trying to query a test name ``hello_world``, and you get an error message such as following

.. code-block:: console

Expand All @@ -128,7 +128,7 @@ Unable to query all test results
---------------------------------

If you run into situation where you are unable to query all test results,
you should check the buildtest configuration file see :ref:`configuring_buildtest_report`_. In this section, check if
you should check the buildtest configuration file see :ref:`configuring_buildtest_report`. In this section, check if
``count`` property is set in configuration file. For instance if you have ``count: 25``, everytime you run ``buildtest report`` it
will query 25 records

Expand All @@ -148,6 +148,8 @@ You can work around this issue by passing ``--count`` on command line and it wil
To retrieve all content you can specify a negative value and buildtest will fetch all records or alternatively you
can specify a really high number

.. code-block:: console

 buildtest report --terse --no-header --count=-1 | wc -l
30

Expand Down
3 changes: 2 additions & 1 deletion docs/writing_buildspecs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Writing Buildspecs
writing_buildspecs/performance_checks
writing_buildspecs/test_dependency
writing_buildspecs/multi_executor
writing_buildspecs/customize_shell
writing_buildspecs/customize_shell
writing_buildspecs/containers
Loading