diff --git a/docker-compose/jupyter.yml b/docker-compose/jupyter.yml index f1970916f7e9facc25908c08c63f0938be0c4eb7..b551592959c6524da8e69edbe65cfb76cdbd00ff 100644 --- a/docker-compose/jupyter.yml +++ b/docker-compose/jupyter.yml @@ -33,5 +33,5 @@ services: - --timeout=30 - --strict - -- - - /usr/bin/tini -- jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --NotebookApp.password= + - /usr/bin/tini -- /usr/local/bin/jupyter-notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --NotebookApp.password= restart: on-failure diff --git a/docker-compose/jupyter/Dockerfile b/docker-compose/jupyter/Dockerfile index 336179e73d9320d6f37edf6cdd13231ef291bcec..7e6f7c14db77042df4c9de9a72f55232496f2d8e 100644 --- a/docker-compose/jupyter/Dockerfile +++ b/docker-compose/jupyter/Dockerfile @@ -1,9 +1,9 @@ ARG VERSION=latest FROM nexus.engageska-portugal.pt/ska-docker/tango-itango:${VERSION} -RUN pip3 install jupyter -RUN pip3 install ipykernel -RUN pip3 install jupyter_bokeh +RUN sudo pip3 install jupyter +RUN sudo pip3 install ipykernel +RUN sudo pip3 install jupyter_bokeh # Configure jupyter_bokeh RUN sudo mkdir -p /usr/share/jupyter /usr/etc @@ -16,6 +16,10 @@ COPY ipython-profiles /opt/ipython-profiles/ RUN sudo chown tango.tango -R /opt/ipython-profiles COPY jupyter-kernels /usr/local/share/jupyter/kernels/ +# Install patched jupyter executable +RUN sudo pip3 install python-logstash-async +COPY jupyter-notebook /usr/local/bin/jupyter-notebook + # Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes. ENV TINI_VERSION v0.6.0 ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini diff --git a/docker-compose/jupyter/jupyter-notebook b/docker-compose/jupyter/jupyter-notebook new file mode 100755 index 0000000000000000000000000000000000000000..59613a137cc1bb5c86b4cd7c82f3a2cb1f9abde3 --- /dev/null +++ b/docker-compose/jupyter/jupyter-notebook @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# An adjustment of the `jupyter-notebook' executable patched to: +# - log to the ELK stack +# +# We go straight for the notebook executable here, as the "jupyter" command +# execvp's into the requested notebook subcommand, erasing all configuration +# we set here. +import re +import sys + +from notebook.notebookapp import main + +from logstash_async.handler import AsynchronousLogstashHandler, LogstashFormatter +import logging + +if __name__ == '__main__': + # log to the tcp_input of logstash in our ELK stack + handler = AsynchronousLogstashHandler("elk", 5959, database_path='/tmp/pending_log_messages.db') + + # add to logger of Jupyter traitlets Application. As that logger is configured not to propagate + # messages upward, we need to configure it directly. + logger = logging.getLogger("NotebookApp") + logger.addHandler(handler) + logger.setLevel(logging.DEBUG) + + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main())