From 286d4a85fb40b681942e23341ba146051250c239 Mon Sep 17 00:00:00 2001 From: Orfeas Kourkakis Date: Mon, 22 Apr 2024 11:15:50 +0300 Subject: [PATCH] feat: Add metadata-writer ROCK (#68) * Add ROCK used by kfp-metadata-writer charm. * Add basic sanity tests for files in built image. * Add tox.ini file. Ref #66 --- .gitignore | 1 + metadata-writer/rockcraft.yaml | 59 ++++++++++++++++++++++++++++++ metadata-writer/tests/test_rock.py | 45 +++++++++++++++++++++++ metadata-writer/tox.ini | 53 +++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 metadata-writer/rockcraft.yaml create mode 100644 metadata-writer/tests/test_rock.py create mode 100644 metadata-writer/tox.ini diff --git a/.gitignore b/.gitignore index 0238a8a..3eab5ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ venv charm_repo *.rock *.tar +__pycache__ diff --git a/metadata-writer/rockcraft.yaml b/metadata-writer/rockcraft.yaml new file mode 100644 index 0000000..1c9d920 --- /dev/null +++ b/metadata-writer/rockcraft.yaml @@ -0,0 +1,59 @@ +# Dockerfile: https://github.com/kubeflow/pipelines/blob/2.0.3/backend/metadata_writer/Dockerfile +name: metadata-writer +summary: Reusable end-to-end ML workflows built using the Kubeflow Pipelines SDK +description: | + This service logs the metadata for KFP components and pipelines. +version: 2.0.3 +license: Apache-2.0 +base: ubuntu@22.04 +run-user: _daemon_ +services: + controller: + override: replace + summary: "Entry point for kfp-metadata-writer oci-image" + command: python3 -u /kfp/metadata_writer/metadata_writer.py + startup: enabled +platforms: + amd64: + +package-repositories: + - type: apt + ppa: deadsnakes/ppa + priority: always + +parts: + python: + plugin: python + source: https://github.com/kubeflow/pipelines.git + source-subdir: backend/metadata_writer + source-tag: 2.0.3 + stage-packages: + # sync this python version to the base image in the Dockerfile. + # Also keep this in sync with PARTS_PYTHON_INTERPRETER below. + - python3.8-venv + python-requirements: + - requirements.txt + build-environment: + - PARTS_PYTHON_INTERPRETER: python3.8 + + python3-is-python3.8: + plugin: nil + override-build: | + # Ensure `python3` 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.8 $CRAFT_PART_INSTALL/usr/bin/python3 + + copy-files: + plugin: nil + source: https://github.com/kubeflow/pipelines.git + source-tag: 2.0.3 + override-build: | + mkdir -p ${CRAFT_PART_INSTALL}/kfp/metadata_writer/ + cp ${CRAFT_PART_SRC}/backend/metadata_writer/src/* ${CRAFT_PART_INSTALL}/kfp/metadata_writer + + 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 -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) > ${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query diff --git a/metadata-writer/tests/test_rock.py b/metadata-writer/tests/test_rock.py new file mode 100644 index 0000000..205122f --- /dev/null +++ b/metadata-writer/tests/test_rock.py @@ -0,0 +1,45 @@ +# Copyright 2024 Canonical Ltd. +# See LICENSE file for licensing details. + +import pytest +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 the rock contains the expected files + subprocess.run( + [ + "docker", + "run", + "--rm", + LOCAL_ROCK_IMAGE, + "exec", + "ls", + "-la", + "/kfp/metadata_writer/metadata_writer.py", + ], + check=True, + ) + + subprocess.run( + [ + "docker", + "run", + "--rm", + LOCAL_ROCK_IMAGE, + "exec", + "ls", + "-la", + "/kfp/metadata_writer/metadata_helpers.py", + ], + check=True, + ) diff --git a/metadata-writer/tox.ini b/metadata-writer/tox.ini new file mode 100644 index 0000000..eab50eb --- /dev/null +++ b/metadata-writer/tox.ini @@ -0,0 +1,53 @@ +# Copyright 2022 Canonical Ltd. +# See LICENSE file for licensing details. +[tox] +skipsdist = True +skip_missing_interpreters = True +envlist = unit, sanity, integration + +[testenv] +setenv = + PYTHONPATH={toxinidir} + PYTHONBREAKPOINT=ipdb.set_trace + CHARM_REPO=https://github.com/canonical/kfp-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 = + # 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 = + pytest -s -v --tb native --show-capture=all --log-cli-level=INFO {posargs} {toxinidir}/tests + +[testenv:integration] +passenv = * +allowlist_externals = + echo +commands = + echo "WARNING: This is a placeholder test - no test is implemented here." +