Skip to content

Commit 61d4451

Browse files
committed
squashme: notebooks changes
This includes major edits to the notebooks code to work with the data service.
1 parent 03223a7 commit 61d4451

66 files changed

Lines changed: 6435 additions & 1383 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {
2121
"minikube": "none"
2222
},
23-
"ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {},
23+
"ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {
24+
"jqVersion": "latest",
25+
"yqVersion": "latest"
26+
},
2427
"ghcr.io/dhoeric/features/k9s:1": {},
2528
"ghcr.io/EliiseS/devcontainer-features/bash-profile:1": {
2629
"command": "alias k=kubectl"

.devcontainer/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ services:
2323
ZED_TOKEN: renku
2424
ZED_INSECURE: "true"
2525
POETRY_CACHE_DIR: "/poetry_cache"
26+
NB_SERVER_OPTIONS__DEFAULTS_PATH: /workspace/server_defaults.json
27+
NB_SERVER_OPTIONS__UI_CHOICES_PATH: /workspace/server_options.json
2628
network_mode: service:db
2729
depends_on:
2830
- db
@@ -43,6 +45,7 @@ services:
4345
- "8080:8080"
4446
- "5678:5678"
4547
- "50051:50051"
48+
- "8888:80"
4649

4750
swagger:
4851
image: swaggerapi/swagger-ui

.github/workflows/acceptance-tests.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ jobs:
2525
renku-graph: ${{ steps.deploy-comment.outputs.renku-graph}}
2626
renku-notebooks: ${{ steps.deploy-comment.outputs.renku-notebooks}}
2727
renku-ui: ${{ steps.deploy-comment.outputs.renku-ui}}
28+
amalthea-sessions: ${{ steps.deploy-comment.outputs.amalthea-sessions}}
29+
amalthea: ${{ steps.deploy-comment.outputs.amalthea}}
2830
test-enabled: ${{ steps.deploy-comment.outputs.test-enabled}}
2931
test-cypress-enabled: ${{ steps.deploy-comment.outputs.test-cypress-enabled}}
3032
persist: ${{ steps.deploy-comment.outputs.persist}}
3133
extra-values: ${{ steps.deploy-comment.outputs.extra-values}}
3234
steps:
3335
- id: deploy-comment
34-
uses: SwissDataScienceCenter/renku-actions/check-pr-description@v1.11.3
36+
uses: SwissDataScienceCenter/renku-actions/check-pr-description@v1.12.1
3537
with:
3638
string: /deploy
3739
pr_ref: ${{ github.event.number }}
@@ -61,7 +63,7 @@ jobs:
6163
body: |
6264
You can access the deployment of this PR at https://renku-ci-ds-${{ github.event.number }}.dev.renku.ch
6365
- name: Build and deploy
64-
uses: SwissDataScienceCenter/renku-actions/deploy-renku@v1.11.3
66+
uses: SwissDataScienceCenter/renku-actions/deploy-renku@v1.12.1
6567
env:
6668
RANCHER_PROJECT_ID: ${{ secrets.CI_RANCHER_PROJECT }}
6769
DOCKER_PASSWORD: ${{ secrets.RENKU_DOCKER_PASSWORD }}
@@ -84,14 +86,16 @@ jobs:
8486
renku_graph: "${{ needs.check-deploy.outputs.renku-graph }}"
8587
renku_notebooks: "${{ needs.check-deploy.outputs.renku-notebooks }}"
8688
renku_data_services: "@${{ github.head_ref }}"
89+
amalthea: "${{ needs.check-deploy.outputs.amalthea }}"
90+
amalthea-sessions: "${{ needs.check-deploy.outputs.amalthea-sessions }}"
8791
extra_values: "${{ needs.check-deploy.outputs.extra-values }}"
8892

8993
selenium-acceptance-tests:
9094
needs: [check-deploy, deploy-pr]
9195
if: github.event.action != 'closed' && needs.check-deploy.outputs.pr-contains-string == 'true' && needs.check-deploy.outputs.test-enabled == 'true'
9296
runs-on: ubuntu-22.04
9397
steps:
94-
- uses: SwissDataScienceCenter/renku-actions/test-renku@v1.11.3
98+
- uses: SwissDataScienceCenter/renku-actions/test-renku@v1.12.1
9599
with:
96100
kubeconfig: ${{ secrets.RENKUBOT_DEV_KUBECONFIG }}
97101
renku-release: renku-ci-ds-${{ github.event.number }}
@@ -118,7 +122,7 @@ jobs:
118122
steps:
119123
- name: Extract Renku repository reference
120124
run: echo "RENKU_REFERENCE=`echo '${{ needs.check-deploy.outputs.renku }}' | cut -d'@' -f2`" >> $GITHUB_ENV
121-
- uses: SwissDataScienceCenter/renku-actions/test-renku-cypress@v1.11.3
125+
- uses: SwissDataScienceCenter/renku-actions/test-renku-cypress@v1.12.1
122126
with:
123127
e2e-target: ${{ matrix.tests }}
124128
renku-reference: ${{ env.RENKU_REFERENCE }}
@@ -146,7 +150,7 @@ jobs:
146150
body: |
147151
Tearing down the temporary RenkuLab deplyoment for this PR.
148152
- name: renku teardown
149-
uses: SwissDataScienceCenter/renku-actions/cleanup-renku-ci-deployments@v1.11.3
153+
uses: SwissDataScienceCenter/renku-actions/cleanup-renku-ci-deployments@v1.12.1
150154
env:
151155
HELM_RELEASE_REGEX: "^renku-ci-ds-${{ github.event.number }}$"
152156
GITLAB_TOKEN: ${{ secrets.DEV_GITLAB_TOKEN }}

.github/workflows/save_cache.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Create cache from commits on main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- chore-add-kind
8+
workflow_dispatch:
9+
10+
11+
jobs:
12+
save-poetry-cache:
13+
runs-on: ubuntu-latest
14+
env:
15+
CACHE_KEY: main-branch-poetry-cache-ubuntu
16+
CACHE_PATH: .devcontainer/.poetry_cache
17+
DEVCONTAINER_IMAGE_CACHE: ghcr.io/swissdatasciencecenter/renku-data-services/devcontainer
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- name: Login to Docker Hub
24+
uses: docker/login-action@v2
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Install python deps
30+
uses: devcontainers/ci@v0.3
31+
with:
32+
runCmd: poetry install --with dev
33+
push: always
34+
skipContainerUserIdUpdate: false
35+
imageName: ${{ env.DEVCONTAINER_IMAGE_CACHE }}
36+
cacheFrom: ${{ env.DEVCONTAINER_IMAGE_CACHE }}
37+
- uses: actions/cache/save@v3
38+
name: Create cache
39+
with:
40+
path: ${{ env.CACHE_PATH }}
41+
key: ${{ env.CACHE_KEY }}

.github/workflows/test_publish.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,58 @@ jobs:
7171
- uses: actions/checkout@v4
7272
with:
7373
fetch-depth: 0
74+
- name: Docker image metadata
75+
id: meta
76+
uses: docker/metadata-action@v5
77+
with:
78+
images: ${{ env.DEVCONTAINER_REGISTRY }}/${{ env.DEVCONTAINER_IMAGE_NAME }}
79+
tags: |
80+
type=ref,event=pr,prefix=cache-pr-,priority=600
81+
type=ref,event=branch,prefix=cache-,priority=500
82+
type=ref,event=tag,prefix=cache-,priority=500
83+
flavor: |
84+
latest=false
85+
- name: Extract Docker image name
86+
id: docker_image
87+
env:
88+
IMAGE_TAGS: ${{ steps.meta.outputs.tags }}
89+
run: |
90+
IMAGE=$(echo "$IMAGE_TAGS" | cut -d" " -f1)
91+
IMAGE_REPOSITORY=$(echo "$IMAGE" | cut -d":" -f1)
92+
IMAGE_TAG=$(echo "$IMAGE" | cut -d":" -f2)
93+
echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
94+
echo "image_repository=$IMAGE_REPOSITORY" >> "$GITHUB_OUTPUT"
95+
echo "image_tag=$IMAGE_TAG" >> "$GITHUB_OUTPUT"
96+
- uses: docker/login-action@v3
97+
with:
98+
registry: ghcr.io
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
- name: Pre-build devcontainer
102+
uses: devcontainers/ci@v0.3
103+
continue-on-error: true
104+
with:
105+
push: always
106+
skipContainerUserIdUpdate: false
107+
imageName: ${{ steps.docker_image.outputs.image_repository }}
108+
imageTag: ${{ steps.docker_image.outputs.image_tag }}
109+
cacheFrom: |
110+
${{ steps.docker_image.outputs.image_repository }}:${{ steps.docker_image.outputs.image_tag }}
111+
${{ steps.docker_image.outputs.image_repository }}:${{ env.DEVCONTAINER_IMAGE_TAG_MAIN }}
112+
113+
style-checks:
114+
runs-on: ubuntu-latest
115+
needs:
116+
- build-devcontainer
117+
steps:
118+
- uses: actions/checkout@v4
119+
with:
120+
fetch-depth: 0
121+
- uses: actions/cache/restore@v3
122+
name: Restore cache
123+
with:
124+
path: ${{ env.CACHE_PATH }}
125+
key: ${{ env.CACHE_KEY }}
74126
- name: Set Git config
75127
shell: bash
76128
run: |
@@ -99,6 +151,11 @@ jobs:
99151
- uses: actions/checkout@v4
100152
with:
101153
fetch-depth: 0
154+
- uses: actions/cache/restore@v3
155+
name: Restore cache
156+
with:
157+
path: ${{ env.CACHE_PATH }}
158+
key: ${{ env.CACHE_KEY }}
102159
- name: Set Git config
103160
shell: bash
104161
run: |
@@ -143,6 +200,11 @@ jobs:
143200
- uses: actions/checkout@v4
144201
with:
145202
fetch-depth: 0
203+
- uses: actions/cache/restore@v3
204+
name: Restore cache
205+
with:
206+
path: ${{ env.CACHE_PATH }}
207+
key: ${{ env.CACHE_KEY }}
146208
- name: Set Git config
147209
shell: bash
148210
run: |

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: schemas tests test_setup main_tests schemathesis_tests collect_coverage style_checks pre_commit_checks run download_avro check_avro avro_models update_avro kind_cluster install_amaltheas all
22

3-
AMALTHEA_JS_VERSION ?= 0.11.0
4-
AMALTHEA_SESSIONS_VERSION ?= 0.0.1-new-operator-chart
3+
AMALTHEA_JS_VERSION ?= 0.12.2
4+
AMALTHEA_SESSIONS_VERSION ?= 0.0.9-new-operator-chart
55
codegen_params = --input-file-type openapi --output-model-type pydantic_v2.BaseModel --use-double-quotes --target-python-version 3.12 --collapse-root-models --field-constraints --strict-nullable --set-default-enum-member --openapi-scopes schemas paths parameters --set-default-enum-member --use-one-literal-as-default --use-default
66

77
define test_apispec_up_to_date
@@ -153,7 +153,13 @@ kind_cluster: ## Creates a kind cluster for testing
153153
sleep 15
154154
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s
155155

156-
install_amaltheas: ## Installs both version of amalthea in the currently active k8s context.
156+
install_amaltheas: ## Installs both version of amalthea in the. NOTE: It uses the currently active k8s context.
157157
helm repo add renku https://swissdatasciencecenter.github.io/helm-charts
158-
helm install amalthea-js renku/amalthea --version $(AMALTHEA_JS_VERSION)
159-
helm install amalthea-sessions renku/amalthea-sessions --version $(AMALTHEA_SESSIONS_VERSION)
158+
helm repo update
159+
helm upgrade --install amalthea-js renku/amalthea --version $(AMALTHEA_JS_VERSION)
160+
helm upgrade --install amalthea-sessions amalthea-sessions-0.0.9-new-operator-chart.tgz --version $(AMALTHEA_SESSIONS_VERSION)
161+
162+
# TODO: Add the version variables from the top of the file here when the charts are fully published
163+
amalthea_schema: ## Updates generates pydantic classes from CRDs
164+
curl https://raw.githubusercontent.com/SwissDataScienceCenter/amalthea/fix-missing-status/config/crd/bases/amalthea.dev_amaltheasessions.yaml | yq '.spec.versions[0].schema.openAPIV3Schema' | poetry run datamodel-codegen --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output components/renku_data_services/notebooks/cr_amalthea_session.py --use-double-quotes --target-python-version 3.12 --collapse-root-models --field-constraints --strict-nullable --base-class renku_data_services.notebooks.cr_base.BaseCRD --allow-extra-fields --use-default-kwarg
165+
curl https://raw.githubusercontent.com/SwissDataScienceCenter/amalthea/main/controller/crds/jupyter_server.yaml | yq '.spec.versions[0].schema.openAPIV3Schema' | poetry run datamodel-codegen --input-file-type jsonschema --output-model-type pydantic_v2.BaseModel --output components/renku_data_services/notebooks/cr_jupyter_server.py --use-double-quotes --target-python-version 3.12 --collapse-root-models --field-constraints --strict-nullable --base-class renku_data_services.notebooks.cr_base.BaseCRD --allow-extra-fields --use-default-kwarg

bases/renku_data_services/data_api/app.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
UserResourcePoolsBP,
1717
)
1818
from renku_data_services.namespace.blueprints import GroupsBP
19+
from renku_data_services.notebooks.blueprints import NotebooksBP, NotebooksNewBP
1920
from renku_data_services.platform.blueprints import PlatformConfigBP
2021
from renku_data_services.project.blueprints import ProjectsBP
2122
from renku_data_services.repositories.blueprints import RepositoriesBP
@@ -134,6 +135,24 @@ def register_all_handlers(app: Sanic, config: Config) -> Sanic:
134135
authenticator=config.authenticator,
135136
internal_gitlab_authenticator=config.gitlab_authenticator,
136137
)
138+
notebooks = NotebooksBP(
139+
name="notebooks_old",
140+
url_prefix=url_prefix,
141+
authenticator=config.authenticator,
142+
nb_config=config.nb_config,
143+
internal_gitlab_authenticator=config.gitlab_authenticator,
144+
git_repo=config.git_repositories_repo,
145+
)
146+
notebooks_new = NotebooksNewBP(
147+
name="notebooks",
148+
url_prefix=url_prefix,
149+
authenticator=config.authenticator,
150+
nb_config=config.nb_config,
151+
project_repo=config.project_repo,
152+
session_repo=config.session_repo,
153+
rp_repo=config.rp_repo,
154+
internal_gitlab_authenticator=config.gitlab_authenticator,
155+
)
137156
platform_config = PlatformConfigBP(
138157
name="platform_config",
139158
url_prefix=url_prefix,
@@ -161,6 +180,8 @@ def register_all_handlers(app: Sanic, config: Config) -> Sanic:
161180
oauth2_clients.blueprint(),
162181
oauth2_connections.blueprint(),
163182
repositories.blueprint(),
183+
notebooks.blueprint(),
184+
notebooks_new.blueprint(),
164185
platform_config.blueprint(),
165186
]
166187
)

