Skip to content

Commit 96deb9f

Browse files
committed
jupyter#1205: Manage both config files
1 parent 9648e05 commit 96deb9f

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

base-notebook/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ CMD ["start-notebook.sh"]
150150

151151
# Copy local files as late as possible to avoid cache busting
152152
COPY start.sh start-notebook.sh start-singleuser.sh /usr/local/bin/
153-
COPY jupyter_server_config.py /etc/jupyter/
153+
# Need to have both files to be able to use classic and lab
154+
COPY jupyter_notebook_config.py jupyter_server_config.py /etc/jupyter/
154155

155156
# Fix permissions on /etc/jupyter as root
156157
USER root
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
4+
from jupyter_core.paths import jupyter_data_dir
5+
import subprocess
6+
import os
7+
import errno
8+
import stat
9+
10+
c = get_config() # noqa: F821
11+
c.NotebookApp.ip = '0.0.0.0'
12+
c.NotebookApp.port = 8888
13+
c.NotebookApp.open_browser = False
14+
15+
# https://github.com/jupyter/notebook/issues/3130
16+
c.FileContentsManager.delete_to_trash = False
17+
18+
# Generate a self-signed certificate
19+
if 'GEN_CERT' in os.environ:
20+
dir_name = jupyter_data_dir()
21+
pem_file = os.path.join(dir_name, 'notebook.pem')
22+
try:
23+
os.makedirs(dir_name)
24+
except OSError as exc: # Python >2.5
25+
if exc.errno == errno.EEXIST and os.path.isdir(dir_name):
26+
pass
27+
else:
28+
raise
29+
30+
# Generate an openssl.cnf file to set the distinguished name
31+
cnf_file = os.path.join(os.getenv('CONDA_DIR', '/usr/lib'), 'ssl', 'openssl.cnf')
32+
if not os.path.isfile(cnf_file):
33+
with open(cnf_file, 'w') as fh:
34+
fh.write('''\
35+
[req]
36+
distinguished_name = req_distinguished_name
37+
[req_distinguished_name]
38+
''')
39+
40+
# Generate a certificate if one doesn't exist on disk
41+
subprocess.check_call(['openssl', 'req', '-new',
42+
'-newkey', 'rsa:2048',
43+
'-days', '365',
44+
'-nodes', '-x509',
45+
'-subj', '/C=XX/ST=XX/L=XX/O=generated/CN=generated',
46+
'-keyout', pem_file,
47+
'-out', pem_file])
48+
# Restrict access to the file
49+
os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)
50+
c.NotebookApp.certfile = pem_file
51+
52+
# Change default umask for all subprocesses of the notebook server if set in
53+
# the environment
54+
if 'NB_UMASK' in os.environ:
55+
os.umask(int(os.environ['NB_UMASK'], 8))

0 commit comments

Comments
 (0)