ARG VERSION=9.3.3.7
FROM artefact.skatelescope.org/ska-tango-images/tango-itango:${VERSION}

# UID if the user that this container will run under. This is needed to give directories
# that are needed for temporary storage the proper owner and access rights.
ARG CONTAINER_EXECUTION_UID=1000

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
RUN sudo chmod a+rwx /usr/share/jupyter /usr/etc
RUN sudo jupyter nbextension install --sys-prefix --symlink --py jupyter_bokeh
RUN sudo jupyter nbextension enable jupyter_bokeh --py --sys-prefix

# Install profiles for ipython & jupyter
COPY ipython-profiles /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
ENV JUPYTER_RUNTIME_DIR=/tmp
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN sudo chmod +x /usr/bin/tini

# Make sure Jupyter can write to the home directory
ENV HOME=/home/user
RUN sudo mkdir -p ${HOME}
RUN sudo chown ${CONTAINER_EXECUTION_UID} -R ${HOME}
RUN sudo chown ${CONTAINER_EXECUTION_UID} -R /opt/ipython-profiles