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

feat: add tensorboards-web-app rock for CKF 1.9 #87

Merged
merged 7 commits into from
Sep 2, 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
136 changes: 136 additions & 0 deletions tensorboards-web-app/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Based on https://github.com/kubeflow/kubeflow/blob/v1.9.0/components/crud-web-apps/tensorboards/Dockerfile
name: tensorboards-web-app
summary: Tensorboards Web App
description: |
This web app is responsible for allowing the user to manipulate tensorboards in their Kubeflow
cluster.
version: "1.9.0"
license: Apache-2.0
base: [email protected]
platforms:
amd64:
run-user: _daemon_

services:
tensorboards-web-app:
override: replace
summary: "Tensorboards web app service"
startup: enabled
command: '/bin/bash -c "gunicorn -w 3 --bind 0.0.0.0:5000 --access-logfile - entrypoint:app"'
working-dir: "/src/"

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

backend:
plugin: nil
source: https://github.com/kubeflow/kubeflow
source-type: git
source-tag: v1.9.0
source-depth: 1
build-packages:
- python3-venv
- python3-setuptools
- python3-pip
override-build: |
python3 -m pip install wheel
# Create a directory that holds the src of the backend copied
# from the CRAFT_PART_SRC directory to avoid bringing files that
# could affect the build of the backend wheel.
# This measure helps keeping the rockcraft and the Dockerfile files
# as similar as possible in terms of the operations they perform.
# This is replicated in other steps for the frontend.
mkdir $CRAFT_STAGE/backend-src && cd $CRAFT_STAGE/backend-src
cp -r $CRAFT_PART_SRC/components/crud-web-apps/common/backend/* $CRAFT_STAGE/backend-src/
python3 setup.py bdist_wheel

frontend-lib:
plugin: nil
source: https://github.com/kubeflow/kubeflow
source-type: git
source-tag: v1.9.0
source-depth: 1
build-snaps:
- node/12/stable
build-environment:
- NG_CLI_ANALYTICS: "ci"
override-build: |
mkdir $CRAFT_STAGE/frontend-lib-src/ && cd $CRAFT_STAGE/frontend-lib-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/common/frontend/kubeflow-common-lib/package.json $CRAFT_STAGE/frontend-lib-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/common/frontend/kubeflow-common-lib/package-lock.json $CRAFT_STAGE/frontend-lib-src/
npm ci

cp -r $CRAFT_PART_SRC/components/crud-web-apps/common/frontend/kubeflow-common-lib/projects/ $CRAFT_STAGE/frontend-lib-src/projects
cp $CRAFT_PART_SRC/components/crud-web-apps/common/frontend/kubeflow-common-lib/angular.json $CRAFT_STAGE/frontend-lib-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/common/frontend/kubeflow-common-lib/tsconfig.json $CRAFT_STAGE/frontend-lib-src/
npm run build

frontend:
after: [frontend-lib]
plugin: nil
source: https://github.com/kubeflow/kubeflow
source-type: git
source-tag: v1.9.0
source-depth: 1
build-snaps:
- node/12/stable
build-environment:
- NG_CLI_ANALYTICS: "ci"
override-build: |
mkdir $CRAFT_STAGE/frontend-src/ && cd $CRAFT_STAGE/frontend-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/package.json $CRAFT_STAGE/frontend-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/package-lock.json $CRAFT_STAGE/frontend-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/tsconfig.json $CRAFT_STAGE/frontend-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/tsconfig.app.json $CRAFT_STAGE/frontend-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/tsconfig.spec.json $CRAFT_STAGE/frontend-src/
cp $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/angular.json $CRAFT_STAGE/frontend-src/
mkdir $CRAFT_STAGE/frontend-src/src/
cp -r $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/frontend/src/* $CRAFT_STAGE/frontend-src/src/
npm ci

mkdir -p $CRAFT_STAGE/frontend-src/node_modules/kubeflow
cp -r $CRAFT_STAGE/frontend-lib-src/dist/kubeflow/* $CRAFT_STAGE/frontend-src/node_modules/kubeflow

npm run build -- --output-path=$CRAFT_STAGE/frontend-src/dist --configuration=production

webapp:
after: [backend, frontend]
plugin: nil
source: https://github.com/kubeflow/kubeflow
source-type: git
source-tag: v1.9.0
source-depth: 1
build-packages:
- python3-venv
- python3-setuptools
- python3-pip
override-build: |
cd $CRAFT_STAGE/backend-src/ && pip install .

# 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 $CRAFT_PART_INSTALL/src && cd $CRAFT_PART_INSTALL/src
mkdir $CRAFT_PART_INSTALL/src/app/
cp -r $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/backend/app/* $CRAFT_PART_INSTALL/src/app/
cp -r $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/backend/entrypoint.py $CRAFT_PART_INSTALL/src/
cp -r $CRAFT_PART_SRC/components/crud-web-apps/tensorboards/backend/Makefile $CRAFT_PART_INSTALL/src/

cp -r $CRAFT_STAGE/frontend-src/dist/ $CRAFT_PART_INSTALL/src/app/static

gunicorn:
plugin: python
source: https://github.com/kubeflow/kubeflow.git
source-tag: v1.9.0
source-depth: 1
python-requirements:
- components/crud-web-apps/tensorboards/backend/requirements.txt
stage-packages:
- python3-venv
46 changes: 46 additions & 0 deletions tensorboards-web-app/tests/test_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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",
"/src",
],
check=True,
)

subprocess.run(
[
"docker",
"run",
"--rm",
LOCAL_ROCK_IMAGE,
"exec",
"cat",
"/src/entrypoint.py",
],
check=True,
)
54 changes: 54 additions & 0 deletions tensorboards-web-app/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/notebook-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 rock 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."
Loading