From 91e2fe8e935f14abb61a8fe811eb01cd60d80d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Jes=C3=BAs?= Date: Wed, 15 Nov 2023 17:07:33 +0100 Subject: [PATCH] fix (JupyterHub): Uploaded start-notebook.py. --- jupyterhub/tensorflow-gpu/Dockerfile | 3 +- jupyterhub/tensorflow-gpu/start-notebook.py | 41 +++++++++++++++++++ jupyterhub/tensorflow-gpu/start-singleuser.py | 23 +++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 jupyterhub/tensorflow-gpu/start-notebook.py create mode 100644 jupyterhub/tensorflow-gpu/start-singleuser.py diff --git a/jupyterhub/tensorflow-gpu/Dockerfile b/jupyterhub/tensorflow-gpu/Dockerfile index b2ea3ac..993a440 100644 --- a/jupyterhub/tensorflow-gpu/Dockerfile +++ b/jupyterhub/tensorflow-gpu/Dockerfile @@ -43,8 +43,7 @@ COPY run-hooks.sh /usr/local/bin/run-hooks.sh COPY --from=base_notebook /usr/local/bin/start-notebook.sh /usr/local/bin/ COPY --from=base_notebook /usr/local/bin/start-singleuser.sh /usr/local/bin/ -COPY --from=base_notebook /usr/local/bin/start-notebook.py /usr/local/bin/ -COPY --from=base_notebook /usr/local/bin/start-singleuser.py /usr/local/bin/ +COPY start-notebook.py start-singleuser.py /usr/local/bin/ # COPY --from=base_notebook /etc/jupyter/jupyter_server_config.py /etc/jupyter/ # COPY --from=base_notebook /etc/jupyter/docker_healthcheck.py /etc/jupyter/ COPY jupyter_server_config.py /etc/jupyter/jupyter_server_config.py diff --git a/jupyterhub/tensorflow-gpu/start-notebook.py b/jupyterhub/tensorflow-gpu/start-notebook.py new file mode 100644 index 0000000..db1efc2 --- /dev/null +++ b/jupyterhub/tensorflow-gpu/start-notebook.py @@ -0,0 +1,41 @@ +#!/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) + + +# Wrap everything in start.sh, no matter what +command = ["/usr/local/bin/start.sh"] + +# If we want to survive restarts, tell that to start.sh +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 commandline +command += sys.argv[1:] + +# Execute the command! +os.execvp(command[0], command) diff --git a/jupyterhub/tensorflow-gpu/start-singleuser.py b/jupyterhub/tensorflow-gpu/start-singleuser.py new file mode 100644 index 0000000..2dcf6c0 --- /dev/null +++ b/jupyterhub/tensorflow-gpu/start-singleuser.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +import os +import shlex +import sys + +command = ["/usr/local/bin/start.sh", "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! +os.execvp(command[0], command)