Skip to content
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

Added kubeflow pipelines launcher rock image #158

Merged
merged 9 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions launcher/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Based on: https://github.com/kubeflow/pipelines/blob/2.2.0/backend/Dockerfile.launcher
name: kfp-launcher
summary: Kubeflow Pipelines Launcher
description: |
Kubeflow Pipelines Launcher is a streamlined interface designed to simplify the creation, management, and deployment of machine learning workflows on Kubernetes.
version: 2.2.0
license: Apache-2.0
base: ubuntu@22.04
run-user: _daemon_
platforms:
amd64:

services:
launcher:
override: merge
summary: "kfp launcher service"
startup: enabled
user: appuser
command: "/bin/launcher-v2"

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 -f '${db:Status-Abbrev},${binary:Package},${Version},${source:Package},${Source:Version}\n' -W) > \
${CRAFT_PART_INSTALL}/usr/share/rocks/dpkg.query

launcher:
plugin: go
source-type: git
source: https://github.com/kubeflow/pipelines.git
source-depth: 1
source-tag: 2.2.0
build-snaps:
- go/1.21/stable
build-packages:
- apt
- bash
build-environment:
- CGO_ENABLED: 0
- GOOS: linux
- GOARCH: amd64
stage-packages:
- bash
override-build: |
set -xe

mkdir -p $CRAFT_PART_INSTALL/bin
mkdir -p $CRAFT_PART_INSTALL/third_party

go build -tags netgo -ldflags '-extldflags "-static"' -o $CRAFT_PART_INSTALL/bin/launcher-v2 $CRAFT_PART_BUILD/backend/src/v2/cmd/launcher-v2/*.go

./hack/install-go-licenses.sh

$GOBIN/go-licenses check $CRAFT_PART_BUILD/backend/src/v2/cmd/launcher-v2
$GOBIN/go-licenses csv $CRAFT_PART_BUILD/backend/src/v2/cmd/launcher-v2 > $CRAFT_PART_INSTALL/third_party/licenses.csv && \
diff $CRAFT_PART_INSTALL/third_party/licenses.csv $CRAFT_PART_BUILD/backend/third_party_licenses/launcher.csv && \
$GOBIN/go-licenses save $CRAFT_PART_BUILD/backend/src/v2/cmd/launcher-v2 --save_path $CRAFT_PART_INSTALL/third_party/NOTICES

# not-root user for this rock should be 'appuser'
non-root-user:
plugin: nil
after: [ launcher ]
overlay-script: |
# Create a user in the $CRAFT_OVERLAY chroot
groupadd -R $CRAFT_OVERLAY -g 1001 appuser
useradd -R $CRAFT_OVERLAY -M -r -u 1001 -g appuser appuser
override-prime: |
craftctl default
chown -R 584792:users bin

51 changes: 51 additions & 0 deletions launcher/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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",
"/third_party/licenses.csv",
],
check=True,
)

# Assert the rock contains the expected file in /third_party
subprocess.run(
[
"docker",
"run",
"--rm",
LOCAL_ROCK_IMAGE,
"exec",
"ls",
"-la",
"/third_party/NOTICES/",
],
check=True,
)

subprocess.run(
["docker", "run", "--rm", LOCAL_ROCK_IMAGE, "exec", "ls", "-la", "/bin/launcher-v2"],
check=True,
)
53 changes: 53 additions & 0 deletions launcher/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2022 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist = pack, export-to-docker, 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 =
# TODO: Implement integration tests here
echo "WARNING: This is a placeholder test - no test is implemented here."
Loading