From 296518b070a6cfadaa338a5142b72ebbebc83c68 Mon Sep 17 00:00:00 2001 From: antoniochavesgarcia Date: Thu, 16 Nov 2023 22:08:29 +0100 Subject: [PATCH] feat (JupyterHub): Changed base image to a simpler one. --- .github/workflows/jupyterhub-base-gpu.yml | 22 +++++ jupyterhub/base-gpu/Dockerfile | 92 ++++++++++++++++++++ jupyterhub/base-gpu/README.md | 8 ++ jupyterhub/base-gpu/fix-permissions | 35 ++++++++ jupyterhub/base-gpu/jupyter_requirements.txt | 4 + 5 files changed, 161 insertions(+) create mode 100644 .github/workflows/jupyterhub-base-gpu.yml create mode 100644 jupyterhub/base-gpu/Dockerfile create mode 100644 jupyterhub/base-gpu/README.md create mode 100644 jupyterhub/base-gpu/fix-permissions create mode 100644 jupyterhub/base-gpu/jupyter_requirements.txt diff --git a/.github/workflows/jupyterhub-base-gpu.yml b/.github/workflows/jupyterhub-base-gpu.yml new file mode 100644 index 0000000..e81273c --- /dev/null +++ b/.github/workflows/jupyterhub-base-gpu.yml @@ -0,0 +1,22 @@ +on: + push: + paths: + - jupyterhub/base-gpu/**/* + - .github/workflows/jupyterhub-base-gpu.yml + - .github/workflows/builder.yml + branches: + - "master" + - "main" + - "latest" + release: + types: + - created +jobs: + build-jupyterhub-base-gpu: + uses: ./.github/workflows/builder.yml + with: + context: jupyterhub/base-gpu + dockerfile: jupyterhub/base-gpu/Dockerfile + name: ertis-research/jupyterhub-base-gpu + platforms: linux/amd64 + diff --git a/jupyterhub/base-gpu/Dockerfile b/jupyterhub/base-gpu/Dockerfile new file mode 100644 index 0000000..f9c1d9d --- /dev/null +++ b/jupyterhub/base-gpu/Dockerfile @@ -0,0 +1,92 @@ +FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +USER root + +# Install some basic utilities and python3.10 +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + sudo \ + git \ + bzip2 \ + tzdata \ + less \ + xclip \ + libx11-6 \ + nano \ + bat \ + locales \ + sudo \ + openssh-client \ + iputils-ping \ + gpg \ + tini \ + wget \ + && \ + apt-get clean && rm -rf /var/lib/apt/lists/* && \ + echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \ + locale-gen + +# Install EZA +RUN mkdir -p /etc/apt/keyrings && \ + wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | sudo gpg --dearmor -o /etc/apt/keyrings/gierens.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | sudo tee /etc/apt/sources.list.d/gierens.list && \ + chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list && \ + apt update -y && \ + apt install -y eza \ + && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +# alias ls with eza +RUN echo "alias ls='eza'" >> ~/.bashrc +RUN echo "alias cat='batcat'" >> ~/.bashrc + + +# Install Python 3.10 +RUN apt-get update --yes && \ + apt-get install --yes --no-install-recommends \ + python3.10 \ + python3-pip \ + python3.10-dev \ + python3.10-distutils \ + && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +COPY jupyter_requirements.txt /tmp/jupyter_requirements.txt + +RUN pip install --no-cache-dir -r /tmp/jupyter_requirements.txt + +# Initialization of user copied from: +# https://github.com/jupyter/docker-stacks/blob/main/docker-stacks-foundation/Dockerfile + +ARG NB_USER="ertis" +ARG NB_UID="1000" +ARG NB_GID="100" + +# Fix: https://github.com/hadolint/hadolint/wiki/DL4006 +# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014 +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +USER root + +COPY fix-permissions /usr/local/bin/fix-permissions +RUN chmod a+rx /usr/local/bin/fix-permissions + +ENV HOME="/home/${NB_USER}" + +# Enable prompt color in the skeleton .bashrc before creating the default NB_USER +# hadolint ignore=SC2016 +RUN sed -i 's/^#force_color_prompt=yes/force_color_prompt=yes/' /etc/skel/.bashrc + +# Create NB_USER with name jovyan user with UID=1000 and in the 'users' group +# and make sure these dirs are writable by the `users` group. +RUN echo "auth requisite pam_deny.so" >> /etc/pam.d/su && \ + useradd -l -m -s /bin/bash -N -u "${NB_UID}" "${NB_USER}" && \ + chmod g+w /etc/passwd && \ + fix-permissions "${HOME}" + +USER ${NB_UID} + +WORKDIR "${HOME}" \ No newline at end of file diff --git a/jupyterhub/base-gpu/README.md b/jupyterhub/base-gpu/README.md new file mode 100644 index 0000000..fd756bc --- /dev/null +++ b/jupyterhub/base-gpu/README.md @@ -0,0 +1,8 @@ +# Base GPU Jupyter notebook image for Jupyter hub + +Based on the [Jupyter Docker Stacks](https://jupyter-docker-stacks.readthedocs.io/en/latest/index.html) project and [Zonca's JupyterHub JetStream Deploy](https://github.com/zonca/jupyterhub-deploy-kubernetes-jetstream/blob/master/gpu/nvidia-tensorflow-jupyterhub/fix-permissions) + +Please visit the project documentation site for help to use and contribute to this image and others. + +- [Jupyter Docker Stacks on ReadTheDocs](https://jupyter-docker-stacks.readthedocs.io/en/latest/index.html) +- [Selecting an Image :: Core Stacks :: jupyter/docker-stacks-foundation](https://jupyter-docker-stacks.readthedocs.io/en/latest/using/selecting.html#jupyter-docker-stacks-foundation) diff --git a/jupyterhub/base-gpu/fix-permissions b/jupyterhub/base-gpu/fix-permissions new file mode 100644 index 0000000..d167578 --- /dev/null +++ b/jupyterhub/base-gpu/fix-permissions @@ -0,0 +1,35 @@ +#!/bin/bash +# set permissions on a directory +# after any installation, if a directory needs to be (human) user-writable, +# run this script on it. +# It will make everything in the directory owned by the group ${NB_GID} +# and writable by that group. +# Deployments that want to set a specific user id can preserve permissions +# by adding the `--group-add users` line to `docker run`. + +# uses find to avoid touching files that already have the right permissions, +# which would cause massive image explosion + +# right permissions are: +# group=${NB_GID} +# AND permissions include group rwX (directory-execute) +# AND directories have setuid,setgid bits set + +set -e + +for d in "$@"; do + find "${d}" \ + ! \( \ + -group "${NB_GID}" \ + -a -perm -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 -- {} \+ +done diff --git a/jupyterhub/base-gpu/jupyter_requirements.txt b/jupyterhub/base-gpu/jupyter_requirements.txt new file mode 100644 index 0000000..89035a4 --- /dev/null +++ b/jupyterhub/base-gpu/jupyter_requirements.txt @@ -0,0 +1,4 @@ +jupyterhub==4.0.2 +jupyterlab==4.0.8 +notebook==7.0.6 +jupyter_server==2.10.1 \ No newline at end of file