diff --git a/registry/coder/modules/jupyter-notebook/README.md b/registry/coder/modules/jupyter-notebook/README.md index 9c0cd5e22..a509df6a1 100644 --- a/registry/coder/modules/jupyter-notebook/README.md +++ b/registry/coder/modules/jupyter-notebook/README.md @@ -16,7 +16,7 @@ A module that adds Jupyter Notebook in your Coder template. module "jupyter-notebook" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/jupyter-notebook/coder" - version = "1.1.1" + version = "1.2.0" agent_id = coder_agent.example.id } ``` diff --git a/registry/coder/modules/jupyter-notebook/main.tf b/registry/coder/modules/jupyter-notebook/main.tf index 61cf25ebf..568e8ca7a 100644 --- a/registry/coder/modules/jupyter-notebook/main.tf +++ b/registry/coder/modules/jupyter-notebook/main.tf @@ -48,13 +48,27 @@ variable "group" { default = null } +variable "requirements_path" { + type = string + description = "The path to requirements.txt with packages to preinstall" + default = "" +} + +variable "pip_install_extra_packages" { + type = string + description = "List of extra packages to preinstall (example: numpy==1.26.4 pandas matplotlib<4 scikit-learn)" + default = "" +} + resource "coder_script" "jupyter-notebook" { agent_id = var.agent_id display_name = "jupyter-notebook" icon = "/icon/jupyter.svg" script = templatefile("${path.module}/run.sh", { LOG_PATH : var.log_path, - PORT : var.port + PORT : var.port, + REQUIREMENTS_PATH : var.requirements_path, + PIP_INSTALL_EXTRA_PACKAGES : var.pip_install_extra_packages }) run_on_start = true } diff --git a/registry/coder/modules/jupyter-notebook/run.sh b/registry/coder/modules/jupyter-notebook/run.sh index 0c7a9b85f..797d9b41f 100644 --- a/registry/coder/modules/jupyter-notebook/run.sh +++ b/registry/coder/modules/jupyter-notebook/run.sh @@ -20,6 +20,24 @@ else echo "🥳 jupyter-notebook is already installed\n\n" fi +# Install packages selected with REQUIREMENTS_PATH +if [ -n "${REQUIREMENTS_PATH}" ]; then + if [ -f "${REQUIREMENTS_PATH}" ]; then + echo "📄 Installing packages from ${REQUIREMENTS_PATH}..." + pipx -q runpip notebook install -r "${REQUIREMENTS_PATH}" + echo "🥳 Packages from ${REQUIREMENTS_PATH} have been installed\n\n" + else + echo "⚠️ REQUIREMENTS_PATH is set to '${REQUIREMENTS_PATH}' but the file does not exist!\n\n" + fi +fi + +# Install packages selected with PIP_INSTALL_EXTRA_PACKAGES +if [ -n "${PIP_INSTALL_EXTRA_PACKAGES}" ]; then + echo "📦 Installing additional packages: ${PIP_INSTALL_EXTRA_PACKAGES}" + pipx -q runpip notebook install ${PIP_INSTALL_EXTRA_PACKAGES} + echo "🥳 Additional packages have been installed\n\n" +fi + echo "👷 Starting jupyter-notebook in background..." echo "check logs at ${LOG_PATH}" $HOME/.local/bin/jupyter-notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &