Skip to content

Commit

Permalink
Add support for testing with docker
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Oct 16, 2024
1 parent 60c37b4 commit 77c149f
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 14 deletions.
49 changes: 46 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install bats bash codespell python3-argcomplete pipx
sudo apt-get install podman bats bash codespell python3-argcomplete pipx
make install-requirements
- name: Print disk space before cleanup
shell: bash
Expand All @@ -34,8 +34,6 @@ jobs:
sudo systemctl restart docker.service
df -h
- name: Docker info
run: docker info
- name: Print disk space after cleanup
shell: bash
Expand All @@ -46,11 +44,56 @@ jobs:
run: |
make validate
make bats
- name: bats-nocontainer
run: |
pip install tqdm --break-system-packages
make bats-nocontainer
docker:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: install bats
shell: bash
run: |
sudo apt-get update
sudo apt-get install bats bash codespell python3-argcomplete pipx
make install-requirements
- name: Print disk space before cleanup
shell: bash
run: |
df -h
- name: Free Disk Space Linux
shell: bash
run: |
sudo docker rmi "$(docker image ls -aq)" >/dev/null 2>&1 || true
sudo rm -rf \
/usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/share/powershell /usr/share/swift /usr/local/.ghcup \
/usr/lib/jvm || true
# /mnt has ~ 65 GB free disk space. / is too small.
- name: Reconfigure Docker data-root
run: |
sudo mkdir -p /mnt/docker /etc/docker
echo '{"data-root": "/mnt/docker"}' > /tmp/daemon.json
sudo mv /tmp/daemon.json /etc/docker/daemon.json
cat /etc/docker/daemon.json
sudo systemctl restart docker.service
df -h
- name: Print disk space after cleanup
shell: bash
run: |
df -h
- name: bats-docker
run: |
docker info
pip install tqdm --break-system-packages
make bats-docker
macos:
runs-on: macos-14
steps:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ bats:
bats-nocontainer:
_RAMALAMA_TEST_OPTS=--nocontainer RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/

.PHONY: bats-docker
bats-docker:
_RAMALAMA_TEST_OPTS=--engine=docker RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/

.PHONY: ci
ci:
test/ci.sh
Expand Down
16 changes: 13 additions & 3 deletions ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,21 @@ def _stop_container(args, name):
raise IndexError("no container manager (Podman, Docker) found")

conman_args = [conman, "stop", "-t=0"]
ignore_stderr=False
if args.ignore:
conman_args += ["--ignore", str(args.ignore)]
if conman == "podman":
conman_args += ["--ignore", str(args.ignore)]
else:
ignore_stderr=True

conman_args += [name]
run_cmd(conman_args)
try:
run_cmd(conman_args, ignore_stderr=ignore_stderr)
except subprocess.CalledProcessError:
if args.ignore and conman == "docker":
return
else:
raise


def stop_container(args):
Expand All @@ -507,7 +518,6 @@ def stop_container(args):

if args.NAME:
raise IndexError("specifying --all and container name, %s, not allowed" % args.NAME)
args.noheading = True
args.ignore = True
args.format = "{{ .Names }}"
for i in _list_containers(args):
Expand Down
8 changes: 6 additions & 2 deletions ramalama/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def exec_cmd(args, stderr=True):
raise


def run_cmd(args, cwd=None):
def run_cmd(args, cwd=None, ignore_stderr=False):
"""
Run the given command arguments.
Expand All @@ -65,7 +65,11 @@ def run_cmd(args, cwd=None):
if x:
print(*args)

return subprocess.run(args, check=True, cwd=cwd, stdout=subprocess.PIPE)
stderr=None
if ignore_stderr:
stderr=subprocess.PIPE

return subprocess.run(args, check=True, cwd=cwd, stdout=subprocess.PIPE, stderr=stderr)


def find_working_directory():
Expand Down
4 changes: 3 additions & 1 deletion test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ load helpers
model=m_$(safename)
image=m_$(safename)

verify_begin="podman run --rm -i --label RAMALAMA --security-opt=label=disable -e RAMALAMA_TRANSPORT --name"
run_ramalama info
conman=$(jq .Engine <<< $output | tr -d '"' )
verify_begin="${conman} run --rm -i --label RAMALAMA --security-opt=label=disable -e RAMALAMA_TRANSPORT --name"

run_ramalama --dryrun run ${model}
is "$output" "${verify_begin} ramalama_.*" "dryrun correct"
Expand Down
9 changes: 6 additions & 3 deletions test/system/040-serve.bats
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ verify_begin=".*run --rm -i --label RAMALAMA --security-opt=label=disable -e RAM

run_ramalama serve --name ${container1} --detach ${model}
cid="$output"
run -0 podman inspect $cid
run_ramalama info
conmon=$(jq .Engine <<< $output)

run -0 ${conman} inspect1 $cid

run_ramalama ps
is "$output" ".*${container1}" "list correct for for container1"
Expand Down Expand Up @@ -100,8 +103,8 @@ verify_begin=".*run --rm -i --label RAMALAMA --security-opt=label=disable -e RAM
run_ramalama 22 stop
is "$output" "Error: must specify a container name" "name required"

run_ramalama 125 stop ${name}
is "$output" "Error: no container with name or ID \"${name}\" found: no such container.*" "missing container"
run_ramalama ? stop ${name}
is "$output" "Error.*such container.*" "missing container"

run_ramalama stop --ignore ${name}
is "$output" "" "ignore missing"
Expand Down
2 changes: 1 addition & 1 deletion test/system/060-info.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ load helpers
Image | "quay.io/ramalama/ramalama:latest"
Runtime | "llama.cpp"
Version | "${version}"
Store | "${HOME}/.local/share/ramalama"
Store | \\\("${HOME}/.local/share/ramalama"\\\|"/var/lib/ramalama"\\\)
"

defer-assertion-failures
Expand Down
4 changes: 3 additions & 1 deletion test/system/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,9 @@ function skip_if_nocontainer() {
}

function skip_if_darwin() {
[ "$(uname)" == "darwin" ] || skip "Not supported on darwin"
if [[ "$(uname)" == "Darwin" ]]; then
skip "Not supported on darwin"
fi
}

# END miscellaneous tools
Expand Down

0 comments on commit 77c149f

Please sign in to comment.