DynamicDevices / ming-original

Balena.io/Docker-compose repo for a containerised #MING (Mosquitto, InfluxDB, NodeRed, Grafana) stack
33 stars 20 forks source link

Add jupyter-lab support #9

Closed MatthewCroughan closed 4 years ago

MatthewCroughan commented 4 years ago

I'm in the process now of doing this on my fork, once done I'll submit a PR.

MatthewCroughan commented 4 years ago

I'm currently having trouble with password management in Jupyter which this stackoverflow has useful discussion on.

https://stackoverflow.com/questions/47092878/auto-configure-jupyter-password-from-command-line

MatthewCroughan commented 4 years ago

Taken from https://github.com/SilvesterHsu/jupyterlab We may at some stage wish to implement a bunch of optional extensions, but for now I'm having too much trouble with them to bother, since they all have their own chains of deps.

    jupyter labextension install @jupyterlab/toc && \
    jupyter labextension install @lckr/jupyterlab_variableinspector && \
    jupyter labextension install @krassowski/jupyterlab_go_to_definition && \
    jupyter labextension install @ryantam626/jupyterlab_code_formatter && \
    jupyter serverextension enable --py jupyterlab_code_formatter && \
    jupyter labextension install @ryantam626/jupyterlab_sublime
MatthewCroughan commented 4 years ago

I've resolved an issue I encountered regarding conditionals based on environment variables. We're going to have to use a start.sh or entry.sh convention to solve it.

https://forums.balena.io/t/can-docker-compose-variables-be-informed-by-service-device-variables-what-about-default-variables/43200/19

TL;DR I wanted a default value to be accepted for the password that Jupyter uses on launch, but also for the user to be able to set one, and have the default not be the used password. I've solved this with this script.

This isn't too dissimilar to how this is handled in Balena-Sense https://github.com/balena-io-projects/balena-sense/blob/master/telegraf/entry.sh

#!/usr/bin/bash

MING_JUPYTER_DEFAULT_PASS=mingstack

# If MING_JUPYTER_PASS is set then hash this password via Jupyter and store it in hashed_password
# otherwise use MING_JUPYTER_DEFAULT_PASS as none has been set by the user

if [[ -n "$MING_JUPYTER_PASS" ]]; then
  hashed_password=$(python3 -c "from notebook.auth import passwd; print(passwd('$MING_JUPYTER_PASS'))")
else
  hashed_password=$(python3 -c "from notebook.auth import passwd; print(passwd('$MING_JUPYTER_DEFAULT_PASS'))")
fi

jupyter lab --ip=0.0.0.0 --NotebookApp.password="$hashed_password"
MatthewCroughan commented 4 years ago

This can be closed once https://github.com/DynamicDevices/ming/pull/10 is merged.

ajlennon commented 4 years ago

Merged the PR