Skip to content

Commit

Permalink
Merge pull request #108 from DSD-DBS/jupyter
Browse files Browse the repository at this point in the history
Jupyter image
  • Loading branch information
MoritzWeber0 authored Feb 27, 2023
2 parents bb98cd2 + 0a9433a commit 1f1c458
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export DOCKER_TAG=$(CAPELLA_VERSION)-$(CAPELLA_DOCKERIMAGES_REVISION)

# Should be 'latest', the branch name, the commit hash or a Git tag name
export CAPELLA_DOCKERIMAGES_REVISION ?= latest
export JUPYTER_NOTEBOOK_REVISION ?= python-3.11

# UID which is used for the techuser in the Docker images
export TECHUSER_UID = 1004370000
Expand Down Expand Up @@ -130,6 +131,7 @@ export MAKE_CURRENT_TARGET=$@

all: \
base \
jupyter-notebook \
capella/base \
capella/cli \
capella/remote \
Expand All @@ -149,6 +151,10 @@ base:
docker build $(DOCKER_BUILD_FLAGS) --build-arg UID=$(TECHUSER_UID) -t $(DOCKER_PREFIX)$@:$(CAPELLA_DOCKERIMAGES_REVISION) base
$(MAKE) PUSH_IMAGES=$(PUSH_IMAGES) DOCKER_TAG=$(CAPELLA_DOCKERIMAGES_REVISION) IMAGENAME=$@ .push

jupyter-notebook: base
docker build $(DOCKER_BUILD_FLAGS) -t $(DOCKER_PREFIX)$@:$(JUPYTER_NOTEBOOK_REVISION) jupyter-notebook
$(MAKE) PUSH_IMAGES=$(PUSH_IMAGES) DOCKER_TAG=$(JUPYTER_NOTEBOOK_REVISION) IMAGENAME=$@ .push

capella/base: SHELL=./capella_loop.sh
capella/base: base
envsubst < capella/.dockerignore.template > capella/.dockerignore
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This repository includes Docker files to build the following Docker images:
| `t4c/client/backup`|This extends the T4C client base image to import a model from T4C and export it to Git.|
| `t4c/client/exporter`|This extends the T4C client base image to import a model from GIT and export it to T4C.|
| `capella/remote/pure-variants`<br>`t4c/client/remote/pure-variants`|This extends the remote image with pure::variants support.|
| `jupyter-notebook`|A Jupyter notebook image based on the base image.|

