Skip to content

Commit e6d2038

Browse files
tim-quixtomas-quix
andauthored
JupyterLab Service Template (#610)
* add jupyterlab * idk tweak resources * lowercase the name * add reqs.txt * fix dockerfile * Enable state * Update library.json * Update library.json * Creates a JupyterLab Dockerfile Adds a Dockerfile for running JupyterLab. This Dockerfile includes: - Installation of necessary OS and Python dependencies. - Configuration for JupyterLab, including password authentication, default theme, and autocompletion. - A startup script to initialize Jupyter state if it doesn't exist, including setting a password and theme, and copying a default notebook. Also adds a sample notebook and requirements file. --------- Co-authored-by: tomas-quix <[email protected]> Co-authored-by: Tomas Neubauer <[email protected]>
1 parent ff73672 commit e6d2038

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 8,
6+
"id": "5e598c31-3b11-405b-acdc-c6665378e9ec",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"topic=\"your-topic-name\""
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "eabc6a12-848f-4b30-a92b-ef49c85dcef7",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from quixstreams import Application\n",
21+
"from quixstreams.sinks.core.list import ListSink\n",
22+
"\n",
23+
"import os\n",
24+
"\n",
25+
"\n",
26+
"# Setup necessary objects\n",
27+
"app = Application(\n",
28+
" consumer_group=\"topic-query-v1\",\n",
29+
" auto_offset_reset=\"earliest\"\n",
30+
")\n",
31+
"input_topic = app.topic(name=topic)\n",
32+
"sdf = app.dataframe(topic=input_topic)\n",
33+
"\n",
34+
"list_sink = ListSink() # sink will be a list-like object\n",
35+
"sdf.sink(list_sink)\n",
36+
"\n",
37+
"app.run(timeout=3.0, count=100)"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": null,
43+
"id": "5c3437f0-aa8a-41a8-b85a-62a79fe712da",
44+
"metadata": {},
45+
"outputs": [],
46+
"source": [
47+
"import pandas as pd\n",
48+
"df = pd.DataFrame(list_sink)\n",
49+
"df.head(10)"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"id": "d7ee9398-28d7-4934-90ba-076ec25f1ef0",
56+
"metadata": {},
57+
"outputs": [],
58+
"source": []
59+
}
60+
],
61+
"metadata": {
62+
"kernelspec": {
63+
"display_name": "Python 3 (ipykernel)",
64+
"language": "python",
65+
"name": "python3"
66+
},
67+
"language_info": {
68+
"codemirror_mode": {
69+
"name": "ipython",
70+
"version": 3
71+
},
72+
"file_extension": ".py",
73+
"mimetype": "text/x-python",
74+
"name": "python",
75+
"nbconvert_exporter": "python",
76+
"pygments_lexer": "ipython3",
77+
"version": "3.11.12"
78+
}
79+
},
80+
"nbformat": 4,
81+
"nbformat_minor": 5
82+
}

