Skip to content
Merged
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
27 changes: 23 additions & 4 deletions apps/jupyter/run-jupyter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ die() {
mkdir -p $HOME/.jupyter
if [[ -f /.dockerenv ]]; then
APP_DIR=/app

else
APP_DIR=$(cd "$(dirname "$0")"; pwd)
fi
Expand Down Expand Up @@ -36,13 +37,30 @@ if [[ "${JUPYTER_CONFIG_RESET}" == yes ]]; then
fi

if [[ ! -f "${JUPYTER_CONFIG_DOCKER}" ]]; then
TOKEN=$(openssl rand -hex 24)
s3_token="s3://${JUPYTER_S3_BUCKET}/${JUPYTER_S3_PREFIX}/jupyter_token"
[[ ${s3_token} == "s3:///jupyter_token" ]] && s3_token=""
if [[ ${s3_token} != "" && ! -f "${VOLUME}/token" ]]; then
echo "Trying to fetch token from ${s3_token}"
aws s3 cp ${s3_token} "${VOLUME}/token"
fi
if [[ -f "${VOLUME}/token" ]]; then
echo "Re-using token"
TOKEN=$(cat ${VOLUME}/token)
else
TOKEN=$(openssl rand -hex 24)
echo $TOKEN >${VOLUME}/token
if [[ ${s3_token} != "" ]]; then
echo "Storing jupyter token as ${s3_token}"
aws s3 cp ${VOLUME}/token ${s3_token}
fi
fi
cat >"${JUPYTER_CONFIG_DOCKER}".tmp <<EOF
# Configuration file for notebook.

c = get_config() #noqa

c.IdentityProvider.token = '${TOKEN}'

EOF

if [[ "${JUPYTER_S3_BUCKET}" ]]; then
Expand All @@ -57,7 +75,7 @@ EOF
"") : ;;
*/)
echo "ERROR: JUPYTER_S3_PREFIX ${JUPYTER_S3_PREFIX} must not end in / or no file will be accessible"
exit 1
SETUP_FAILED=true
;;
*)
echo "Using S3 Prefix ${JUPYTER_S3_PREFIX}"
Expand Down Expand Up @@ -130,5 +148,6 @@ fi

trap "kill $!" EXIT

cd "${WORK_DIR}"
poetry run jupyter lab "${SSLARG[@]}" --no-browser --ip 0.0.0.0 "$@"
cd "${APP_DIR}"
poetry run jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
poetry run jupyter lab "${SSLARG[@]}" --no-browser --ip 0.0.0.0 "$@"