Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
.idea
41 changes: 41 additions & 0 deletions singleuser/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,44 @@ RUN \
[ -d "/home/jovyan/work" ] && rm -r /home/jovyan/work \
# Install dependencies: pip
&& pip install /tmp/ipython-datajoint-creds-updater -r /tmp/config/pip_requirements.txt


# CODE-SERVER INSTALLATION
ARG code_server_proxy_wheel="jupyter_codeserver_proxy-1.0b3-py3-none-any.whl"
ARG JUPYTER_CODESERVER_PROXY_DIR="jupyter_codeserver_proxy_dir"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# prerequisites ----
RUN apt-get update && apt-get install -yq --no-install-recommends \
curl \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# creation of the jupyter_codeserver_proxy package ----
WORKDIR $HOME/$JUPYTER_CODESERVER_PROXY_DIR
COPY setup.py /${HOME}/${JUPYTER_CODESERVER_PROXY_DIR}
COPY jupyter_codeserver_proxy /${HOME}/${JUPYTER_CODESERVER_PROXY_DIR}/jupyter_codeserver_proxy
RUN python setup.py bdist_wheel
WORKDIR ../..

# code-server install ----
RUN wget -qO- https://code-server.dev/install.sh | sh && \
rm -rf "${HOME}/.cache"

# jupyter-server-proxy + code-server proxy install ----
RUN conda install --quiet --yes \
'jupyter-server-proxy' && \
jupyter labextension install @jupyterlab/server-proxy --version latest && \
pip install --quiet --no-cache-dir "${HOME}/${JUPYTER_CODESERVER_PROXY_DIR}/dist/${code_server_proxy_wheel}" && \
rm -rf "${HOME}/${JUPYTER_CODESERVER_PROXY_DIR}" && \
jupyter lab clean -y && \
npm cache clean --force && \
conda clean --all -f -y && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

WORKDIR $HOME
RUN touch .gitconfig
USER $NB_UID
42 changes: 42 additions & 0 deletions singleuser/jupyter_codeserver_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Return config on servers to start for codeserver

See https://jupyter-server-proxy.readthedocs.io/en/latest/server-process.html
for more information.
"""
import os
import shutil
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.getenv("JUPYTER_SERVER_ROOT", ".")

dj_user = os.getenv("DJ_USER", None)
dj_user_email = os.getenv("DJ_USER_EMAIL", None)

# # Run Git commands if user information is provided
if dj_user and dj_user_email:
try:
subprocess.run(['git', 'config', '--global', 'user.name', dj_user], check=True)
subprocess.run(['git', 'config', '--global', 'user.email', dj_user_email], check=True)
except subprocess.CalledProcessError as e:
print(f"Error setting Git user: {e}")

return [full_path, f'--port={port}', "--auth", "none", 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')
}
}
Loading