# 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 eclipse/ubuntu_python
FROM quay.io/eclipse/che-python-3.7:nightly
#FROM python:3.7

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

#RUN adduser --disabled-password --gecos '' docker
#RUN adduser docker sudo
#RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

#USER docker

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

#RUN apt update && apt install sudo && \
#    adduser maapuser && \
#    usermod -aG sudo maapuser

#USER root

RUN python --version
#RUN  chmod 777 /etc/apt/sources.list
RUN  sudo apt-get update 
RUN  sudo 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 install -y  --no-install-recommends  rsync software-properties-common python3-lxml python3-pip python3-dev gdal-bin libgdal-dev octave && \ 
     #apt-get install -y software-properties-common python-software-properties python3-lxml python3-pip &&\
      pip3 install scipy && \
      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 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 && \      
      pip install conda  && \
      apt-get install -y git && \
      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 GDAL

# installation of GDL
RUN  apt -y install gnudatalanguage

# install gdal and matplotlib with CONDA
#RUN conda install -y gdal
#RUN easy_install GDAL
#RUN  pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`

# 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/maap-s3.sh

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/maap-s3.sh

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 1001
    
#EXPOSE 8080