Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 29c52b7

Browse files
authored
feat: jupyter-notebook: preinstall Python packages (#263)
1 parent 312cb71 commit 29c52b7

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

‎registry/coder/modules/jupyter-notebook/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ A module that adds Jupyter Notebook in your Coder template.
1616
module "jupyter-notebook" {
1717
count = data.coder_workspace.me.start_count
1818
source = "registry.coder.com/coder/jupyter-notebook/coder"
19-
version = "1.1.1"
19+
version = "1.2.0"
2020
agent_id = coder_agent.example.id
2121
}
2222
```

‎registry/coder/modules/jupyter-notebook/main.tf‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,27 @@ variable "group" {
4848
default = null
4949
}
5050

51+
variable "requirements_path" {
52+
type = string
53+
description = "The path to requirements.txt with packages to preinstall"
54+
default = ""
55+
}
56+
57+
variable "pip_install_extra_packages" {
58+
type = string
59+
description = "List of extra packages to preinstall (example: numpy==1.26.4 pandas matplotlib<4 scikit-learn)"
60+
default = ""
61+
}
62+
5163
resource "coder_script" "jupyter-notebook" {
5264
agent_id = var.agent_id
5365
display_name = "jupyter-notebook"
5466
icon = "/icon/jupyter.svg"
5567
script = templatefile("${path.module}/run.sh", {
5668
LOG_PATH : var.log_path,
57-
PORT : var.port
69+
PORT : var.port,
70+
REQUIREMENTS_PATH : var.requirements_path,
71+
PIP_INSTALL_EXTRA_PACKAGES : var.pip_install_extra_packages
5872
})
5973
run_on_start = true
6074
}

‎registry/coder/modules/jupyter-notebook/run.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ else
2020
echo "🥳 jupyter-notebook is already installed\n\n"
2121
fi
2222

23+
# Install packages selected with REQUIREMENTS_PATH
24+
if [ -n "${REQUIREMENTS_PATH}" ]; then
25+
if [ -f "${REQUIREMENTS_PATH}" ]; then
26+
echo "📄 Installing packages from ${REQUIREMENTS_PATH}..."
27+
pipx -q runpip notebook install -r "${REQUIREMENTS_PATH}"
28+
echo "🥳 Packages from ${REQUIREMENTS_PATH} have been installed\n\n"
29+
else
30+
echo "⚠️ REQUIREMENTS_PATH is set to '${REQUIREMENTS_PATH}' but the file does not exist!\n\n"
31+
fi
32+
fi
33+
34+
# Install packages selected with PIP_INSTALL_EXTRA_PACKAGES
35+
if [ -n "${PIP_INSTALL_EXTRA_PACKAGES}" ]; then
36+
echo "📦 Installing additional packages: ${PIP_INSTALL_EXTRA_PACKAGES}"
37+
pipx -q runpip notebook install ${PIP_INSTALL_EXTRA_PACKAGES}
38+
echo "🥳 Additional packages have been installed\n\n"
39+
fi
40+
2341
echo "👷 Starting jupyter-notebook in background..."
2442
echo "check logs at ${LOG_PATH}"
2543
$HOME/.local/bin/jupyter-notebook --NotebookApp.ip='0.0.0.0' --ServerApp.port=${PORT} --no-browser --ServerApp.token='' --ServerApp.password='' > ${LOG_PATH} 2>&1 &

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /