Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion base-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ ONBUILD RUN echo "Checking for pip 'requirements.txt'..." \
${NB_PYTHON_PREFIX}/bin/pip install --no-cache -r requirements.txt \
; fi

ONBUILD USER root

ONBUILD RUN echo "Copy 'layer-cleanup'..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; pwd; ls \
; cp resources/layer-cleanup.sh /usr/local/bin/ \
; chmod +x /usr/local/bin/layer-cleanup.sh

ONBUILD RUN echo "Executing install scripts..." \
; [ -d binder ] && cd binder \
; [ -d .binder ] && cd .binder \
; for script in $(find "resources" -type f -name "install.sh"); do \
chmod +x "$script"; \
echo "Executing $script"; \
bash "$script"; \
layer-cleanup.sh; \
chown -R ${NB_USER}:${NB_USER} ${HOME}; \
done

ONBUILD USER ${NB_USER}

# If a postBuild file exists, run it!
# After it's done, we try to remove any possible cruft commands there
# leave behind under $HOME - particularly stuff that jupyterlab extensions
Expand All @@ -210,4 +232,4 @@ ONBUILD RUN echo "Checking for 'start'..." \
chmod +x start \
&& cp start /srv/start \
; fi
# ----------------------
# ----------------------
4 changes: 4 additions & 0 deletions base-notebook/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
environment.yml
packages.txt
.dockerignore
19 changes: 19 additions & 0 deletions base-notebook/apt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build-essential
curl
dfc
file
git
htop
jq
less
ncdu
ranger
rclone
rsync
silversearcher-ag
software-properties-common
tig
tmux
tree
unzip
vim
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all this dependencies really needed for this particular change? I feel some are just here for adding tools, but could be in another PR?

31 changes: 31 additions & 0 deletions base-notebook/resources/layer-cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

apt-get autoclean --yes
apt-get autoremove --yes

rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/*
rm -rf /usr/local/src/*

rm -rf /var/cache/apt/*
rm -rf /root/.cache/*
# including /root/.cache/pip
rm -rf /usr/local/share/.cache/*
# including /usr/local/share/.cache/yarn

if [ -x "$(command -v npm)" ]; then
npm cache clean --force
rm -rf /root/.npm/*
rm -rf /root/.node-gyp/*
rm -rf /usr/local/share/jupyter/lab/staging/node_modules/*
rm -rf /opt/*/node_modules/*
fi

rm -rf /tmp/* /var/tmp/*

echo "Layer cleaned"

exit 0
12 changes: 12 additions & 0 deletions base-notebook/resources/nbproxy/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# Copyright 2024 CNES - https://cnes.fr
# All rights reserved
# This file is provided under MIT license. See LICENSE file.
set -e

cp -r resources/nbproxy /opt/jupyter_proxy

chmod -R +rX /opt/jupyter_proxy
pip install --upgrade /opt/jupyter_proxy
# rm -rf /opt/jupyter_proxy
51 changes: 51 additions & 0 deletions base-notebook/resources/nbproxy/jupyter_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

"""
Return config on servers

See https://jupyter-server-proxy.readthedocs.io/en/latest/server-process.html
for more information.
"""
import getpass
import os
import shutil
import shlex
import subprocess


def setup_codeserver():
# Make sure codeserver is in $PATH
def _codeserver_command(port):
full_path = shutil.which("code-server")
if not full_path:
raise FileNotFoundError("Can not find code-server in $PATH")
working_dir = os.getenv("CODE_WORKINGDIR", None)
if working_dir is None:
working_dir = os.path.expanduser("~")
if working_dir is None:
working_dir = os.getenv("JUPYTER_SERVER_ROOT", ".")

return [
full_path,
"--port=" + str(port),
"--auth",
"password",
"--disable-telemetry",
"--extensions-dir",
os.path.join(os.path.join(working_dir, ".vscode"), "extensions"),
working_dir,
]

return {
"command": _codeserver_command,
"timeout": 20,
"launcher_entry": {
"title": "VS Code IDE",
"icon_path": os.path.join(
os.path.dirname(os.path.abspath(__file__)), "icons", "vscode.svg"
),
},
"new_browser_tab": True,
}
61 changes: 61 additions & 0 deletions base-notebook/resources/nbproxy/jupyter_proxy/icons/vscode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions base-notebook/resources/nbproxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"dependencies": {
"typescript": "latest",
"yarn": "^1.12.3"
}
}
26 changes: 26 additions & 0 deletions base-notebook/resources/nbproxy/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

import setuptools

setuptools.setup(
name="jupyter-proxy",
version="0.0.1",
url="https://github.com/jupyterhub/jupyter-server-proxy/tree/master/contrib/theia",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installation process looks complicated, especially in this repo. Couldn't we build a better extension system, maybe in the repo linked above, so that such an extension could be easily installed with standard Jupyter toolset?

author="Project Jupyter Contributors",
description="[email protected]",
packages=setuptools.find_packages(),
keywords=["Jupyter"],
classifiers=["Framework :: Jupyter"],
install_requires=["jupyter-server-proxy"],
entry_points={
"jupyter_serverproxy_servers": [
#'rstudio = jupyter_proxy:setup_rstudio',
"codeserver = jupyter_proxy:setup_codeserver",
]
},
package_data={
"jupyter_proxy": ["icons/*"],
},
)
45 changes: 45 additions & 0 deletions base-notebook/resources/vscode/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# Copyright 2024 CNES - https://cnes.fr
# All rights reserved
# This file is provided under MIT license. See LICENSE file.
set -e

# Code server setup
cp resources/vscode/start-notebook-vscode.sh /usr/local/bin/
chmod +x /usr/local/bin/start-notebook-vscode.sh
mkdir -p /opt/code-server
cp resources/vscode/user-settings.py /opt/code-server/user-settings.py
cd /opt/code-server
curl -fsSL https://code-server.dev/install.sh | \
sh -s -- --prefix /opt/code-server --method standalone

export PATH=/opt/code-server/bin:$PATH
export VSCODE_EXTENSIONS=/opt/code-server/extensions
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt

# Install extensions with retry
retry() {
local -r -i max_attempts=10
local -i attempt_num=1

until "$@"; do
if (( attempt_num == max_attempts )); then
echo "Attempt $attempt_num failed! No more retries left."
return 1
else
echo "Attempt $attempt_num failed! Trying again in 2 seconds..."
sleep 2
fi

attempt_num=$(( attempt_num + 1 ))
done
}

retry bash -c "mkdir -p $VSCODE_EXTENSIONS && \
chmod +rX /opt/code-server/user-settings.py && \
code-server --install-extension ms-toolsai.jupyter --extensions-dir $VSCODE_EXTENSIONS && \
code-server --install-extension ms-python.python --extensions-dir $VSCODE_EXTENSIONS && \
code-server --install-extension mhutchie.git-graph --extensions-dir $VSCODE_EXTENSIONS && \
code-server --install-extension eamodio.gitlens --extensions-dir $VSCODE_EXTENSIONS && \
layer-cleanup.sh"
19 changes: 19 additions & 0 deletions base-notebook/resources/vscode/start-notebook-vscode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Copyright 2024 CS GROUP - https://www.csgroup.eu
# All rights reserved
# This file is provided under MIT license. See LICENSE file.

# VSCode base extensions copy if not already set
export PATH=/opt/code-server/bin:$PATH
export VSCODE_EXTENSIONS=/opt/code-server/extensions
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt

VSCODE_EXTENSIONS_DIR=$HOME/.vscode/extensions
echo "INFO: VSCode extensions folder set up in $VSCODE_EXTENSIONS_DIR"
mkdir -p $VSCODE_EXTENSIONS_DIR
echo "INFO: Avoiding extensions auto update by overriding user settings"
python /opt/code-server/user-settings.py $HOME/.local/share/code-server/User/settings.json
echo "INFO: Copy of VSCode base extensions"
rsync -a /opt/code-server/extensions/ $VSCODE_EXTENSIONS_DIR
echo "INFO: VSCode extensions successfully set up"

24 changes: 24 additions & 0 deletions base-notebook/resources/vscode/user-settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python
# Copyright 2022 CS GROUP - France, http://www.c-s.fr
# All rights reserved

import sys
import json

settings_file_path = sys.argv[1]
try:
try:
with open(settings_file_path) as settings_file:
data = json.load(settings_file)
except FileNotFoundError:
print('ERROR: User settings file not found.. Creating new one')
data = {}

data['extensions.autoUpdate'] = False
data['update.mode'] = "none"
with open(settings_file_path, 'w+') as settings_file:
json.dump(data, settings_file, indent=2)
print('INFO: User settings file successfully overidden')

except:
print('ERROR: Error during VSCode user settings file set up ...')
12 changes: 12 additions & 0 deletions base-notebook/start
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ if ! [[ -z "${PANGEO_SCRATCH_PREFIX}" ]] && ! [[ -z "${JUPYTERHUB_USER}" ]]; the
export PANGEO_SCRATCH="${PANGEO_SCRATCH_PREFIX}/${JUPYTERHUB_USER}/"
fi

echo "[INFO] Executing up startup scripts"
for file in /usr/local/bin/*
do
if [[ $file == *"start-notebook-"* ]]
then
echo "[INFO] Executing $file"
source "$file"
fi
done
echo "[INFO] Executing up startup scripts - Finished"


# ==== ONLY EDIT WITHIN THIS BLOCK =====

exec "$@"
4 changes: 4 additions & 0 deletions ml-notebook/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
environment.yml
packages.txt
.dockerignore
17 changes: 17 additions & 0 deletions ml-notebook/apt.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
build-essential
curl
dfc
file
git
groff
htop
jq
less
ncdu
ranger
rclone
rsync
silversearcher-ag
software-properties-common
tig
tmux
tree
unzip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this normal to have to repeat all the apt package again in ml-notebook?

vim
Loading
Loading