FROM jupyter/base-notebook

LABEL maintainer="a.ellery@uq.edu.au"

USER root

RUN cat /etc/os-release
RUN apt-get update
RUN apt-get -y install texlive-binaries
RUN apt-get -y install x11vnc xvfb libglvnd-dev tzdata libasound2

# gmsh
RUN apt-get -y install cmake gfortran g++
RUN apt-get -y install libfltk1.3-dev liblapack-dev libblas-dev \
             libhdf5-dev libfreetype6-dev libgmp-dev
RUN wget http://gmsh.info/src/gmsh-4.4.1-source.tgz
RUN tar zxvf gmsh-4.4.1-source.tgz
RUN cd gmsh-4.4.1-source \
    && cmake . -DENABLE_OPENMP=OFF -DENABLE_OCC=OFF -DENABLE_MPI=OFF \
    && sudo make -j`nproc` install
RUN apt-get -y remove cmake gfortran g++
RUN rm -rf /home/jovyan/gmsh-4.4.1-source

# This fixes the '404 GET react-dom' bug
RUN pip install notebook==6.0.1

RUN conda update -n base conda
RUN conda install --yes ipython
RUN conda install --yes spyder
RUN conda install --yes esys-escript -c aellery -c conda-forge
RUN conda install --yes mayavi -c conda-forge
RUN conda install --yes jupyter_contrib_nbextensions -c conda-forge

# This fixes the '404 GET nbextension' bug
RUN conda install --yes widgetsnbextension -c conda-forge
RUN jupyter nbextension enable --py widgetsnbextension

RUN UBUNTU_FRONTEND=noninteractive

RUN export uid=1000 gid=1000
RUN mkdir -p /home/jovyan
RUN echo "jovyan:x:${uid}:${gid}:Developer,,,:/home/jovyan:/bin/bash" >> /etc/passwd
RUN echo "jovyan:x:${uid}:" >> /etc/group
RUN echo "jovyan ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/jovyan
RUN chmod 0440 /etc/sudoers.d/jovyan
RUN chown ${uid}:${gid} -R /home/jovyan

# USER jovyan
USER $NB_UID

EXPOSE 8888
ENTRYPOINT ["tini", "-g", "--"]
CMD ["/bin/bash"]
# CMD ["start-notebook.sh"]
