Skip to content

Commit

Permalink
Merge pull request #124 from iot-salzburg/update
Browse files Browse the repository at this point in the history
Update build scripts for cuda 11.8 and PyTorch 2.x
  • Loading branch information
ChristophSchranz authored Dec 14, 2023
2 parents 5d8443c + de3ca3f commit 78a1079
Show file tree
Hide file tree
Showing 17 changed files with 8,372 additions and 2,796 deletions.
146 changes: 101 additions & 45 deletions .build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Use NVIDIA CUDA as base image and run the same installation as in the other packages.
# The version of cuda must match those of the packages installed in src/Dockerfile.gpulibs
FROM nvidia/cuda:11.6.2-cudnn8-runtime-ubuntu20.04
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
LABEL authors="Christoph Schranz <christoph.schranz@salzburgresearch.at>, Mathematical Michael <consistentbayes@gmail.com>"
# This is a concatenated Dockerfile, the maintainers of subsequent sections may vary.
RUN chmod 1777 /tmp && chmod 1777 /var/tmp
Expand All @@ -17,15 +17,15 @@ RUN apt-get update && \
apt-get -y install apt-utils

############################################################################
#################### Dependency: jupyter/base-image ########################
#################### Dependency: jupyter/docker-stacks-foundation ##########
############################################################################

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

# Ubuntu 20.04 (focal)
# https://hub.docker.com/_/ubuntu/?tab=tags&name=focal
ARG ROOT_CONTAINER=ubuntu:focal
# Ubuntu 22.04 (jammy)
# https://hub.docker.com/_/ubuntu/tags?page=1&name=jammy
ARG ROOT_CONTAINER=ubuntu:22.04


LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"
Expand All @@ -50,15 +50,7 @@ RUN apt-get update --yes && \
# - bzip2 is necessary to extract the micromamba executable.
bzip2 \
ca-certificates \
fonts-liberation \
locales \
# - pandoc is used to convert notebooks to html files
# it's not present in arm64 ubuntu image, so we install it here
pandoc \
# - run-one - a wrapper script that runs no more
# than one unique instance of some command with a unique set of arguments,
# we use `run-one-constantly` to support `RESTARTABLE` option
run-one \
sudo \
# - tini is installed as a helpful container entrypoint that reaps zombie
# processes and such of the actual executable we want to start, see
Expand Down Expand Up @@ -106,7 +98,7 @@ RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \
USER ${NB_UID}

# Pin python version here, or set it to "default"
ARG PYTHON_VERSION=3.10
ARG PYTHON_VERSION=3.11

# Setup work directory for backward-compatibility
RUN mkdir "/home/${NB_USER}/work" && \
Expand All @@ -117,8 +109,7 @@ RUN mkdir "/home/${NB_USER}/work" && \
# Similar projects using Micromamba:
# - Micromamba-Docker: <https://github.com/mamba-org/micromamba-docker>
# - repo2docker: <https://github.com/jupyterhub/repo2docker>
# Install Python, Mamba, Jupyter Notebook, Lab, and Hub
# Generate a notebook server config
# Install Python, Mamba and jupyter_core
# Cleanup temporary files and remove Micromamba
# Correct permissions
# Do all this in a single RUN command to avoid duplicating all of the
Expand All @@ -131,7 +122,7 @@ RUN set -x && \
# Should be simpler, see <https://github.com/mamba-org/mamba/issues/1437>
arch="64"; \
fi && \
wget -qO /tmp/micromamba.tar.bz2 \
wget --progress=dot:giga -O /tmp/micromamba.tar.bz2 \
"https://micromamba.snakepit.net/api/micromamba/linux-${arch}/latest" && \
tar -xvjf /tmp/micromamba.tar.bz2 --strip-components=1 bin/micromamba && \
rm /tmp/micromamba.tar.bz2 && \
Expand All @@ -144,12 +135,70 @@ RUN set -x && \
--yes \
"${PYTHON_SPECIFIER}" \
'mamba' \
'notebook' \
'jupyterhub' \
'jupyterlab' && \
'jupyter_core' && \
rm micromamba && \
# Pin major.minor version of python
mamba list python | grep '^python ' | tr -s ' ' | cut -d ' ' -f 1,2 >> "${CONDA_DIR}/conda-meta/pinned" && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

# Configure container startup
ENTRYPOINT ["tini", "-g", "--"]
CMD ["start.sh"]

# Copy local files as late as possible to avoid cache busting
COPY start.sh /usr/local/bin/

# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}

WORKDIR "${HOME}"

############################################################################
#################### Dependency: jupyter/base-notebook #####################
############################################################################

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
ARG OWNER=jupyter

LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# Install all OS dependencies for notebook server that starts but lacks all
# features (e.g., download as all possible file formats)
RUN apt-get update --yes && \
apt-get install --yes --no-install-recommends \
fonts-liberation \
# - pandoc is used to convert notebooks to html files
# it's not present in aarch64 ubuntu image, so we install it here
pandoc \
# - run-one - a wrapper script that runs no more
# than one unique instance of some command with a unique set of arguments,
# we use `run-one-constantly` to support `RESTARTABLE` option
run-one && \
apt-get clean && rm -rf /var/lib/apt/lists/*

USER ${NB_UID}

# Install Jupyter Notebook, Lab, and Hub
# Generate a notebook server config
# Cleanup temporary files
# Correct permissions
# Do all this in a single RUN command to avoid duplicating all of the
# files across image layers when the permissions change
WORKDIR /tmp
RUN mamba install --yes \
'notebook' \
'jupyterhub' \
'jupyterlab' \
'nbclassic' && \
jupyter notebook --generate-config && \
mamba clean --all -f -y && \
npm cache clean --force && \
Expand All @@ -158,16 +207,16 @@ RUN set -x && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

EXPOSE 8888
ENV JUPYTER_PORT=8888
EXPOSE $JUPYTER_PORT

# Configure container startup
ENTRYPOINT ["tini", "-g", "--"]
CMD ["start-notebook.sh"]

# Copy local files as late as possible to avoid cache busting
COPY start.sh start-notebook.sh start-singleuser.sh /usr/local/bin/
COPY start-notebook.sh start-singleuser.sh /usr/local/bin/
# Currently need to have both jupyter_notebook_config and jupyter_server_config to support classic and lab
COPY jupyter_server_config.py /etc/jupyter/
COPY jupyter_server_config.py docker_healthcheck.py /etc/jupyter/

# Fix permissions on /etc/jupyter as root
USER root
Expand All @@ -180,9 +229,8 @@ RUN sed -re "s/c.ServerApp/c.NotebookApp/g" \
# HEALTHCHECK documentation: https://docs.docker.com/engine/reference/builder/#healthcheck
# This healtcheck works well for `lab`, `notebook`, `nbclassic`, `server` and `retro` jupyter commands
# https://github.com/jupyter/docker-stacks/issues/915#issuecomment-1068528799
HEALTHCHECK --interval=15s --timeout=3s --start-period=5s --retries=3 \
CMD wget -O- --no-verbose --tries=1 --no-check-certificate \
http${GEN_CERT:+s}://localhost:8888${JUPYTERHUB_SERVICE_PREFIX:-/}api || exit 1
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
CMD /etc/jupyter/docker_healthcheck.py || exit 1

# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}
Expand Down Expand Up @@ -214,8 +262,6 @@ RUN apt-get update --yes && \
tzdata \
unzip \
vim-tiny \
# Inkscape is installed to be able to convert SVG files
inkscape \
# git-over-ssh
openssh-client \
# less is needed to run help in R
Expand All @@ -225,7 +271,9 @@ RUN apt-get update --yes && \
# https://nbconvert.readthedocs.io/en/latest/install.html#installing-tex
texlive-xetex \
texlive-fonts-recommended \
texlive-plain-generic && \
texlive-plain-generic \
# Enable clipboard on Linux host systems
xclip && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Create alternative for nano -> nano-tiny
Expand All @@ -234,6 +282,12 @@ RUN update-alternatives --install /usr/bin/nano nano /bin/nano-tiny 10
# Switch back to jovyan to avoid accidental container runs as root
USER ${NB_UID}

# Add R mimetype option to specify how the plot returns from R to the browser
COPY --chown=${NB_UID}:${NB_GID} Rprofile.site /opt/conda/lib/R/etc/

# Add setup scripts that may be used by downstream images or inherited images
COPY setup-scripts/ /opt/setup-scripts/

############################################################################
################# Dependency: jupyter/scipy-notebook #######################
############################################################################
Expand Down Expand Up @@ -264,7 +318,7 @@ RUN apt-get update --yes && \
USER ${NB_UID}

# Install Python 3 packages
RUN mamba install --quiet --yes \
RUN mamba install --yes \
'altair' \
'beautifulsoup4' \
'bokeh' \
Expand All @@ -277,9 +331,11 @@ RUN mamba install --quiet --yes \
'h5py' \
'ipympl'\
'ipywidgets' \
'jupyterlab-git' \
'matplotlib-base' \
'numba' \
'numexpr' \
'openpyxl' \
'pandas' \
'patsy' \
'protobuf' \
Expand All @@ -300,7 +356,7 @@ RUN mamba install --quiet --yes \
# Install facets which does not have a pip or conda package at the moment
WORKDIR /tmp
RUN git clone https://github.com/PAIR-code/facets.git && \
jupyter nbextension install facets/facets-dist/ --sys-prefix && \
jupyter nbclassic-extension install facets/facets-dist/ --sys-prefix && \
rm -rf /tmp/facets && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
Expand All @@ -326,30 +382,30 @@ LABEL maintainer="Christoph Schranz <christoph.schranz@salzburgresearch.at>, Mat
# installation via conda leads to errors in version 4.8.2
USER ${NB_UID}
RUN pip install --upgrade pip && \
pip install --no-cache-dir tensorflow==2.10.1 keras==2.10 && \
pip install --no-cache-dir tensorflow==2.15.0 keras==2.15.0 && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

# Install PyTorch with dependencies
RUN conda install --quiet --yes \
pyyaml mkl mkl-include setuptools cmake cffi typing && \
conda clean --all -f -y && \
RUN mamba install --quiet --yes \
pyyaml setuptools cmake cffi typing && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

# Check compatibility here:
# https://pytorch.org/get-started/locally/
# Installation via conda leads to errors installing cudatoolkit=11.1
# RUN pip install --no-cache-dir torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 && \
# torchviz==0.0.2 --extra-index-url https://download.pytorch.org/whl/cu116
# RUN pip install --no-cache-dir torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 && \
# torchviz==0.0.2 --extra-index-url https://download.pytorch.org/whl/cu118
RUN set -ex \
&& buildDeps=' \
torch==1.13.1 \
torchvision==0.14.1 \
torchaudio==0.13.1 \
torch==2.1.0 \
torchvision==0.16.0 \
torchaudio==2.1.0 \
torchviz==0.0.2 \
' \
&& pip install --no-cache-dir $buildDeps --extra-index-url https://download.pytorch.org/whl/cu116 \
&& pip install --no-cache-dir $buildDeps --extra-index-url https://download.pytorch.org/whl/cu118 \
&& fix-permissions "${CONDA_DIR}" \
&& fix-permissions "/home/${NB_USER}"

Expand All @@ -363,13 +419,13 @@ RUN apt-get update && \

# reinstall nvcc with cuda-nvcc to install ptax
USER $NB_UID
RUN conda install -c nvidia cuda-nvcc -y && \
conda clean --all -f -y && \
RUN mamba install -c nvidia cuda-nvcc -y && \
mamba clean --all -f -y && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER

USER root
RUN ln -s /opt/conda/bin/ptxas /usr/bin/ptxas
RUN ln -s $CONDA_DIR/bin/ptxas /usr/bin/ptxas

USER $NB_UID

Expand Down
4 changes: 4 additions & 0 deletions .build/Rprofile.site
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Add R mimetype to specify how the plot returns from R to the browser.
# https://notebook.community/andrie/jupyter-notebook-samples/Changing%20R%20plot%20options%20in%20Jupyter

options(jupyter.plot_mimetypes = c('text/plain', 'image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf'))
2 changes: 1 addition & 1 deletion .build/docker-stacks
Submodule docker-stacks updated 138 files
21 changes: 21 additions & 0 deletions .build/docker_healthcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import json
import os
from pathlib import Path

import requests

# A number of operations below deliberately don't check for possible errors
# As this is a healthcheck, it should succeed or raise an exception on error

runtime_dir = Path("/home/") / os.environ["NB_USER"] / ".local/share/jupyter/runtime/"
json_file = next(runtime_dir.glob("*server-*.json"))

url = json.loads(json_file.read_bytes())["url"]
url = url + "api"

r = requests.get(url, verify=False) # request without SSL verification
r.raise_for_status()
print(r.content)
6 changes: 3 additions & 3 deletions .build/fix-permissions
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ for d in "$@"; do
-group "${NB_GID}" \
-a -perm -g+rwX \
\) \
-exec chgrp "${NB_GID}" {} \; \
-exec chmod g+rwX {} \;
-exec chgrp "${NB_GID}" -- {} \+ \
-exec chmod g+rwX -- {} \+
# setuid, setgid *on directories only*
find "${d}" \
\( \
-type d \
-a ! -perm -6000 \
\) \
-exec chmod +6000 {} \;
-exec chmod +6000 -- {} \+
done
4 changes: 3 additions & 1 deletion .build/jupyter_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

c = get_config() # noqa: F821
c.ServerApp.ip = "0.0.0.0"
c.ServerApp.port = 8888
c.ServerApp.open_browser = False

# to output both image/svg+xml and application/pdf plot formats in the notebook file
c.InlineBackend.figure_formats = {"png", "jpeg", "svg", "pdf"}

# https://github.com/jupyter/notebook/issues/3130
c.FileContentsManager.delete_to_trash = False

Expand Down
33 changes: 33 additions & 0 deletions .build/setup-scripts/setup-julia-packages.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -exuo pipefail
# Requirements:
# - Run as non-root user
# - The JULIA_PKGDIR environment variable is set
# - Julia is already set up, with the setup-julia.bash command

# Install base Julia packages
julia -e '
import Pkg;
Pkg.update();
Pkg.add([
"HDF5",
"IJulia",
"Pluto"
]);
Pkg.precompile();
'

# Move the kernelspec out to the system share location. Avoids
# problems with runtime UID change not taking effect properly on the
# .local folder in the jovyan home dir. move kernelspec out of home
mv "${HOME}/.local/share/jupyter/kernels/julia"* "${CONDA_DIR}/share/jupyter/kernels/"
chmod -R go+rx "${CONDA_DIR}/share/jupyter"
rm -rf "${HOME}/.local"
fix-permissions "${JULIA_PKGDIR}" "${CONDA_DIR}/share/jupyter"

# Install jupyter-pluto-proxy to get Pluto to work on JupyterHub
mamba install --yes \
'jupyter-pluto-proxy' && \
mamba clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"
Loading

0 comments on commit 78a1079

Please sign in to comment.