Skip to content

Commit 84a3a0a

Browse files
committed
add suport for running bats in a container
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]>
1 parent b216516 commit 84a3a0a

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PATH := $(PATH):$(HOME)/.local/bin
1010
IMAGE ?= ramalama
1111
PYTHON_FILES := $(shell find . -path "./.venv" -prune -o -name "*.py" -print) $(shell find . -name ".venv" -prune -o -type f -perm +111 -exec grep -l "^\#!/usr/bin/env python3" {} \; 2>/dev/null || true)
1212
PYTEST_COMMON_CMD ?= PYTHONPATH=. pytest test/unit/ -vv
13+
BATS_IMAGE ?= localhost/bats:latest
1314

1415
default: help
1516

@@ -161,6 +162,30 @@ bats-nocontainer:
161162
bats-docker:
162163
_RAMALAMA_TEST_OPTS=--engine=docker RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/
163164

165+
.PHONY: bats-image
166+
bats-image:
167+
podman inspect $(BATS_IMAGE) &> /dev/null || \
168+
podman build -t $(BATS_IMAGE) container-images/bats
169+
170+
.PHONY: bats-in-container
171+
bats-in-container: bats-image
172+
podman run -it --rm \
173+
--userns=keep-id:size=200000 \
174+
--security-opt unmask=/proc/* \
175+
--security-opt label=disable \
176+
--security-opt=mask=/sys/bus/pci/drivers/i915 \
177+
--device /dev/net/tun \
178+
-v $(CURDIR):/src \
179+
$(BATS_IMAGE) make bats
180+
181+
.PHONY: bats-nocontainer-in-container
182+
bats-nocontainer-in-container: bats-image
183+
podman run -it --rm \
184+
--userns=keep-id:size=200000 \
185+
--security-opt=mask=/sys/bus/pci/drivers/i915 \
186+
-v $(CURDIR):/src \
187+
$(BATS_IMAGE) make bats-nocontainer
188+
164189
.PHONY: ci
165190
ci:
166191
test/ci.sh

container-images/bats/Containerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM quay.io/fedora/fedora:42
2+
3+
ENV HOME=/tmp \
4+
XDG_RUNTIME_DIR=/tmp \
5+
STORAGE_DRIVER=vfs
6+
WORKDIR /src
7+
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
8+
9+
RUN dnf -y install make bats jq iproute podman openssl httpd-tools \
10+
ollama python3-huggingface-hub \
11+
# for building llama-bench
12+
git-core cmake gcc-c++ curl-devel && \
13+
dnf -y clean all
14+
RUN rpm --restore shadow-utils
15+
RUN git clone --depth=1 https://github.com/ggml-org/llama.cpp && \
16+
pushd llama.cpp && \
17+
cmake -B build -DGGML_NATIVE=OFF -DGGML_RPC=ON -DGGML_CCACHE=OFF -DGGML_CMAKE_BUILD_TYPE=Release -DLLAMA_CURL=ON -DCMAKE_INSTALL_PREFIX=/usr && \
18+
cmake --build build --config Release --parallel $(nproc) && \
19+
cmake --install build && \
20+
popd && rm -rf llama.cpp
21+
22+
COPY entrypoint.sh /usr/bin
23+
COPY containers.conf /etc/containers
24+
RUN chmod a+rw /etc/subuid /etc/subgid

container-images/bats/containers.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[containers]
2+
utsns="host"
3+
cgroups="disabled"
4+
log_driver="k8s-file"
5+
6+
[engine]
7+
events_logger="file"
8+
infra_image="quay.io/libpod/k8s-pause:3.5"

container-images/bats/entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
echo $(id -u):10000:100000 > /etc/subuid
4+
echo $(id -g):10000:100000 > /etc/subgid
5+
6+
if [ $# -gt 0 ]; then
7+
exec "$@"
8+
else
9+
exec /bin/bash
10+
fi

container_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ build() {
116116
echo "${conman_show_size[@]}"
117117
"${conman_show_size[@]}"
118118
case ${target} in
119-
ramalama-cli | llama-stack | openvino)
119+
ramalama-cli | llama-stack | openvino | bats)
120120
;;
121121
*)
122122
add_entrypoints "${conman[@]}" "${REGISTRY_PATH}"/"${target}" "${version}"

0 commit comments

Comments
 (0)