From 490492034bbebb02b74e621e87d7652936035cb5 Mon Sep 17 00:00:00 2001
From: Dimitris Aragiorgis <dimitris.aragiorgis@gmail.com>
Date: Sun, 23 Jul 2023 12:26:59 +0300
Subject: [PATCH] Rock for TWA

Add rockcraft.yaml for tensorboards-web-app.
---
 .github/workflows/build_and_scan_rocks.yaml |   1 +
 tensorboards-web-app/rockcraft.yaml         | 112 ++++++++++++++++++++
 2 files changed, 113 insertions(+)
 create mode 100644 tensorboards-web-app/rockcraft.yaml

diff --git a/.github/workflows/build_and_scan_rocks.yaml b/.github/workflows/build_and_scan_rocks.yaml
index bb84dbf..3f6a73d 100644
--- a/.github/workflows/build_and_scan_rocks.yaml
+++ b/.github/workflows/build_and_scan_rocks.yaml
@@ -24,6 +24,7 @@ jobs:
           - kfam
           - notebook-controller
           - volumes-web-app
+          - tensorboards-web-app
     uses: canonical/charmed-kubeflow-workflows/.github/workflows/build_and_scan_rock.yaml@main
     with:
       rock: ${{ matrix.rock }}
diff --git a/tensorboards-web-app/rockcraft.yaml b/tensorboards-web-app/rockcraft.yaml
new file mode 100644
index 0000000..eaaf7f7
--- /dev/null
+++ b/tensorboards-web-app/rockcraft.yaml
@@ -0,0 +1,112 @@
+name: tensorboards-web-app
+summary: Tensorboards Web App
+description: |
+  This web app is responsible for allowing the user to manipulate Tensorboard
+  instances in their Kubeflow cluster. To achieve this it provides a user
+  friendly way to handle the lifecycle of Tensorboard CRs.
+version: v1.7.0_20.04_1
+license: Apache-2.0
+base: ubuntu:20.04
+
+run-user: _daemon_
+services:
+  serve:
+    override: replace
+    summary: "tensorboards service"
+    command: gunicorn -w 3 --bind 0.0.0.0:5000 --access-logfile - entrypoint:app
+    startup: enabled
+    environment:
+      NODE_ENV: production
+platforms:
+  amd64:
+
+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.7-branch  # upstream branch
+    source-depth: 1
+    build-packages:
+      - python3-venv
+      - python3-setuptools
+      - python3-pip
+    override-build: |
+      python3 -m pip install wheel
+      cd components/crud-web-apps/common/backend
+      python3 setup.py bdist_wheel
+      # XXX: Upstream has a hardcoded/dummy version=1.1 in setup.py
+      cp dist/kubeflow-1.1-py3-none-any.whl $CRAFT_STAGE
+
+  frontend-lib:
+    plugin: nil
+    source: https://github.com/kubeflow/kubeflow
+    source-type: git
+    source-tag: v1.7-branch  # upstream branch
+    source-depth: 1
+    build-snaps:
+      - node/12/stable
+    build-environment:
+      - NG_CLI_ANALYTICS: "ci"
+    override-build: |
+      cd components/crud-web-apps/common/frontend/kubeflow-common-lib
+      npm ci
+      npm run build
+      cp -r dist/kubeflow/ $CRAFT_STAGE
+
+  frontend:
+    after: [frontend-lib]
+    plugin: nil
+    source: https://github.com/kubeflow/kubeflow
+    source-type: git
+    source-tag: v1.7-branch  # upstream branch
+    source-depth: 1
+    build-snaps:
+      - node/12/stable
+    build-environment:
+      - NG_CLI_ANALYTICS: "ci"
+    override-build: |
+      cd components/crud-web-apps/tensorboards/frontend
+      npm ci
+      cp -r $CRAFT_STAGE/kubeflow/ ./node_modules/  # TODO confirm
+      npm run build -- --output-path=./dist --configuration=production
+      cp -r dist $CRAFT_STAGE
+
+  webapp:
+    after: [backend, frontend]
+    plugin: nil
+    source: https://github.com/kubeflow/kubeflow
+    source-type: git
+    source-tag: v1.7-branch  # upstream branch
+    source-depth: 1
+    build-packages:
+      - python3-venv
+      - python3-setuptools
+      - python3-pip
+    override-build: |
+      pip3 install $CRAFT_STAGE/kubeflow-1.1-py3-none-any.whl
+      cd components/crud-web-apps/tensorboards/backend
+      cp -r $CRAFT_STAGE/dist/ app/static/
+      cp -r app $CRAFT_STAGE/
+      cp entrypoint.py $CRAFT_STAGE
+    override-stage: |
+      cp -r app $CRAFT_PRIME
+      cp entrypoint.py $CRAFT_PRIME
+      # XXX: Ubuntu 20.04 has Python 3.8
+      cp -r /usr/local/lib/python3.8/dist-packages/* $CRAFT_PRIME
+
+  gunicorn:
+    plugin: python
+    source: https://github.com/kubeflow/kubeflow.git
+    source-tag: v1.7-branch  # upstream branch
+    source-depth: 1
+    python-requirements:
+    - components/crud-web-apps/tensorboards/backend/requirements.txt
+    stage-packages:
+    - python3-venv