From a953f55dea9a1e372688a5f593c0eb533cd0d54c Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno <emmanuelbruno@users.noreply.github.com> Date: Sat, 25 Mar 2023 17:36:16 +0100 Subject: [PATCH] big clean up. --- Dockerfile | 187 +++++++++++++++++++++++------------------ README.md | 45 ++++++++-- condeserver-extensions | 9 ++ create_work_subdirs.sh | 26 +++--- gitinitconfig.sh | 2 + initdockerclient.sh | 12 +++ list_packages | 15 ++++ list_pip | 16 ++++ 8 files changed, 212 insertions(+), 100 deletions(-) create mode 100644 condeserver-extensions create mode 100755 gitinitconfig.sh create mode 100755 initdockerclient.sh create mode 100644 list_packages create mode 100644 list_pip diff --git a/Dockerfile b/Dockerfile index 56b34bc..909487d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,62 @@ -ARG LAB_BASE=jupyter/scipy-notebook:lab-3.6.1 +ARG LAB_BASE=jupyter/minimal-notebook:lab-3.6.1 FROM ${LAB_BASE} +ARG TARGETPLATFORM + +ARG DOCKER_CLI_VERSION="23.0.1" +ARG DOCKER_COMPOSE_VERSION="2.17.0" +ARG DOCKER_BUILDX_VERSION="0.10.4" +ARG DOCKER_CONFIG="/usr/local/lib/docker/cli-plugins" + USER root +# Copy the list artefacts to install +# Ubuntu and PIP packages, ... +COPY list-* /tmp/ + +# Sets a cache for pip packages ENV PIP_CACHE_DIR=/var/cache/buildkit/pip +# We need to remove the default `docker-clean` to avoid cache cleaning RUN --mount=type=cache,target=/var/cache/apt \ - mkdir -p $PIP_CACHE_DIR &&\ - apt-get update --yes && \ - apt-get install --yes -qq --no-install-recommends \ - bash \ - curl \ - less \ - vim \ - zip && \ + mkdir -p $PIP_CACHE_DIR && \ + rm -f /etc/apt/apt.conf.d/docker-clean && \ + apt-get update && \ + apt-get install -qq --yes --no-install-recommends \ + $(cat /tmp/list_packages) && \ rm -rf /var/lib/apt/lists/* +# Installs only the docker client and docker compose +ENV BIN_DIR=/usr/local/bin +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + ARCH_LEG=x86_64; \ + ARCH=amd64; \ + elif [ "$TARGETPLATFORM" = "linux/arm64/v8" ] || [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + ARCH_LEG=aarch64; \ + ARCH=arm64; \ + else \ + ARCH_LEG=amd64; \ + ARCH=amd64; \ + fi && \ + echo -e "\e[93m**** Installs docker ****\e[38;5;241m" && \ + echo "https://download.docker.com/linux/static/stable/${ARCH_LEG}/docker-${DOCKER_CLI_VERSION}.tgz" && \ + echo "https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-${ARCH_LEG}" && \ + echo "https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v${DOCKER_BUILDX_VERSION}.linux-${ARCH}" && \ + curl -sL "https://download.docker.com/linux/static/stable/${ARCH_LEG}/docker-${DOCKER_CLI_VERSION}.tgz" | \ + tar --directory="${BIN_DIR}" --strip-components=1 -zx docker/docker && \ + chmod +x "${BIN_DIR}/docker" && \ + mkdir -p "$DOCKER_CONFIG" && \ + echo -e "\e[93m**** Installs docker compose ****\e[38;5;241m" && \ + curl -sL "https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-${ARCH_LEG}" \ + -o "$DOCKER_CONFIG/docker-compose" && \ + chmod +x "$DOCKER_CONFIG/docker-compose" && \ + echo -e "\e[93m**** Installs docker buildx ****\e[38;5;241m" && \ + curl -sL "https://github.com/docker/buildx/releases/download/v${DOCKER_BUILDX_VERSION}/buildx-v${DOCKER_BUILDX_VERSION}.linux-${ARCH}" \ + -o "$DOCKER_CONFIG/docker-buildx" && \ + chmod +x "$DOCKER_CONFIG/docker-buildx" + + # Sets Defaults directories ENV WORK_DIR $HOME/work ENV NOTEBOOKS_DIR $WORK_DIR/notebooks @@ -26,93 +66,78 @@ ENV DATA_DIR $WORK_DIR/data ENV CODESERVEREXT_DIR /opt/codeserver/extensions ENV CODE_WORKINGDIR $HOME/work ENV CODESERVERDATA_DIR $HOME/work/.codeserver/data +ENV CODE_EXTRA_EXTENSIONSDIR $HOME/work/.codeserver/extensions ENV PATH=/opt/bin:$PATH # Enable persistant conda env COPY condarc /home/jovyan/.condarc -# Install JupyterLab -RUN --mount=type=cache,target=/var/cache/buildkit/pip \ +RUN --mount=type=cache,target=${PIP_CACHE_DIR} \ --mount=type=cache,target=/opt/conda/pkgs \ - echo -e "\e[93m***** Install Jupyter Lab Extensions ****\e[38;5;241m" && \ - pip install --quiet --no-cache-dir --upgrade \ - jupyter-book \ - jupyter-server-proxy \ - nbgitpuller \ - jupyterlab_latex \ - jupyterlab-git \ - jupyterlab-system-monitor \ - jinja-yaml-magic \ - jupyterlab_widgets \ -# ipympl \ - && \ -# pip install jupyterlab_templates && \ -# jupyter labextension install jupyterlab_templates && \ -# jupyter serverextension enable --py jupyterlab_templates && \ -# conda install defaults::nb_conda_kernels && \ - mamba install --quiet --yes \ - nb_conda_kernels \ - && \ - mamba install --quiet --yes -c conda-forge \ - jupyterlab-drawio \ - # jupyterlab_code_formatter \ - # tectonic texlab chktex \ - && \ - echo -e "\e[93m**** Installs Code Server Web ****\e[38;5;241m" && \ - curl -fsSL https://code-server.dev/install.sh | sh -s -- --prefix=/opt --method=standalone && \ - mkdir -p $CODESERVERDATA_DIR &&\ - mkdir -p $CODESERVEREXT_DIR && \ - PATH=/opt/bin:$PATH code-server \ - --user-data-dir $CODESERVERDATA_DIR\ - --extensions-dir $CODESERVEREXT_DIR \ - --install-extension vscjava.vscode-java-pack \ - --install-extension redhat.vscode-xml \ - --install-extension vscode-icons-team.vscode-icons \ - --install-extension SonarSource.sonarlint-vscode \ - --install-extension GabrielBB.vscode-lombok \ - --install-extension james-yu.latex-workshop \ - --install-extension jebbs.plantuml \ - --install-extension eamodio.gitlens && \ - groupadd codeserver && \ - chgrp -R codeserver $CODESERVEREXT_DIR &&\ - chmod 770 -R $CODESERVEREXT_DIR && \ - adduser "$NB_USER" codeserver && \ - echo -e "\e[93m**** Clean up ****\e[38;5;241m" && \ -# npm cache clean --force && \ -# mamba clean --all -f -y && \ -# jupyter lab clean && \ - rm -rf "/home/${NB_USER}/.cache/yarn" && \ - fix-permissions "$CONDA_DIR" && \ - fix-permissions "/home/$NB_USER" - -COPY configs/* /home/jovyan/.jupyter/ + echo -e "\e[93m***** Install Jupyter Lab Extensions ****\e[38;5;241m" && \ + pip install --quiet --upgrade \ + $(cat /tmp/packages) && \ + mamba install --quiet --yes \ + nb_conda_kernels \ + && \ + mamba install --quiet --yes -c conda-forge \ + jupyterlab-drawio \ + jupyterlab_code_formatter \ + && \ + echo -e "\e[93m**** Installs Code Server Web ****\e[38;5;241m" && \ + curl -fsSL https://code-server.dev/install.sh | sh -s -- --prefix=/opt --method=standalone && \ + mkdir -p $CODESERVERDATA_DIR &&\ + mkdir -p $CODESERVEREXT_DIR && \ + PATH=/opt/bin:$PATH code-server \ + --user-data-dir $CODESERVERDATA_DIR\ + --extensions-dir $CODESERVEREXT_DIR \ + --install-extension ms-python.python \ + --install-extension vscjava.vscode-java-pack \ + --install-extension redhat.vscode-xml \ + --install-extension vscode-icons-team.vscode-icons \ + --install-extension SonarSource.sonarlint-vscode \ + --install-extension GabrielBB.vscode-lombok \ + --install-extension james-yu.latex-workshop \ + --install-extension jebbs.plantuml \ + --install-extension eamodio.gitlens && \ + echo -e "\e[93m**** Clean up ****\e[38;5;241m" && \ +# npm cache clean --force && \ +# mamba clean --all -f -y && \ +# jupyter lab clean && \ + rm -rf "/home/${NB_USER}/.cache/yarn" && \ + fix-permissions "$CODESERVERDATA_DIR" && \ + fix-permissions "$CODESERVEREXT_DIR" && \ + fix-permissions "$CONDA_DIR" && \ + fix-permissions /opt/codeserver/extensions && \ + fix-permissions "/home/$NB_USER" + COPY code-server/jupyter_codeserver_config.py /tmp/ COPY code-server/icons $HOME/.jupyter/icons RUN [[ ! -f /home/jovyan/.jupyter/jupyter_config.py ]] && touch /home/jovyan/.jupyter/jupyter_config.py ; \ cat /tmp/jupyter_codeserver_config.py >> /home/jovyan/.jupyter/jupyter_config.py -# INSTALL NB GRADER FIXE NEEDED -#COPY nbgrader_config.py /tmp/nbgrader_config.py -#RUN python3 -m pip install git+https://github.com/jupyter/nbgrader.git@5a81fd5 && \ -# jupyter nbextension install --symlink --sys-prefix --py nbgrader && \ -# jupyter nbextension enable --sys-prefix --py nbgrader && \ -# jupyter serverextension enable --sys-prefix --py nbgrader && \ -# python3 -m pip install ngshare_exchange && \ - # cat /tmp/nbgrader_config.py >> /etc/jupyter/nbgrader_config.py && \ -# echo -e "\e[93m**** Clean up ****\e[38;5;241m" && \ - # npm cache clean --force && \ -# mamba clean --all -f -y && \ -# jupyter lab clean && \ -# rm -rf "/home/${NB_USER}/.cache/yarn" && \ -# fix-permissions "$CONDA_DIR" && \ -# fix-permissions "/home/$NB_USER" - -#Adds git and ssh sub directories in works -COPY create_work_subdirs.sh /usr/local/bin/before-notebook.d/ +# Creates dirs and files in $HOME/work (persistent) +# adds links from $HOME (not persistent) +# usefull for config files like .gitconfig, .ssh, ... +COPY create_work_subdirs.sh /usr/local/bin/before-notebook.d/create_work_subdirs.sh ENV NEEDED_WORK_DIRS .ssh ENV NEEDED_WORK_FILES .gitconfig +#Git client default initialisation +COPY gitinitconfig.sh /tmp/gitinitconfig.sh + +COPY $PWD/initdockerclient.sh /usr/local/bin/before-notebook.d/initdockerclient.sh + +RUN echo -e "\e[93m**** Update Jupyter config ****\e[38;5;241m" && \ + mkdir -p $HOME/jupyter_data && \ + jupyter lab --generate-config && \ + sed -i -e '/c.ServerApp.root_dir =/ s/= .*/= "\/home\/jovyan\/work"/' \ + -e "s/# \(c.ServerApp.root_dir\)/\1/" \ + $HOME/.jupyter/jupyter_lab_config.py + +RUN ln -s /usr/share/plantuml/plantuml.jar /usr/local/bin/ + USER $NB_USER WORKDIR "${HOME}/work" diff --git a/README.md b/README.md index 8792d5d..3b9388f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,43 @@ -# JupyterLab UTLN Default Image +# JupyterLab Base Image -A base image for the UTLN Jupyter Hub. +A base image for the Jupyter Lab ased on jupyter/minimal-notebook : + +* ZSH +* TexLive +* Code Server Web IDE +* Jupyter Book - * Based on jupyter/scipy-notebook:584f43f06586 - * LateX editor - * Code Server Web IDE +## Quickstart +```bash +docker run --rm --name JupyterDocker-${PWD##*/} \ + --volume data-${PWD##*/}:/home/jovyan/work/${PWD##*/} \ + --publish 8888:8888 \ + --env NB_UID=$UID \ + brunoe/jupyter-base:develop start-notebook.sh --notebook-dir=work/${PWD##*/} +``` + +## Host files and UIDs + +```bash +docker run --rm --name JupyterDocker-${PWD##*/} \ + --user root + --volume $PWD:/home/jovyan/work/${PWD##*/} \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + --publish 8888:8888 \ + --env NB_UID=$UID \ + brunoe/jupyter-base:develop start-notebook.sh --notebook-dir=work/${PWD##*/} +``` + +## With Docker support + +```bash +docker run --rm --name JupyterDocker-${PWD##*/} \ + --user root \ + --privileged=true \ + --volume $PWD:/home/jovyan/work/${PWD##*/} \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + --publish 8888:8888 \ + --env NB_UID=$UID \ + brunoe/jupyter-base:develop start-notebook.sh --notebook-dir=work/${PWD##*/} +``` diff --git a/condeserver-extensions b/condeserver-extensions new file mode 100644 index 0000000..c121263 --- /dev/null +++ b/condeserver-extensions @@ -0,0 +1,9 @@ +--install-extension vscjava.vscode-java-pack +--install-extension redhat.vscode-xml +--install-extension vscode-icons-team.vscode-icons +--install-extension SonarSource.sonarlint-vscode +--install-extension GabrielBB.vscode-lombok +--install-extension james-yu.latex-workshop +--install-extension jebbs.plantuml +--install-extension eamodio.gitlens +--install-extension ms-python.python \ No newline at end of file diff --git a/create_work_subdirs.sh b/create_work_subdirs.sh index e3e792f..67922fb 100755 --- a/create_work_subdirs.sh +++ b/create_work_subdirs.sh @@ -1,22 +1,20 @@ #!/bin/bash for subdir in $NEEDED_WORK_DIRS; do - dir=/home/jovyan/work/$subdir - ln -s $dir /home/jovyan/$subdir - if [ ! -f $dir ]; then - echo Creating $dir - mkdir -p $dir - fix-permissions $dir - # chmod 700 $dir + dir="/home/jovyan/work/$subdir" + ln -s "$dir" "/home/jovyan/$subdir" + if [ ! -f "$dir" ]; then + echo Creating "$dir" + mkdir -p "$dir" fi + fix-permissions "$dir" done for subfile in $NEEDED_WORK_FILES; do - file=/home/jovyan/work/$subfile - ln -s $file /home/jovyan/$subfile - if [ ! -f $file ]; then - echo Creating $file - touch $file - fix-permissions $file - # chmod 700 $dir + file="/home/jovyan/work/$subfile" + ln -s "$file" "/home/jovyan/$subfile" + if [ ! -f "$file" ]; then + echo Creating "$file" + touch "$file" fi + fix-permissions "$file" done diff --git a/gitinitconfig.sh b/gitinitconfig.sh new file mode 100755 index 0000000..0ea4201 --- /dev/null +++ b/gitinitconfig.sh @@ -0,0 +1,2 @@ +!#/bin/bash +git config --global init.defaultBranch master \ No newline at end of file diff --git a/initdockerclient.sh b/initdockerclient.sh new file mode 100755 index 0000000..41b42ac --- /dev/null +++ b/initdockerclient.sh @@ -0,0 +1,12 @@ +#/bin/bash + +## Direct sock mount +if [[ -S /var/run/docker.sock ]]; then + chown jovyan: /var/run/docker.sock + +## Remote docker daemon (like DIND) +elif [[ -f ${DOCKER_TLS_CERTDIR:-/certs}/client ]]; then + mkdir -p /home/jovyan/.docker + cp -v ${DOCKER_TLS_CERTDIR:-/certs}/client/{ca,cert,key}.pem /home/jovyan/.docker + chown -R $NB_USER: /home/jovyan/.docker +fi diff --git a/list_packages b/list_packages new file mode 100644 index 0000000..a60aad0 --- /dev/null +++ b/list_packages @@ -0,0 +1,15 @@ +bash +curl +graphviz +grep +host +imagemagick +jq +latexmk +less +make +plantuml +texlive-full +vim +zip +zsh diff --git a/list_pip b/list_pip new file mode 100644 index 0000000..8d421e0 --- /dev/null +++ b/list_pip @@ -0,0 +1,16 @@ +jinja-yaml-magic +jupyter-book +jupyterlab-myst +jupyter-server-proxy +jupyterlab_latex +jupyterlab_widgets +jupyterlab-code-formatter +black +isort +jupyterlab-git +jupyterlab-system-monitor +nbgitpuller +iplantuml +sphinx-inline-tabs +sphinxcontrib-plantuml +sphinxcontrib-svg2pdfconverter \ No newline at end of file -- GitLab