feat: jupyter-notebook: preinstall Python packages (#263)
This commit is contained in:
parent
312cb71bf0
commit
29c52b7072
@ -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
|
||||
}
|
||||
```
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 &
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user