-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add image for Jupyter projects (#14)
- Loading branch information
1 parent
fd7eb83
commit b1403ba
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
ARG PYTHON_VERSION=3.11.7 | ||
ARG DOCKER_USER=docker | ||
ARG USER_ID=1000 | ||
ARG GROUP_ID=$USER_ID | ||
|
||
FROM python:${PYTHON_VERSION}-slim | ||
ARG DOCKER_USER | ||
ARG USER_ID | ||
ARG GROUP_ID | ||
|
||
RUN apt update && apt install -y --no-install-recommends \ | ||
curl \ | ||
procps \ | ||
neovim \ | ||
&& apt clean && rm -rf /var/lib/apt/lists/* | ||
|
||
RUN addgroup --gid $GROUP_ID $DOCKER_USER \ | ||
&& adduser --uid $USER_ID --gid $GROUP_ID --shell /bin/sh --home "/home/${DOCKER_USER}" --disabled-password $DOCKER_USER | ||
USER $USER_ID:$GROUP_ID | ||
|
||
WORKDIR /src | ||
VOLUME /src | ||
VOLUME /notebooks | ||
VOLUME /home/docker/.jupyter | ||
EXPOSE 8888 | ||
COPY JUPYTER.md /assets/ | ||
COPY entrypoint.sh /usr/local/bin/ | ||
ENTRYPOINT ["entrypoint.sh"] | ||
CMD [ \ | ||
"python", \ | ||
"-m", \ | ||
"jupyter", \ | ||
"notebook", \ | ||
"--ip", \ | ||
"0.0.0.0", \ | ||
"--no-browser", \ | ||
"--ServerApp.root_dir=/notebooks", \ | ||
"--IdentityProvider.token=''", \ | ||
"--PasswordIdentityProvider.password_required=false" \ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Jupyter Notebook | ||
|
||
## Setup | ||
|
||
### Setup Riptide project | ||
|
||
```shell | ||
riptide setup | ||
``` | ||
|
||
### Update images | ||
|
||
```shell | ||
riptide update | ||
``` | ||
|
||
Note: Make sure riptide is in your PATH (not just an alias to your bin), so it could be found with `which`. | ||
|
||
|
||
## Start | ||
|
||
To start your notebook server run: | ||
|
||
```shell | ||
riptide start | ||
``` | ||
|
||
This will | ||
- create a new python virtual environment at `.venv` (if not existing) | ||
- create a `pyproject.toml` containing the project dependencies (if not existing) | ||
- install the project dependencies from the `pyproject.toml` (if the venv was not existing before) | ||
- ensures that jupyter notebook is installed (adds it as dependency if missing) | ||
- starts the jupyter notebook server | ||
|
||
You manually need to adjust the `pyproject.toml` to your needs. | ||
|
||
When the start command is finished, it will give you the link to your notebook server. | ||
|
||
If no virtual environment exists, the start command can take a little longer. | ||
It will wait until the server is up and running, so that you know, when you can start accessing it. | ||
|
||
## Install dependencies | ||
|
||
After `pyproject.toml` was externally changed (e.g. by `git pull`), you need to run following command, | ||
to install the up-to-date dependencies. | ||
|
||
```shell | ||
poetry install | ||
``` | ||
|
||
### Add new dependencies | ||
|
||
To install a new dependency (like in this example `pandas`), run the following: | ||
|
||
```shell | ||
poetry add pandas | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
If something is not working as expected, you can attach to the logs: | ||
|
||
```shell | ||
tail -f _riptide/logs/jupyter/stderr.log | ||
``` | ||
|
||
At any time you can remove the `.venv` directory in you project and restart | ||
Riptide (`riptide restart`) to recreate it. This could solve most of the issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Supported tags and respective `Dockerfile` links | ||
|
||
- [`latest` (*Dockerfile*)](https://github.com/theCapypara/riptide-docker-images/jupyter/Dockerfile) | ||
|
||
# Quick reference | ||
|
||
- **Where to get help**: | ||
[the Riptide Docker Images Github Repository](https://github.com/theCapypara/riptide-docker-images) | ||
|
||
- **Where to file issues**: | ||
[https://github.com/theCapypara/riptide-docker-images/issues](https://github.com/theCapypara/riptide-docker-images/issues) | ||
|
||
- **Maintained by**: | ||
[the Riptide Community](https://github.com/theCapypara/riptide-docker-images) | ||
|
||
- **Source of this description**: | ||
[README in riptide-docker-images repo](https://github.com/theCapypara/riptide-docker-images/tree/master/jupyter) ([history](https://github.com/theCapypara/riptide-docker-images/tree/master/jupyter)) | ||
|
||
# What is Jupyter? | ||
|
||
[Jupyter Notebook](https://jupyter.org) is a web-based interactive computing platform. This image contains all tools needed to run a Jupyter server and work with notebooks. | ||
|
||
# How to use this image. | ||
|
||
This image is meant to be used with [Riptide](https://github.com/theCapypara/riptide-cli). | ||
Using it without Riptide is probably possible, but not supported. | ||
|
||
## Basic Usage with Riptide | ||
|
||
For a service using this image, see: [Jupyter Riptide Service](https://github.com/theCapypara/riptide-repo/tree/master/service/jupyter) | ||
|
||
This image supports ``run_as_current_user: true`` for services. | ||
|
||
## Basic Usage with Docker Run | ||
|
||
``` | ||
docker run \ | ||
-v .:/src \ | ||
-v ./notebooks:/notebooks \ | ||
-v ./.jupyter:~/.jupyter \ | ||
riptidepy/jupyter | ||
``` | ||
|
||
# Volumes | ||
|
||
Have a look here for the volumes used by this image: [Jupyter Riptide Service](https://github.com/theCapypara/riptide-repo/tree/master/service/jupyter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
NEW_VENV=false | ||
cp /assets/JUPYTER.md /src | ||
|
||
# create new venv if not existing | ||
if [ ! -d .venv ]; then | ||
python -m venv .venv | ||
.venv/bin/pip install --upgrade pip | ||
.venv/bin/pip install poetry | ||
NEW_VENV=true | ||
fi | ||
|
||
# activate the virtual env | ||
source .venv/bin/activate | ||
|
||
# add activation script to .bashrc, so we are using the venv, if we are in a bash shell | ||
echo "if [ -f .venv/bin/activate ]; then source .venv/bin/activate; fi" >> ~/.bashrc | ||
|
||
# init poetry project | ||
if [ ! -f pyproject.toml ]; then | ||
PLACEHOLDER_NAME="Your Project" | ||
poetry new "$PLACEHOLDER_NAME" | ||
cp "$PLACEHOLDER_NAME/pyproject.toml" . | ||
rm -r "$PLACEHOLDER_NAME" | ||
fi | ||
|
||
# install dependencies if the venv was newly created | ||
if [ "$NEW_VENV" = true ]; then | ||
poetry install --no-root | ||
fi | ||
|
||
# ensure jupyter is installed | ||
if ! jupyter-notebook --version; then | ||
poetry add jupyter | ||
fi | ||
|
||
exec "$@" |