Skip to content

Commit

Permalink
Allow to configure default settings for JupyterLab (overrides.json) (
Browse files Browse the repository at this point in the history
…nebari-dev#2249)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Amit Kumar <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2024
1 parent 32f62f8 commit 872f7bf
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test_local_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ jobs:
sed -i -E 's/(cpu_guarantee):\s+[0-9\.]+/\1: 0.25/g' "nebari-config.yaml"
sed -i -E 's/(mem_guarantee):\s+[A-Za-z0-9\.]+/\1: 0.25G/g' "nebari-config.yaml"
# Change default JupyterLab theme
cat >> nebari-config.yaml <<- EOM
jupyterlab:
default_settings:
"@jupyterlab/apputils-extension:themes":
theme: JupyterLab Dark
EOM
cat nebari-config.yaml
- name: Deploy Nebari
Expand Down
5 changes: 5 additions & 0 deletions src/_nebari/stages/kubernetes_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class IdleCuller(schema.Base):


class JupyterLab(schema.Base):
default_settings: typing.Dict[str, typing.Any] = {}
idle_culler: IdleCuller = IdleCuller()
initial_repositories: typing.List[typing.Dict[str, str]] = []
preferred_dir: typing.Optional[str] = None
Expand Down Expand Up @@ -353,6 +354,9 @@ class CondaStoreInputVars(schema.Base):
class JupyterhubInputVars(schema.Base):
jupyterhub_theme: Dict[str, Any] = Field(alias="jupyterhub-theme")
jupyterlab_image: ImageNameTag = Field(alias="jupyterlab-image")
jupyterlab_default_settings: Dict[str, Any] = Field(
alias="jupyterlab-default-settings"
)
initial_repositories: str = Field(alias="initial-repositories")
jupyterhub_overrides: List[str] = Field(alias="jupyterhub-overrides")
jupyterhub_stared_storage: str = Field(alias="jupyterhub-shared-storage")
Expand Down Expand Up @@ -505,6 +509,7 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
argo_workflows_enabled=self.config.argo_workflows.enabled,
jhub_apps_enabled=self.config.jhub_apps.enabled,
initial_repositories=str(self.config.jupyterlab.initial_repositories),
jupyterlab_default_settings=self.config.jupyterlab.default_settings,
jupyterlab_preferred_dir=self.config.jupyterlab.preferred_dir,
)

Expand Down
7 changes: 7 additions & 0 deletions src/_nebari/stages/kubernetes_services/template/jupyterhub.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ variable "initial-repositories" {
type = string
}

variable "jupyterlab-default-settings" {
description = "Default settings for JupyterLab to be placed in overrides.json"
type = map(any)
}

variable "jupyterhub-hub-extraEnv" {
description = "Extracted overrides to merge with jupyterhub.hub.extraEnv"
type = string
Expand Down Expand Up @@ -147,6 +152,8 @@ module "jupyterhub" {
idle-culler-settings = var.idle-culler-settings
initial-repositories = var.initial-repositories

jupyterlab-default-settings = var.jupyterlab-default-settings

jupyterlab-pioneer-enabled = var.jupyterlab-pioneer-enabled
jupyterlab-pioneer-log-format = var.jupyterlab-pioneer-log-format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ locals {
)
}

locals {
jupyterlab-overrides-json-object = merge(
jsondecode(file("${path.module}/files/jupyterlab/overrides.json")),
var.jupyterlab-default-settings
)
}

locals {
jupyter-pioneer-config-py-template = templatefile("${path.module}/files/jupyter/jupyter_jupyterlab_pioneer_config.py.tpl", {
log_format = var.jupyterlab-pioneer-log-format != null ? var.jupyterlab-pioneer-log-format : ""
Expand All @@ -31,6 +38,12 @@ resource "local_file" "jupyter_jupyterlab_pioneer_config_py" {
}


resource "local_file" "overrides_json" {
content = jsonencode(local.jupyterlab-overrides-json-object)
filename = "${path.module}/files/jupyterlab/overrides.json"
}


resource "kubernetes_config_map" "etc-ipython" {
metadata {
name = "etc-ipython"
Expand All @@ -57,6 +70,12 @@ locals {
)
}

locals {
etc-jupyterlab-settings = {
"overrides.json" = local_file.overrides_json.content
}
}

resource "kubernetes_config_map" "etc-jupyter" {
depends_on = [
local_file.jupyter_server_config_py,
Expand Down Expand Up @@ -86,15 +105,16 @@ resource "kubernetes_config_map" "etc-skel" {


resource "kubernetes_config_map" "jupyterlab-settings" {
depends_on = [
local_file.overrides_json
]

metadata {
name = "jupyterlab-settings"
namespace = var.namespace
}

data = {
for filename in fileset("${path.module}/files/jupyterlab", "*") :
filename => file("${path.module}/files/jupyterlab/${filename}")
}
data = local.etc-jupyterlab-settings
}

resource "kubernetes_config_map" "git_clone_update" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ variable "argo-workflows-enabled" {
type = bool
}

variable "jupyterlab-default-settings" {
description = "Default settings for JupyterLab to be placed in overrides.json"
type = map(any)
}

variable "jupyterlab-pioneer-enabled" {
description = "Enable JupyterLab Pioneer for telemetry"
type = bool
Expand Down
3 changes: 3 additions & 0 deletions tests/tests_e2e/cypress/integration/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ describe('First Test', () => {
// Click VS Code Launcher exists
cy.get('div.jp-LauncherCard[title="VS Code [↗]"]').should('exist');

// Should reflect theme set by default_settings
cy.get('body[data-jp-theme-name="JupyterLab Dark"]').should('exist');

// Stop my Jupyter server - must do this so PVC can be destroyed on Minikube
cy.visit('/hub/home');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project_name: test
jupyterlab:
default_settings:
"@jupyterlab/apputils-extension:themes":
theme: JupyterLab Dark

0 comments on commit 872f7bf

Please sign in to comment.