Skip to content

add support for running bats in a container #1598

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

Merged
merged 3 commits into from
Jun 26, 2025
Merged

add support for running bats in a container #1598

merged 3 commits into from
Jun 26, 2025

Conversation

mikebonnet
Copy link
Collaborator

@mikebonnet mikebonnet commented Jun 24, 2025

The bats-in-container and bats-nocontainer-in-container will run the bats tests in a local container. In the case of bats-container, this uses podman-in-podman to run the test suite as realistically as possible.

Also includes a new --dri option to ramalama serve --api llama-stack, to allow disabling mounting /dev/dri into the container. This is required for podman-in-podman to work.

This is a prerequisite to getting bats tests running in Konflux on each pull request, and working around the out-of-space issues in the current CI setup.

Summary by Sourcery

Add support for running the BATS test suite inside a Podman container and make DRI mounting configurable for llama-stack containers.

New Features:

  • Introduce bats-image, bats-in-container, and bats-nocontainer-in-container Makefile targets to build and run BATS tests in a container.
  • Add a --dri CLI flag to ramalama serve --api llama-stack to enable or disable mounting /dev/dri into the container.

Enhancements:

  • Provide a Containerfile, entrypoint script, and containers.conf to build a dedicated bats test image.
  • Exclude the bats container definition directory in container_build.sh.

Tests:

  • Update the system test for llama-stack serve to include the --dri off option when verifying endpoints.

Copy link
Contributor

sourcery-ai bot commented Jun 24, 2025

Reviewer's Guide

Adds support for running BATS tests inside a local container using Podman-in-Podman, including new Makefile targets and a container image, and introduces a --dri option in ramalama to toggle /dev/dri mounts in the generated stack, with related updates to system tests and container build scripts.

Class diagram for updated ramalama stack and CLI options

classDiagram
    class StackArgs {
        dri: str = "on"
    }
    class Stack {
        +args: StackArgs
        +model_type: str
        +model_path: str
        +add_label(label)
        +generate()
    }
    class CLI {
        +runtime_options(parser, command)
    }
    Stack --> StackArgs
    CLI ..> StackArgs : adds --dri option
    Stack : generate() now conditionally mounts /dev/dri based on args.dri
Loading

Flow diagram for Makefile BATS-in-container targets

flowchart TD
    bats-in-container --> bats-image
    bats-image -->|if not exists| BuildBATSImage["podman build container-images/bats"]
    bats-in-container -->|run| PodmanRunBATS["podman run bats:latest make bats"]
    bats-nocontainer-in-container --> bats-image
    bats-nocontainer-in-container -->|run| PodmanRunNoContainer["podman run bats:latest make bats-nocontainer"]
Loading

File-Level Changes

Change Details Files
Introduce Makefile targets for containerized BATS execution
  • Define BATS_IMAGE variable
  • Add bats-image target to build the BATS container
  • Add bats-in-container and bats-nocontainer-in-container targets
Makefile
Update container build script to skip the BATS image directory
  • Extend skip pattern to include 'bats' in container_build.sh
container_build.sh
Add BATS container image artifacts
  • Create Containerfile for BATS image
  • Add entrypoint.sh for container runtime setup
  • Add containers.conf for Podman configuration
container-images/bats/Containerfile
container-images/bats/entrypoint.sh
container-images/bats/containers.conf
Introduce --dri option and conditional /dev/dri volume mounting
  • Add --dri flag to CLI with choices on/off
  • Update stack.generate() to include /dev/dri mounts only when args.dri is on
  • Adjust volume definitions for OCI and non-OCI models
  • Modify system test to pass --dri off in serve command
ramalama/cli.py
ramalama/stack.py
test/system/040-serve.bats

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @mikebonnet, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances our testing infrastructure by enabling BATS system tests to run within containers, addressing CI stability concerns. It also introduces a new command-line option to manage device mounting for better compatibility with containerized environments.

Highlights

  • Containerized BATS Tests: I've added new Makefile targets (bats-image, bats-in-container, bats-nocontainer-in-container) and a dedicated container image (container-images/bats) to enable running BATS system tests within a containerized environment, including support for Podman-in-Podman.
  • New --dri Option for ramalama serve: I've introduced a --dri option to ramalama serve --api llama-stack to allow explicit control over mounting /dev/dri into the container. This is crucial for environments like Podman-in-Podman where /dev/dri mounting can cause conflicts.
  • CI/CD Improvement Prerequisite: These changes are a prerequisite for integrating BATS tests into Konflux CI, aiming to resolve existing out-of-space issues and improve test reliability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mikebonnet - I've reviewed your changes - here's some feedback:

  • In ramalama/stack.py the volume_mounts and volumes strings are built via repeated concatenation, consider refactoring into a list or helper function to reduce duplication and improve readability.
  • The bats-in-container and bats-nocontainer-in-container Makefile targets share nearly identical podman flags—extract those options into a variable to avoid drift between the two recipes.
  • Defaulting BATS_IMAGE to “localhost/bats:latest” can lead to non‐reproducible builds; consider making the tag configurable or pinning to a specific version/digest.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In ramalama/stack.py the volume_mounts and volumes strings are built via repeated concatenation, consider refactoring into a list or helper function to reduce duplication and improve readability.
- The bats-in-container and bats-nocontainer-in-container Makefile targets share nearly identical podman flags—extract those options into a variable to avoid drift between the two recipes.
- Defaulting BATS_IMAGE to “localhost/bats:latest” can lead to non‐reproducible builds; consider making the tag configurable or pinning to a specific version/digest.

## Individual Comments

### Comment 1
<location> `container_build.sh:212` </location>
<code_context>
   for i in ./container-images/*; do
     i=$(basename "$i")
     # skip these directories
-    if [[ "$i" =~ ^(scripts|ramalama)$ ]]; then
+    if [[ "$i" =~ ^(scripts|ramalama|bats)$ ]]; then
       continue
     fi
</code_context>

<issue_to_address>
Excluding 'bats' from processing may need a comment for future maintainers.

If the reason for excluding 'bats' isn't documented, please add a brief explanation for clarity.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds valuable support for running BATS tests in a container, which will improve CI reliability. The addition of the --dri flag for configurable GPU device mounting is also a welcome enhancement.

I've provided a couple of suggestions: one to optimize the new test container's Containerfile for better efficiency and a smaller image size, and another to fix a potential shell scripting bug in the entrypoint.sh. Overall, this is a great contribution.

@taronaeo
Copy link
Collaborator

LGTM but we should fix the CI errors first :)

@mikebonnet mikebonnet force-pushed the bats-container branch 2 times, most recently from 23d7216 to b6fddea Compare June 25, 2025 18:22
Add the --dri option to disable mounting /dev/dri into the container when running "ramalama serve --api llama-stack".
Update bats test to pass "--dri off".

Signed-off-by: Mike Bonnet <[email protected]>
Add a new "bats" container which is configured to run the bats tests.
The container supports running the standard bats test suite
(container-in-container) as well as the "--nocontainer" tests.

Add two new Makefile targets for running the bats container via podman.

Signed-off-by: Mike Bonnet <[email protected]>
@rhatdan
Copy link
Member

rhatdan commented Jun 26, 2025

LGTM

@rhatdan rhatdan merged commit d4e76d3 into main Jun 26, 2025
25 of 31 checks passed
@mikebonnet mikebonnet deleted the bats-container branch June 26, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants