Skip to content

Commit

Permalink
Faster jupyter notebook image (#11)
Browse files Browse the repository at this point in the history
* Faster jupyter notebook image

* work

* more progress but default landing page is broken

* Use bleeding-edge jupyter

* erase tmpenv mentions

* readme fix

* notebook instruction
  • Loading branch information
paulgb authored Jun 8, 2023
1 parent aa060f5 commit 00d5bd5
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 1,118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env
29 changes: 24 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
FROM python:3.11.0-buster
FROM python:3.11.3-slim

# This entire section is only needed while we are using notebook directly from git instead of pypi.
# If it were permanent, we would want to do a multi-stage built, but it's not.
RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs

RUN useradd -m jupyter
USER jupyter
WORKDIR /home/jupyter

RUN python3 -m venv notebook-env
COPY --chown=jupyter requirements.txt ./
COPY --chown=jupyter freeze.txt ./
COPY empty.ipynb ./

RUN /home/jupyter/notebook-env/bin/pip install --upgrade pip
RUN /home/jupyter/notebook-env/bin/pip install -r requirements.txt
RUN /home/jupyter/notebook-env/bin/pip install -r freeze.txt

# Warm up the kernel. Disabled until we can prove that this helps.
#RUN /home/jupyter/notebook-env/bin/pip install nbconvert
#RUN /home/jupyter/notebook-env/bin/jupyter nbconvert --to markdown --execute empty.ipynb

COPY --chown=jupyter notebook ./notebook
COPY run.sh ./
RUN /home/jupyter/notebook-env/bin/ipython profile create default

ENV PATH=/home/jupyter/notebook-env/bin:$PATH

WORKDIR /home/jupyter/notebook

CMD ["../run.sh"]
CMD /home/jupyter/notebook-env/bin/jupyter \
notebook \
--ip 0.0.0.0 \
--port $PORT \
--no-browser \
--NotebookApp.token="" \
--JupyterNotebookApp.default_url="/notebooks/hello-jamsocket.ipynb"
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ Base repo for running Jupyter Notebooks on the Jamsocket platform

1. Fork this repository.
2. Add your notebook(s) to the `/notebook` directory.
3. Add your notebook's python dependencies to `requirements.txt`.
4. Update the `NOTEBOOK` value in `run.sh` to make sure Jupyter opens your notebook on start up.
5. Set your account name as the `JAMSOCKET_ACCOUNT` value in your GitHub secrets.
6. Generate an access token at [app.jamsocket.com/settings](https://app.jamsocket.com/settings) and set it as the `JAMSOCKET_TOKEN` value in your GitHub secrets. ([Contact us](https://forms.gle/2xjUy4AmR5tdj42Y7) to get a Jamsocket account if you don't have one.)
7. Push your repo to your GitHub account, and your Jupyter Notebook container will be automatically built and pushed to Jamsocket.
8. Get a Spawn URL from us. (Open this URL in a browser to start a new tmpenv.)
3. Add your notebook's python dependencies to `requirements.txt` (alternatively, if you prefer `pipenv`, add them with `pipenv install` and then run `pipenv run freeze`).
4. Replace `/notebooks/hello-jamsocket.ipynb` in `Dockerfile` with the path to the notebook you'd like to be automatically loaded. If you want the user to see a file listing of the `/notebooks` directory by default, remove that line entirely.
5. Run `./freeze.sh` to create a `freeze.txt` file from `requirements.txt`. This pins the version of all of the dependencies of the libraries in `requirements.txt`.
6. Set your account name as the `JAMSOCKET_ACCOUNT` value in your GitHub secrets.
7. Generate an access token at [app.jamsocket.com/settings](https://app.jamsocket.com/settings) and set it as the `JAMSOCKET_TOKEN` value in your GitHub secrets. ([Sign up](https://auth.jamsocket.com/signup) for a Jamsocket account if you don’t already have one.)
8. Push your repo to your GitHub account, and your Jupyter Notebook container will be automatically built and pushed to Jamsocket.
9. Get a Spawn URL from us. (Open this URL in a browser to start a new notebook instance.)

## Customization
## Restricting access

You can optionally password-protect your notebook by editing the `JUPYTER_NOTEBOOK_PASSWORD` in `run.sh`.
Use Jamsocket's [backend authentication](https://docs.jamsocket.com/backend-authentication/) to restrict access by bearer token.

## To run the jupyter-notebook locally for testing:

Expand Down
6 changes: 6 additions & 0 deletions empty.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
8 changes: 8 additions & 0 deletions freeze.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set -e

virtualenv env
. env/bin/activate
pip install -r requirements.txt
pip freeze > freeze.txt
103 changes: 103 additions & 0 deletions freeze.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
anyio==3.7.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens==2.2.1
async-lru==2.0.2
attrs==23.1.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
comm==0.1.3
contourpy==1.0.7
cycler==0.11.0
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
exceptiongroup==1.1.1
executing==1.2.0
fastjsonschema==2.17.1
fonttools==4.39.4
fqdn==1.5.1
idna==3.4
importlib-metadata==6.6.0
importlib-resources==5.12.0
ipykernel==6.23.1
ipython==8.14.0
isoduration==20.11.0
jedi==0.18.2
Jinja2==3.1.2
json5==0.9.14
jsonpointer==2.3
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter-lsp==2.2.0
jupyter_client==8.2.0
jupyter_core==5.3.0
jupyter_server==2.6.0
jupyter_server_terminals==0.4.4
jupyterlab==4.0.2
jupyterlab-pygments==0.2.2
jupyterlab_server==2.22.1
kiwisolver==1.4.4
MarkupSafe==2.1.3
matplotlib==3.7.1
matplotlib-inline==0.1.6
mistune==2.0.5
nbclient==0.8.0
nbconvert==7.4.0
nbformat==5.9.0
nest-asyncio==1.5.6
notebook @ git+https://github.com/jupyter/notebook@466b6bf2d7532f58e8e2861f350fd93e781c3ed3
notebook_shim==0.2.3
numpy==1.24.3
overrides==7.3.1
packaging==23.1
pandas==2.0.2
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
platformdirs==3.5.1
prometheus-client==0.17.0
prompt-toolkit==3.0.38
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.15.1
pyparsing==3.0.9
pyrsistent==0.19.3
python-dateutil==2.8.2
python-json-logger==2.0.7
pytz==2023.3
PyYAML==6.0
pyzmq==25.1.0
requests==2.31.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
scipy==1.10.1
Send2Trash==1.8.2
six==1.16.0
sniffio==1.3.0
soupsieve==2.4.1
stack-data==0.6.2
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tornado==6.3.2
traitlets==5.9.0
typing_extensions==4.6.3
tzdata==2023.3
uri-template==1.2.0
urllib3==2.0.3
wcwidth==0.2.6
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.2
zipp==3.15.0
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "7b30fe0e-d4b7-42d4-8714-fd29ab746020",
"metadata": {},
"source": [
"# Hi!\n",
"\n",
"This is a notebook hosted by [Jamsocket tmpenv](https://jamsocket.com/tmpenv/).\n",
"This is a notebook hosted by [Jamsocket](https://jamsocket.com/).\n",
"\n",
"You can clone the [jamsocket-jupyter-notebook](https://github.com/drifting-in-space/jamsocket-jupyter-notebook) repo and replace this with whatever you want."
]
Expand All @@ -19,7 +20,7 @@
"metadata": {},
"outputs": [],
"source": [
"print('Hello, tmpenv user!')"
"print('Hello, Jamsocket user!')"
]
}
],
Expand All @@ -39,7 +40,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.9.2"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 00d5bd5

Please sign in to comment.