Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Add option to create JupyterLab config for user (#1439)
Browse files Browse the repository at this point in the history
* Copy config to Jupyter directory

* Create config in Jupyter script

* Copy changes to script-library
  • Loading branch information
jungaretti authored May 11, 2022
1 parent a5358ec commit 55a4179
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion containers/codespaces-linux/.devcontainer/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
RUN bash /tmp/scripts/python-debian.sh "none" "/opt/python/latest" "${PIPX_HOME}" "${USERNAME}" "true" \
# Install JupyterLab and common machine learning packages
&& PYTHON_BINARY="${PYTHON_ROOT}/current/bin/python" \
&& bash /tmp/scripts/jupyterlab-debian.sh "latest" "automatic" ${PYTHON_BINARY} \
&& bash /tmp/scripts/jupyterlab-debian.sh "latest" "automatic" ${PYTHON_BINARY} "true" \
&& bash /tmp/scripts/setup-python-tools.sh ${PYTHON_BINARY} \
# Install rvm, rbenv, any missing base gems
&& chown -R ${USERNAME} /opt/ruby/* \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -e
VERSION=${1:-"latest"}
USERNAME=${2:-"automatic"}
PYTHON=${3:-"python"}
ALLOW_ORIGIN=${4:-""}

# If in automatic mode, determine if a user already exists, if not use vscode
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
Expand Down Expand Up @@ -43,6 +44,18 @@ sudoUserIf() {
fi
}

addToJupyterConfig() {
JUPYTER_DIR="/home/${USERNAME}/.jupyter"
JUPYTER_CONFIG="${JUPYTER_DIR}/jupyter_notebook_config.py"

# Make sure the config file exists
test -d ${JUPYTER_DIR} || sudoUserIf mkdir ${JUPYTER_DIR}
test -f ${JUPYTER_CONFIG} || sudoUserIf touch ${JUPYTER_CONFIG}

# Don't write the same line more than once
grep -q ${1} ${JUPYTER_CONFIG} || echo ${1} >> ${JUPYTER_CONFIG}
}

# Make sure that Python is available
if ! ${PYTHON} --version > /dev/null ; then
echo "You need to install Python before installing JupyterLab."
Expand All @@ -56,3 +69,7 @@ if [ "${VERSION}" = "latest" ]; then
else
sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
fi

if [ "${ALLOW_ORIGIN}" = 'true' ]; then
addToJupyterConfig "c.ServerApp.allow_origin = '*'"
fi
17 changes: 17 additions & 0 deletions script-library/jupyterlab-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set -e
VERSION=${1:-"latest"}
USERNAME=${2:-"automatic"}
PYTHON=${3:-"python"}
ALLOW_ORIGIN=${4:-""}

# If in automatic mode, determine if a user already exists, if not use vscode
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
Expand Down Expand Up @@ -43,6 +44,18 @@ sudoUserIf() {
fi
}

addToJupyterConfig() {
JUPYTER_DIR="/home/${USERNAME}/.jupyter"
JUPYTER_CONFIG="${JUPYTER_DIR}/jupyter_notebook_config.py"

# Make sure the config file exists
test -d ${JUPYTER_DIR} || sudoUserIf mkdir ${JUPYTER_DIR}
test -f ${JUPYTER_CONFIG} || sudoUserIf touch ${JUPYTER_CONFIG}

# Don't write the same line more than once
grep -q ${1} ${JUPYTER_CONFIG} || echo ${1} >> ${JUPYTER_CONFIG}
}

# Make sure that Python is available
if ! ${PYTHON} --version > /dev/null ; then
echo "You need to install Python before installing JupyterLab."
Expand All @@ -56,3 +69,7 @@ if [ "${VERSION}" = "latest" ]; then
else
sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
fi

if [ "${ALLOW_ORIGIN}" = 'true' ]; then
addToJupyterConfig "c.ServerApp.allow_origin = '*'"
fi

0 comments on commit 55a4179

Please sign in to comment.