python/others/jupyterlab/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# JupyterLab
2+
3+
This sample demonstrates how to deploy a JupyterLab instance so you can run
4+
Jupyter notebooks from the platform.
5+
6+
## How to Run
7+
8+
1. Log in or sign up at [Quix](https://portal.platform.quix.io/signup?xlink=github) and navigate to the Code Samples section.
9+
2. Click **Deploy** to launch a pre-built container.
10+
3. Fill in the required environment variables for your JupyterLab instance.
11+
4. Enable state, otherwise changes will be lost on restart. Please note, the necessary storage type may not be supported on all Quix Platforms.
12+
13+
For more configuration options and details, refer to [Mongo Docker Hub](https://hub.docker.com/_/mongo).
14+
15+
16+
## Contribute
17+
18+
Feel free to fork this project on the [GitHub](https://github.com/quixio/quix-samples) repository and contribute your enhancements. Any accepted contributions will be attributed accordingly.
19+
20+
## License & Support
21+
22+
This project is open source under the Apache 2.0 license and available in our [GitHub](https://github.com/quixio/quix-samples) repo. Remember, this image is provided by the [docker community](https://github.com/docker-library/mongo) and is offered as-is, with no MongoDB specific support from Quix.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# ---------- base image ----------
2+
FROM python:3.11-slim
3+
4+
WORKDIR /app
5+
ARG MAINAPPPATH=.
6+
7+
# ---------- OS deps ----------
8+
RUN apt-get update && apt-get install -y \
9+
build-essential \
10+
git \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# ---------- Python deps ----------
14+
COPY "${MAINAPPPATH}/requirements.txt" .
15+
RUN pip install --no-cache-dir -r requirements.txt \
16+
&& pip install --no-cache-dir jupyterlab # <-- ensure Lab is present
17+
18+
COPY "${MAINAPPPATH}/Notebook.ipynb" /app/Notebook.ipynb
19+
20+
# ---------- ports & env ----------
21+
EXPOSE 8888
22+
23+
ENV JUPYTER_CONFIG_DIR=/app/state/config \
24+
JUPYTER_DATA_DIR=/app/state/data \
25+
JUPYTER_RUNTIME_DIR=/app/state/runtime
26+
27+
# ---------- launcher ----------
28+
RUN cat <<'JUPYTER_START_SH' > /jupyter_start.sh
29+
#!/bin/bash
30+
if [ -z "$(ls -A "/app/state")" ]; then
31+
echo "Initializing Jupyter state at /app/state..."
32+
33+
mkdir -p \
34+
/app/state/config \
35+
/app/state/data \
36+
/app/state/runtime \
37+
/app/state/notebooks \
38+
/app/state/config/lab/user-settings/@jupyterlab/apputils-extension \
39+
/app/state/config/lab/user-settings/@jupyterlab/completer-extension
40+
41+
# Copy notebook if bundled (first run)
42+
[ -f /app/Notebook.ipynb ] && cp /app/Notebook.ipynb /app/state/notebooks/Notebook.ipynb
43+
44+
# Write theme config
45+
echo '{ "theme": "JupyterLab Dark" }' > \
46+
/app/state/config/lab/user-settings/@jupyterlab/apputils-extension/themes.jupyterlab-settings
47+
48+
HASHED_PASSWORD=$(python -c "from jupyter_server.auth import passwd; import os; print(passwd(os.getenv('JUPYTER_PASSWORD', '')))")
49+
cat <<CONFIG > "$JUPYTER_CONFIG_DIR/jupyter_notebook_config.py"
50+
c.ServerApp.identity_provider_class = "jupyter_server.auth.identity.PasswordIdentityProvider"
51+
c.PasswordIdentityProvider.hashed_password = '${HASHED_PASSWORD}'
52+
c.IdentityProvider.token = ""
53+
c.ServerApp.open_browser = False
54+
c.ServerApp.ip = "0.0.0.0"
55+
c.ServerApp.port = 8888
56+
CONFIG
57+
58+
# Autocomplete config
59+
cat <<'COMPLETER_JSON' > "$JUPYTER_CONFIG_DIR/lab/user-settings/@jupyterlab/completer-extension/manager.jupyterlab-settings"
60+
{
61+
"availableProviders": {
62+
"CompletionProvider:context": 500,
63+
"CompletionProvider:kernel": 550
64+
},
65+
"providerTimeout": 1000,
66+
"showDocumentationPanel": false,
67+
"autoCompletion": true,
68+
"suppressIfInlineCompleterActive": true
69+
}
70+
COMPLETER_JSON
71+
72+
else
73+
echo "Using existing Jupyter state in /app/state"
74+
fi
75+
76+
exec jupyter lab --no-browser --allow-root --notebook-dir=/app/state/notebooks
77+
JUPYTER_START_SH
78+
79+
RUN chmod +x /jupyter_start.sh
80+
CMD ["/jupyter_start.sh"]

python/others/jupyterlab/icon.png

11.1 KB
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"libraryItemId": "jupyterlab",
3+
"name": "JupyterLab",
4+
"language": "docker",
5+
"tags": {
6+
"Category": ["Data Exploration"],
7+
"Type": ["Auxiliary Services"]
8+
},
9+
"shortDescription": "Run JupyterLab in your pipeline.",
10+
"DefaultFile": "dockerfile",
11+
"EntryPoint": "dockerfile",
12+
"IconFile": "icon.png",
13+
"DeploySettings": {
14+
"DeploymentType": "Service",
15+
"CpuMillicores": 500,
16+
"MemoryInMb": 2000,
17+
"Replicas": 1,
18+
"PublicAccess": true,
19+
"UrlPrefix": "jupyterlab",
20+
"State:": {
21+
"Enabled": true,
22+
"Size": 1
23+
},
24+
"Network": {
25+
"ServiceName": "jupyterlab",
26+
"Ports":
27+
[
28+
{
29+
"Port": 80,
30+
"TargetPort": 8888
31+
}
32+
]
33+
}
34+
},
35+
"Variables": [
36+
{
37+
"Name": "JUPYTER_PASSWORD",
38+
"Type": "EnvironmentVariable",
39+
"InputType": "Secret",
40+
"Description": "The allowed password for connecting to JupyterLab",
41+
"Required": true
42+
}
43+
]
44+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
quixstreams==3.14.1
2+
python-dotenv
3+
jupyterlab
4+
notebook
5+
numpy
6+
pandas
7+
matplotlib
8+
seaborn
9+
scikit-learn
10+
scipy
11+
bcrypt

0 commit comments

Comments
 (0)