From centos:7
MAINTAINER Bob Clapp <bob@sep.stanford.edu>


#INSTALL 
RUN yum -y install gcc gcc-c++ epel-release make git cmake  && \
    yum -y install https://centos7.iuscommunity.org/ius-release.rpm && \
    yum -y install  boost-devel boost-filesystem  cmake3 ffmpeg  libX11-devel libXt-devel libXaw-devel wget bzip2&& \
   yum -y clean all


#BASIC JUPYTER ENVIRONMENT

# Install Tini
RUN wget --quiet https://github.com/krallin/tini/releases/download/v0.18.0/tini && \
    echo "12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855 *tini" | sha256sum -c - && \
    mv tini /usr/local/bin/tini && \
    chmod +x /usr/local/bin/tini

# Configure environment
ENV CONDA_DIR=/opt/conda \
    SHELL=/bin/bash \
    NB_USER=jovyan \
    NB_UID=1000 \
    NB_GID=100 \
    LC_ALL=en_US.UTF-8 \
    LANG=en_US.UTF-8 \
    LANGUAGE=en_US.UTF-8
ENV PATH=$CONDA_DIR/bin:$PATH \
    HOME=/home/$NB_USER

ADD fix-permissions /usr/local/bin/fix-permissions
# Create jovyan user with UID=1000 and in the 'users' group
# and make sure these dirs are writable by the `users` group.
#groupadd wheel -g 11 && \

RUN   echo "auth required pam_wheel.so use_uid" >> /etc/pam.d/su && \
    useradd -m -s /bin/bash -N -u $NB_UID $NB_USER && \
    mkdir -p $CONDA_DIR && \
    chown $NB_USER:$NB_GID $CONDA_DIR && \
    chmod g+w /etc/passwd && \
    fix-permissions $HOME && \
    fix-permissions $CONDA_DIR

USER $NB_UID

# Setup work directory for backward-compatibility
RUN mkdir /home/$NB_USER/work && \
    fix-permissions /home/$NB_USER

# Install conda as jovyan and check the md5 sum provided on the download site
ENV MINICONDA_VERSION 4.5.4
RUN cd /tmp && \
    wget --quiet https://repo.continuum.io/miniconda/Miniconda3-${MINICONDA_VERSION}-Linux-x86_64.sh && \
    echo "a946ea1d0c4a642ddf0c3a26a18bb16d *Miniconda3-${MINICONDA_VERSION}-Linux-x86_64.sh" | md5sum -c - && \
    /bin/bash Miniconda3-${MINICONDA_VERSION}-Linux-x86_64.sh -f -b -p $CONDA_DIR && \
    rm Miniconda3-${MINICONDA_VERSION}-Linux-x86_64.sh && \
    $CONDA_DIR/bin/conda config --system --prepend channels conda-forge && \
    $CONDA_DIR/bin/conda config --system --set auto_update_conda false && \
    $CONDA_DIR/bin/conda config --system --set show_channel_urls true && \
    $CONDA_DIR/bin/conda install --quiet --yes conda="${MINICONDA_VERSION%.*}.*" && \
    $CONDA_DIR/bin/conda update --all --quiet --yes && \
    conda clean -tipsy && \
    rm -rf /home/$NB_USER/.cache/yarn && \
    fix-permissions $CONDA_DIR && \
    fix-permissions /home/$NB_USER

USER root

# Install Jupyter Notebook and Hub
RUN conda install --quiet --yes \
    'notebook=5.5.*' \
    'jupyterhub=0.8.*' \
    'jupyterlab=0.32.*' && \
    conda clean -tipsy && \
    jupyter labextension install @jupyterlab/hub-extension@^0.8.1 && \
    npm cache clean --force && \
    rm -rf $CONDA_DIR/share/jupyter/lab/staging && \
    rm -rf /home/$NB_USER/.cache/yarn && \
    fix-permissions $CONDA_DIR && \
    fix-permissions /home/$NB_USER



USER $NB_UID

# use notebook-friendly backends in these images
RUN conda install --quiet --yes \
    'conda-forge::blas=*=openblas' \
    'numexpr' 

RUN pip install     'matplotlib' 

USER root

EXPOSE 8888
WORKDIR $HOME

## Configure container startup
#ENTRYPOINT ["tini", "-g", "--"]
#CMD ["start-notebook.sh"]

# Add local files as late as possible to avoid cache busting
COPY start.sh /usr/local/bin/
COPY start-notebook.sh /usr/local/bin/
COPY start-singleuser.sh /usr/local/bin/
COPY jupyter_notebook_config.py /etc/jupyter/
RUN fix-permissions /etc/jupyter/

# Switch back to jovyan to avoid accidental container runs as root
USER $NB_UID


# Import matplotlib the first time to build the font cache.
ENV XDG_CACHE_HOME /home/$NB_USER/.cache/
RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
    fix-permissions /home/$NB_USER


USER root


RUN yum -y install tbb-devel  fftw-devel fftw-libs-single gcc-gfortran lapack-devel flex  &&\
   yum -y clean all


#INSTALL SEPLIB
RUN git clone  http://zapad.Stanford.EDU/bob/SEPlib.git /opt/SEP/src &&\
  mkdir /opt/SEP/build &&\
  cd /opt/SEP/build && \
  cmake -DCMAKE_INSTALL_PREFIX=/opt/SEP ../src && \
  make install && \
  rm -rf /opt/SEP/bin &&\
  rm -rf /opt/SEP/lib/python 

  RUN pip install pytest

#INSTALL PYBIND
RUN conda install pybind11 -c conda-forge

RUN yum -y install blas-devel liblas-devel openblas-devel   &&\
   yum -y clean all


#INSTALL SYNTHETIC MODEL
RUN  mkdir -p /opt/syntheticModel/build&&  \
git  clone  http://zapad.Stanford.EDU/SEP-external/syntheticModel.git   /opt/syntheticModel/src &&\
   cd /opt/syntheticModel/build && \
   cmake3 -DCMAKE_INSTALL_PREFIX=/opt/SEP  ../src &&\
    make install;

RUN pip install wget
USER $NB_UID

ENV PYTHONPATH /opt/SEP/lib/python
#CMD jupyter-notebook --no-browser --ip 0.0.0.0 --port 8888 /opt/syntheticBuild/src/notebooks


RUN  pip install ipympl
RUN jupyter nbextension enable --py --sys-prefix ipympl 
RUN jupyter labextension install @jupyter-widgets/jupyterlab-manager
USER jovyan
ENV PYTHONPATH /opt/SEP/lib/python
## Configure container startup
ENTRYPOINT ["tini", "-g", "--"]
ENV JUPYTER_ENABLE_LAB yes
CMD ["start-notebook.sh"]

