# Copyright (c) 2012-2018 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Capgemini modified the first verion of this dockerfile
# for Biomass Project
# Contributors:
#   Red Hat, Inc. - initial API and implementation
#   Capgemini for Biomass project

FROM quay.io/eclipse/che-python-3.7:nightly

LABEL maintainer="teddy.kossoko@capgemini.com"
LABEL version="1.0"
LABEL description="Docker file based on ubuntu for eclipse-che workspaces for Biomass project"

USER root

RUN apt-get update \
 && apt-get install -y sudo


# this is where I was running into problems with the other approaches
#RUN sudo apt-get update 

RUN  apt-get update 
RUN  apt-get clean
# Installation of pip, gdal, python3, matplotlib, doxyen
# installation of scikit-learn, pandas, geopandas, fiona,  shapely

RUN  pip3 install --upgrade pip
RUN  sudo apt-get clean
RUN apt-get -y install sudo wget


RUN wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh 
RUN chmod +x Anaconda3-2020.02-Linux-x86_64.sh


RUN   apt-get install -y  --no-install-recommends  rsync software-properties-common python3-lxml python3-pip python3-dev gdal-bin libgdal-dev octave && \ 
       apt-get install -y libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 && \ 
      pip3 install scipy && \
apt-get -y install sudo wget unzip sqlite3 libsqlite3-dev && \
      pip3 install matplotlib && \
      pip3 install property && \
      pip install pillow && \
      pip install -U scikit-learn && \
      pip install pandas && \
      pip install --user fiona && \
      pip install Shapely && \
      pip install opencv-python && \
      pip install octave_kernel && \
     #apt-get -y install doxygen  && \
      apt-get -y install jq && \
      pip3 install --upgrade pip && \
      apt-get -y install gcc && \
      apt-get -y install g++ && \
      add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable && \
      apt-get install gdal-bin && \
      apt-get install libgdal-dev && \
      pip install requests && \
      apt-get install -y unzip git curl && \      
      bash Anaconda3-2020.02-Linux-x86_64.sh -b -p $HOME/miniconda  && \
      export PATH="$HOME/miniconda/bin:$PATH" && \
      rm Anaconda3-2020.02-Linux-x86_64.sh && \
      git clone https://github.com/geopandas/geopandas.git && \
      cd geopandas && \
      pip install .


#RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
#RUN export C_INCLUDE_PATH=/usr/include/gdal

RUN  pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`

RUN pip3 install namedlist==1.7 && \
    pip install scikit-image && \
    pip install equi7grid==0.0.10 && \
    pip install numpydoc==0.8.0 && \
    pip install packaging==19.0 && \
    pip install pyproj==2.1.1 && \
    pip install pytileproj

# installation of GDL
RUN  apt -y install gnudatalanguage

# We add the script folder and the zip file to be able to unzip the structure of the project
COPY initTemplate.sh /usr/bmap/initTemplate.sh
COPY initCredentials.sh /usr/bmap/initCredentials.sh
COPY Project_template.zip /usr/bmap/Project_template.zip
COPY shareAlgorithm.sh /usr/bmap/shareAlgorithm.sh
COPY .gitlab-ci.yml /usr/bmap/.gitlab-ci.yml


# We add the RestClient file
COPY RestClient.py /usr/bmap/RestClient.py
COPY quicklook_raster.py /usr/bmap/quicklook_raster.py
COPY ingestData.py /usr/bmap/ingestData.py
COPY ingestData.sh /usr/bmap/ingestData.sh
COPY OWSLib /usr/modules/OWSLib
COPY maap-s3.sh /usr/bmap/s3

RUN chmod a+rwx /usr/bmap/


RUN  chmod +x /usr/modules/OWSLib
RUN  chmod +x /usr/bmap/initTemplate.sh
RUN  chmod +x /usr/bmap/shareAlgorithm.sh
RUN  chmod +x /usr/bmap/ingestData.sh
RUN  chmod +x /usr/bmap/s3

ENV PATH="/usr/bmap/:${PATH}"
ENV PYTHONPATH="/usr/bmap/:${PYTHONPATH}"
ENV PATH="/usr/modules/:${PATH}"
ENV PYTHONPATH="/usr/modules/:${PYTHONPATH}"
#We add env variable to request the back end
ENV BMAP_BACKEND_URL=http://backend-val.biomass-maap.com/bmap-web/

#USER user
USER 1001
    
#EXPOSE 8080