Skip to content

Commit

Permalink
Added artexplainer rock and tests (#102)
Browse files Browse the repository at this point in the history
* Update artexplainer/tests/test_rock.py

Co-authored-by: Daniela Plascencia <[email protected]>
  • Loading branch information
BON4 and DnPlas authored Jan 15, 2025
1 parent 06cf444 commit a6741d4
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 0 deletions.
11 changes: 11 additions & 0 deletions artexplainer/dummy_pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.poetry]
name = "workaround-for-editable-install"
version = "0.0.1"
description = ""
authors = ["none"]

[tool.poetry.dependencies]
# This range should match that used upstream: https://github.com/kserve/kserve/blob/v0.11.2/python/artexplainer/pyproject.toml#L13
python = ">=3.9,<3.12"
kserve = { path = "../python/kserve", develop = false }
artserver = { path = "../python/artexplainer", develop = false }
72 changes: 72 additions & 0 deletions artexplainer/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Based on https://github.com/kserve/kserve/blob/v0.13.0/python/artexplainer.Dockerfile
#
# See ../CONTRIBUTING.md for more details about the patterns used in this rock.
# This rock is implemented with some atypical patterns due to the native of the upstream
# Dockerfile.
name: artexplainer
summary: Art server for Kserve deployments
description: "Kserve Art server"
version: "0.13.0"
license: Apache-2.0
base: [email protected]
run-user: _daemon_
platforms:
amd64:
services:
artserver:
override: replace
summary: "Art server service"
startup: enabled
command: "python -m artserver [ ]"
entrypoint-service: artserver

parts:
security-team-requirement:
plugin: nil
override-build: |
mkdir -p ${CRAFT_PART_INSTALL}/usr/share/rocks
(echo "# os-release" && cat /etc/os-release && echo "# dpkg-query" && \
dpkg-query --root=${CRAFT_PROJECT_DIR}/../bundles/ubuntu-22.04/rootfs/ -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) \
> ${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query
python:
plugin: nil
source: https://github.com/kserve/kserve.git
source-subdir: python
source-tag: v0.13.0
build-packages:
- build-essential
- libgomp1
overlay-packages:
- python3.10
- python3-pip
override-build: |
pip install poetry==1.7.1
poetry config virtualenvs.create false
# Install the kserve package, this specific server package, and their dependencies.
mkdir -p ./python_env_builddir
cp -rf $CRAFT_PROJECT_DIR/dummy_pyproject.toml ./python_env_builddir/pyproject.toml
(cd python_env_builddir && poetry install --no-interaction --no-root)
# Promote the packages we've installed from the local env to the primed image
mkdir -p $CRAFT_PART_INSTALL/usr/local/lib/python3.10/dist-packages
cp -fr /usr/local/lib/python3.10/dist-packages/* $CRAFT_PART_INSTALL/usr/local/lib/python3.10/dist-packages/
mkdir -p $CRAFT_PART_INSTALL/usr/local/share
cp -fr /usr/local/share/* $CRAFT_PART_INSTALL/usr/local/share/
# Ensure `python` is an executable command in our primed image by making
# a symbolic link
mkdir -p $CRAFT_PART_INSTALL/usr/bin/
ln -s /usr/bin/python3.10 $CRAFT_PART_INSTALL/usr/bin/python
# Copy licenses
third-party:
plugin: nil
after: [python]
source: https://github.com/kserve/kserve.git
source-subdir: python
source-tag: v0.13.0
override-build: |
cp -fr third_party/* ${CRAFT_PART_INSTALL}/third_party
57 changes: 57 additions & 0 deletions artexplainer/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import random
import pytest
import string
import subprocess

from charmed_kubeflow_chisme.rock import CheckRock


@pytest.mark.abort_on_fail
def test_rock():
"""Test rock."""
check_rock = CheckRock("rockcraft.yaml")
rock_image = check_rock.get_name()
rock_version = check_rock.get_version()
LOCAL_ROCK_IMAGE = f"{rock_image}:{rock_version}"

# assert we have the expected files
subprocess.run(
[
"docker",
"run",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /usr/local/lib/python3.10/dist-packages/artserver",
],
check=True,
)
subprocess.run(
[
"docker",
"run",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /usr/local/lib/python3.10/dist-packages/kserve",
],
check=True,
)
subprocess.run(
[
"docker",
"run",
"--entrypoint",
"/bin/bash",
LOCAL_ROCK_IMAGE,
"-c",
"ls -la /third_party",
],
check=True,
)

54 changes: 54 additions & 0 deletions artexplainer/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist = pack, export-to-docker, sanity, integration

[testenv]
setenv =
PYTHONPATH={toxinidir}
PYTHONBREAKPOINT=ipdb.set_trace
CHARM_REPO=https://github.com/canonical/kserve-operators.git
CHARM_BRANCH=main
LOCAL_CHARM_DIR=charm_repo

[testenv:pack]
passenv = *
allowlist_externals =
rockcraft
commands =
rockcraft pack

[testenv:export-to-docker]
passenv = *
allowlist_externals =
bash
skopeo
yq
commands =
# pack rock and export to docker
bash -c 'NAME=$(yq eval .name rockcraft.yaml) && \
VERSION=$(yq eval .version rockcraft.yaml) && \
ARCH=$(yq eval ".platforms | keys | .[0]" rockcraft.yaml) && \
ROCK="$\{NAME\}_$\{VERSION\}_$\{ARCH\}.rock" && \
DOCKER_IMAGE=$NAME:$VERSION && \
echo "Exporting $ROCK to docker as $DOCKER_IMAGE" && \
skopeo --insecure-policy copy oci-archive:$ROCK docker-daemon:$DOCKER_IMAGE'

[testenv:sanity]
passenv = *
deps =
pytest
charmed-kubeflow-chisme
commands =
# run rock tests
pytest -s -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests

[testenv:integration]
passenv = *
allowlist_externals =
echo
commands =
# TODO: Implement integration tests here
echo "WARNING: This is a placeholder test - no test is implemented here."

0 comments on commit a6741d4

Please sign in to comment.