components/renku_data_services/app_config/config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from renku_data_services.message_queue.interface import IMessageQueue
5353
from renku_data_services.message_queue.redis_queue import RedisQueue
5454
from renku_data_services.namespace.db import GroupRepository
55+
from renku_data_services.notebooks.config import _NotebooksConfig
5556
from renku_data_services.platform.db import PlatformRepository
5657
from renku_data_services.project.db import ProjectMemberRepository, ProjectRepository
5758
from renku_data_services.repositories.db import GitRepositoriesRepository
@@ -144,6 +145,7 @@ class Config:
144145
kc_api: IKeycloakAPI
145146
message_queue: IMessageQueue
146147
gitlab_url: str | None
148+
nb_config: _NotebooksConfig
147149

148150
secrets_service_public_key: rsa.RSAPublicKey
149151
"""The public key of the secrets service, used to encrypt user secrets that only it can decrypt."""
@@ -208,6 +210,10 @@ def __post_init__(self) -> None:
208210
with open(spec_file) as f:
209211
repositories = safe_load(f)
210212

213+
spec_file = Path(renku_data_services.notebooks.__file__).resolve().parent / "api.spec.yaml"
214+
with open(spec_file) as f:
215+
repositories = safe_load(f)
216+
211217
spec_file = Path(renku_data_services.platform.__file__).resolve().parent / "api.spec.yaml"
212218
with open(spec_file) as f:
213219
platform = safe_load(f)
@@ -408,8 +414,8 @@ def from_env(cls, prefix: str = "") -> "Config":
408414
gitlab_client: base_models.GitlabAPIProtocol
409415
user_preferences_config: UserPreferencesConfig
410416
version = os.environ.get(f"{prefix}VERSION", "0.0.1")
411-
server_options_file = os.environ.get("SERVER_OPTIONS")
412-
server_defaults_file = os.environ.get("SERVER_DEFAULTS")
417+
server_options_file = os.environ.get("NB_SERVER_OPTIONS__UI_CHOICES_PATH")
418+
server_defaults_file = os.environ.get("NB_SERVER_OPTIONS__DEFAULTS_PATH")
413419
k8s_namespace = os.environ.get("K8S_NAMESPACE", "default")
414420
max_pinned_projects = int(os.environ.get(f"{prefix}MAX_PINNED_PROJECTS", "10"))
415421
user_preferences_config = UserPreferencesConfig(max_pinned_projects=max_pinned_projects)
@@ -491,6 +497,7 @@ def from_env(cls, prefix: str = "") -> "Config":
491497
sentry = SentryConfig.from_env(prefix)
492498
trusted_proxies = TrustedProxiesConfig.from_env(prefix)
493499
message_queue = RedisQueue(redis)
500+
nb_config = _NotebooksConfig.from_env(db)
494501

495502
return cls(
496503
version=version,
@@ -511,4 +518,5 @@ def from_env(cls, prefix: str = "") -> "Config":
511518
encryption_key=encryption_key,
512519
secrets_service_public_key=secrets_service_public_key,
513520
gitlab_url=gitlab_url,
521+
nb_config=nb_config,
514522
)

components/renku_data_services/authn/dummy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ async def authenticate(access_token: str, request: Request) -> base_models.APIUs
5757
)
5858

5959
return base_models.APIUser(
60-
is_admin=user_props.get("is_admin", False),
60+
is_admin_init=user_props.get("is_admin", False),
6161
id=user_props.get("id", "some-id") if is_set else None,
6262
access_token=access_token,
6363
first_name=user_props.get("first_name", "John") if is_set else None,
6464
last_name=user_props.get("last_name", "Doe") if is_set else None,
6565
email=user_props.get("email", "john.doe@gmail.com") if is_set else None,
6666
full_name=user_props.get("full_name", "John Doe") if is_set else None,
67+
refresh_token=request.headers.get("Renku-Auth-Refresh-Token"),
6768
)

0 commit comments

Comments
 (0)