From c0574ed1e494371ef0afb56a8a37af81a7172099 Mon Sep 17 00:00:00 2001 From: Mike Lutz Date: Tue, 13 Jun 2017 14:13:26 -0400 Subject: [PATCH] first commit - contains working files --- Dockerfile | 10 +++++++++ README.md | 3 +++ jupyter_notebook_config.py | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 jupyter_notebook_config.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9101abb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM jupyter/minimal-notebook + +ENV NB_USER jovyan + +USER root +COPY jupyter_notebook_config.py /etc/jupyter/ +RUN chown -R $NB_USER:users /etc/jupyter/ + +# Switch back to jovyan to avoid accidental container runs as root +USER $NB_USER diff --git a/README.md b/README.md new file mode 100644 index 0000000..d87464d --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +This is a hack to override the (june 12 2017) jupyter_notebook_config.py in jupyter/docker-stacks minimal-notebook + +Specifically it is adding code to check if an autogenerated cert is already there and if so not to replace it. diff --git a/jupyter_notebook_config.py b/jupyter_notebook_config.py new file mode 100644 index 0000000..e48646d --- /dev/null +++ b/jupyter_notebook_config.py @@ -0,0 +1,42 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +from jupyter_core.paths import jupyter_data_dir +import subprocess +import os +import os.path +import errno +import stat +import sys + +c = get_config() +c.NotebookApp.ip = '*' +c.NotebookApp.port = 8888 +c.NotebookApp.open_browser = False + +# Generate a self-signed certificate +if 'GEN_CERT' in os.environ: + dir_name = jupyter_data_dir() + pem_file = os.path.join(dir_name, 'notebook.pem') + try: + os.makedirs(dir_name) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(dir_name): + pass + else: + raise + # Generate a certificate if one doesn't exist on disk + if os.path.isfile(pem_file): + sys.stderr.write ("Reusing SSL pem file: " + str(pem_file)+"\n") + else: + sys.stderr.write ("Generating new self signed cert..\n.") + subprocess.check_call(['openssl', 'req', '-new', + '-newkey', 'rsa:2048', + '-days', '365', + '-nodes', '-x509', + '-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated', + '-keyout', pem_file, + '-out', pem_file]) + # Restrict access to the file + os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR) + c.NotebookApp.certfile = pem_file