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

Commit 55a4179

Browse files
authored
Add option to create JupyterLab config for user (#1439)
* Copy config to Jupyter directory * Create config in Jupyter script * Copy changes to script-library
1 parent a5358ec commit 55a4179

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

containers/codespaces-linux/.devcontainer/base.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
7272
RUN bash /tmp/scripts/python-debian.sh "none" "/opt/python/latest" "${PIPX_HOME}" "${USERNAME}" "true" \
7373
# Install JupyterLab and common machine learning packages
7474
&& PYTHON_BINARY="${PYTHON_ROOT}/current/bin/python" \
75-
&& bash /tmp/scripts/jupyterlab-debian.sh "latest" "automatic" ${PYTHON_BINARY} \
75+
&& bash /tmp/scripts/jupyterlab-debian.sh "latest" "automatic" ${PYTHON_BINARY} "true" \
7676
&& bash /tmp/scripts/setup-python-tools.sh ${PYTHON_BINARY} \
7777
# Install rvm, rbenv, any missing base gems
7878
&& chown -R ${USERNAME} /opt/ruby/* \

containers/codespaces-linux/.devcontainer/library-scripts/jupyterlab-debian.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set -e
1414
VERSION=${1:-"latest"}
1515
USERNAME=${2:-"automatic"}
1616
PYTHON=${3:-"python"}
17+
ALLOW_ORIGIN=${4:-""}
1718

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

47+
addToJupyterConfig() {
48+
JUPYTER_DIR="/home/${USERNAME}/.jupyter"
49+
JUPYTER_CONFIG="${JUPYTER_DIR}/jupyter_notebook_config.py"
50+
51+
# Make sure the config file exists
52+
test -d ${JUPYTER_DIR} || sudoUserIf mkdir ${JUPYTER_DIR}
53+
test -f ${JUPYTER_CONFIG} || sudoUserIf touch ${JUPYTER_CONFIG}
54+
55+
# Don't write the same line more than once
56+
grep -q ${1} ${JUPYTER_CONFIG} || echo ${1} >> ${JUPYTER_CONFIG}
57+
}
58+
4659
# Make sure that Python is available
4760
if ! ${PYTHON} --version > /dev/null ; then
4861
echo "You need to install Python before installing JupyterLab."
@@ -56,3 +69,7 @@ if [ "${VERSION}" = "latest" ]; then
5669
else
5770
sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
5871
fi
72+
73+
if [ "${ALLOW_ORIGIN}" = 'true' ]; then
74+
addToJupyterConfig "c.ServerApp.allow_origin = '*'"
75+
fi

script-library/jupyterlab-debian.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set -e
1414
VERSION=${1:-"latest"}
1515
USERNAME=${2:-"automatic"}
1616
PYTHON=${3:-"python"}
17+
ALLOW_ORIGIN=${4:-""}
1718

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

47+
addToJupyterConfig() {
48+
JUPYTER_DIR="/home/${USERNAME}/.jupyter"
49+
JUPYTER_CONFIG="${JUPYTER_DIR}/jupyter_notebook_config.py"
50+
51+
# Make sure the config file exists
52+
test -d ${JUPYTER_DIR} || sudoUserIf mkdir ${JUPYTER_DIR}
53+
test -f ${JUPYTER_CONFIG} || sudoUserIf touch ${JUPYTER_CONFIG}
54+
55+
# Don't write the same line more than once
56+
grep -q ${1} ${JUPYTER_CONFIG} || echo ${1} >> ${JUPYTER_CONFIG}
57+
}
58+
4659
# Make sure that Python is available
4760
if ! ${PYTHON} --version > /dev/null ; then
4861
echo "You need to install Python before installing JupyterLab."
@@ -56,3 +69,7 @@ if [ "${VERSION}" = "latest" ]; then
5669
else
5770
sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
5871
fi
72+
73+
if [ "${ALLOW_ORIGIN}" = 'true' ]; then
74+
addToJupyterConfig "c.ServerApp.allow_origin = '*'"
75+
fi

0 commit comments

Comments
 (0)