Important for building the Docker images is to strictly follow the sequence.
The dependency graph for the images looks like:
Expand Down Expand Up @@ -443,6 +444,19 @@ pure-variants/dependencies
└── org.eclipse.wst.validation_1.2.800.v201904082137.jar
```

### 11. Docker mage `jupyter-notebook`

The `jupyter-notebook` image provides a JupyterLab server that can run on the
Collab-Manager environment.

The image configured to connect to the same workspace shared volume as the Capella remote images.
If the `notebooks/` folder on the shared volume contains a `requirements.txt` file, dependencies
defined in that file will be installed before the server launches.

```zsh
docker build -t jupyter-notebook jupyter-notebook
```

## Run the images

### Capella locally on X11 systems
Expand Down Expand Up @@ -765,6 +779,20 @@ You can find the description for most of the values directly above and here are
- `HTTP_LOGIN`: username for the REST API. At the moment administrator access is required
- `HTTP_PASSWORD`: password for the REST API

### JupyterLab server

```zsh
docker run -ti --rm -e NOTEBOOKS_DIR=/tmp/notebooks -p 8888:8888 jupyter-notebook
```

The following environment variables can be defined:

- `JUPYTER_PORT`: The port to run the jupyter server on.
- `NOTEBOOKS_DIR`: The working directory for JupyterLab.
- `JUPYTER_BASE_URL`: A context path to access the jupyter server.
This allows you to run multiple server containers on the same domain.
- `JUPYTER_TOKEN`: A token for accessing the environment.

## Additional notes

### Tips
Expand Down
45 changes: 40 additions & 5 deletions ci-templates/gitlab/image-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ variables:
T4C_CLIENT_EASE_REMOTE_DEBUG:
value: "0"
description: "Build the t4c/client/ease/remote/debug image?"
JUPYTER:
value: "0"
description: "Build the jupyter-notebook image?"
CAPELLA_DOCKER_IMAGES_REVISION:
value: "main"
description: "Revision of the Capella Docker images Github repository (https://github.com/DSD-DBS/capella-dockerimages)"
CAPELLA_VERSION:
value: "6.0.0"
description: "Capella version. Please make sure that a subdirectory with the name of the value exists. The value must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes."
JUPYTER_VERSION:
value: "python-3.11"
description: "Python version for the jupyter notebook."
DOCKER_BUILD_ARGS: "--no-cache"
BUILD_ARCHITECTURE: amd64

Expand All @@ -61,8 +67,14 @@ default:
tags:
- docker
before_script:
- &normalizeTag export DOCKER_TAG=$CAPELLA_VERSION-$(echo $CAPELLA_DOCKER_IMAGES_REVISION | sed 's/[^a-zA-Z0-9.]/-/g')-$CI_COMMIT_REF_NAME
- export BASE_IMAGE=$BASE_IMAGE:$DOCKER_TAG
- &baseImageTag export BASE_IMAGE_TAG=$(echo $CAPELLA_DOCKER_IMAGES_REVISION | sed 's/[^a-zA-Z0-9.]/-/g')-$CI_COMMIT_REF_NAME
- export DOCKER_TAG=$CAPELLA_VERSION-$BASE_IMAGE_TAG
- >
if [[ "$BASE_IMAGE" == "$DOCKER_REGISTRY/base2" ]]; then
export BASE_IMAGE=$BASE_IMAGE:$BASE_IMAGE_TAG;
else
export BASE_IMAGE=$BASE_IMAGE:$DOCKER_TAG;
fi
.github: &github
- git clone --recurse-submodules https://github.com/DSD-DBS/capella-dockerimages.git
Expand Down Expand Up @@ -90,17 +102,18 @@ base:
rules:
- if: '$BASE == "1"'
when: always
before_script:
- *normalizeTag
variables:
BASE_IMAGE: debian:bullseye
IMAGE: $DOCKER_REGISTRY/base2
before_script:
- *baseImageTag
- export DOCKER_TAG=$BASE_IMAGE_TAG
script:
- *prepare
- *docker
- |
docker build $DOCKER_BUILD_ARGS \
-t $DOCKER_REGISTRY/base2:$DOCKER_TAG \
-t $IMAGE:$DOCKER_TAG \
--build-arg UID=$UID_ENV \
--build-arg BASE_IMAGE=$BASE_IMAGE \
base
Expand Down Expand Up @@ -422,3 +435,25 @@ t4c/client/ease/remote/debug:
--build-arg BASE_IMAGE=$BASE_IMAGE \
ease/debug
- *push

jupyter:
stage: build
needs:
- job: base
optional: true
rules:
- if: '$JUPYTER == "1"'
when: always
variables:
BASE_IMAGE: $DOCKER_REGISTRY/base2
IMAGE: $DOCKER_REGISTRY/jupyter-notebook
script:
- export DOCKER_TAG=python-3.11-$BASE_IMAGE_TAG
- *prepare
- *docker
- |
docker build $DOCKER_BUILD_ARGS \
-t $IMAGE:$DOCKER_TAG \
--build-arg BASE_IMAGE=$BASE_IMAGE \
jupyter-notebook
- *push
31 changes: 31 additions & 0 deletions jupyter-notebook/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0

ARG BASE_IMAGE=base
FROM $BASE_IMAGE

RUN apt update && \
apt install --yes --no-install-recommends \
git \
git-lfs \
libgirepository1.0-dev \
libcairo2-dev \
gir1.2-pango-1.0 \
graphviz && \
rm -rf /var/lib/apt/lists/*

COPY docker-entrypoint.sh /
COPY requirements_template.txt /etc/skel

RUN chmod +x /docker-entrypoint.sh && \
python3 -m pip install jupyterlab capellambse

ENV JUPYTER_PORT=8888
ENV NOTEBOOKS_DIR=/workspace/notebooks

EXPOSE $JUPYTER_PORT

USER techuser
WORKDIR $HOME

ENTRYPOINT "/docker-entrypoint.sh"
20 changes: 20 additions & 0 deletions jupyter-notebook/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0

echo "---START_PREPARE_WORKSPACE---"

mkdir -p "$NOTEBOOKS_DIR"

test -f "$NOTEBOOKS_DIR/requirements.txt" || cp /etc/skel/requirements_template.txt "$NOTEBOOKS_DIR/requirements.txt"
pip install -r "$NOTEBOOKS_DIR/requirements.txt" 2>&1 | tee "$NOTEBOOKS_DIR/installlog.txt"

echo "---START_SESSION---"

jupyter-lab --ip=0.0.0.0 \
--port=$JUPYTER_PORT \
--no-browser \
--ServerApp.authenticate_prometheus=False \
--ServerApp.base_url="$JUPYTER_BASE_URL" \
--ServerApp.root_dir="$NOTEBOOKS_DIR"
6 changes: 6 additions & 0 deletions jupyter-notebook/requirements_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Use this file to define custom dependencis for your Jupyter workspace.
# The format of the requirements file is described at
# https://pip.pypa.io/en/stable/reference/requirements-file-format/

# numpy
# pandas
2 changes: 2 additions & 0 deletions jupyter-notebook/requirements_template.txt.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
SPDX-License-Identifier: CC0-1.0

0 comments on commit 1f1c458

Please sign in to comment.