diff --git a/docker/Dockerfile b/docker/Dockerfile index fbec515..0d7f224 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -96,7 +96,21 @@ ADD minicalosim /root/minicalosim RUN cd /root/minicalosim && git checkout $COMMIT && \ mkdir -p build && cd build && rm -rf * && cmake ../ && make -j4 &&\ cp minicalo* ../bind/G4Calo.py /usr/local/lib/python3.8/dist-packages/ + + +CMD ["start-notebook.py"] + +RUN cp /root/minicalosim/docker/start-notebook.py /usr/local/bin/ +RUN cp /root/minicalosim/docker/start-notebook.sh /usr/local/bin/ +RUN cp /root/minicalosim/docker/start-singleuser.py /usr/local/bin/ +RUN cp /root/minicalosim/docker/start-singleuser.sh /usr/local/bin/ + +#USER root +##RUN fix-permissions /etc/jupyter/ + + # clean up RUN rm -rf /root/minicalosim +#USER ${NB_UID} diff --git a/docker/start-notebook.py b/docker/start-notebook.py new file mode 100755 index 0000000..973da5a --- /dev/null +++ b/docker/start-notebook.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +import os +import shlex +import sys + +# If we are in a JupyterHub, we pass on to `start-singleuser.py` instead so it does the right thing +if "JUPYTERHUB_API_TOKEN" in os.environ: + print( + "WARNING: using start-singleuser.py instead of start-notebook.py to start a server associated with JupyterHub." + ) + command = ["/usr/local/bin/start-singleuser.py"] + sys.argv[1:] + os.execvp(command[0], command) + + +# Entrypoint is start.sh +command = [] + +# If we want to survive restarts, launch the command using `run-one-constantly` +if os.environ.get("RESTARTABLE") == "yes": + command.append("run-one-constantly") + +# We always launch a jupyter subcommand from this script +command.append("jupyter") + +# Launch the configured subcommand. +# Note that this should be a single string, so we don't split it. +# We default to `lab`. +jupyter_command = os.environ.get("DOCKER_STACKS_JUPYTER_CMD", "lab") +command.append(jupyter_command) + +# Append any optional NOTEBOOK_ARGS we were passed in. +# This is supposed to be multiple args passed on to the notebook command, +# so we split it correctly with shlex +if "NOTEBOOK_ARGS" in os.environ: + command += shlex.split(os.environ["NOTEBOOK_ARGS"]) + +# Pass through any other args we were passed on the command line +command += sys.argv[1:] + +# Execute the command! +print("Executing: " + " ".join(command)) +os.execvp(command[0], command) diff --git a/docker/start-notebook.sh b/docker/start-notebook.sh new file mode 100755 index 0000000..c47ebba --- /dev/null +++ b/docker/start-notebook.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Shim to emit warning and call start-notebook.py +echo "WARNING: Use start-notebook.py instead" + +exec /usr/local/bin/start-notebook.py "$@" diff --git a/docker/start-singleuser.py b/docker/start-singleuser.py new file mode 100755 index 0000000..c80339f --- /dev/null +++ b/docker/start-singleuser.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +import os +import shlex +import sys + +# Entrypoint is start.sh +command = ["jupyterhub-singleuser"] + +# set default ip to 0.0.0.0 +if "--ip=" not in os.environ.get("NOTEBOOK_ARGS", ""): + command.append("--ip=0.0.0.0") + +# Append any optional NOTEBOOK_ARGS we were passed in. +# This is supposed to be multiple args passed on to the notebook command, +# so we split it correctly with shlex +if "NOTEBOOK_ARGS" in os.environ: + command += shlex.split(os.environ["NOTEBOOK_ARGS"]) + +# Pass any other args we have been passed through +command += sys.argv[1:] + +# Execute the command! +print("Executing: " + " ".join(command)) +os.execvp(command[0], command) diff --git a/docker/start-singleuser.sh b/docker/start-singleuser.sh new file mode 100755 index 0000000..ecf0e06 --- /dev/null +++ b/docker/start-singleuser.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Shim to emit warning and call start-singleuser.py +echo "WARNING: Use start-singleuser.py instead" + +exec /usr/local/bin/start-singleuser.py "$@"