FROM nvidia/cuda:11.3.0-base-ubuntu20.04

USER root

RUN apt update -y && apt upgrade -y && \
    apt install -y software-properties-common && \
    add-apt-repository ppa:ubuntugis/ubuntugis-unstable -y && \
    apt update -y &&     apt install \
    build-essential \
    python3.8 \
    python3-pip \
    libgeos++-dev \
    libgeos-3.8.0 \
    libgeos-c1v5 \
    libgeos-dev \
    libgeos-doc \
    libspatialindex-dev \
    g++ \
    libgdal-dev \
    gdal-bin \
    libproj-dev \
    libspatialindex-dev \
    geotiff-bin \
    libgl1 \
    python-is-python3 \
    git -y \
    curl -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN pip install -U pip setuptools wheel
RUN pip install -U --no-cache-dir "setuptools<=58.*" \
    cython>=0.29.* \
    numpy>=1.21.0 \
    pip-tools \
    rtree \
    ipykernel \
    black 


# install VS Code (code-server)
RUN curl -fsSL https://code-server.dev/install.sh | sh


# install geowombat or a branch using --branch option
RUN git clone https://github.com/jgrss/geowombat.git #--branch jgrss/features_citests
# install cloned geowombat 
RUN cd geowombat && pip install --user -e .[stac,time,perf,ml,zarr,coreg,tests,docs] 

# add script to debug from
RUN echo ' #%% \n\ 
    import sys \n\  
    sys.path.append("/") \n\ 
    sys.path.append("/geowombat") \n\ 
    import geowombat as gw \n #%%' > ./geowombat/src/debug_script.py

# add debug profile
RUN cd geowombat && mkdir -p .vscode 
RUN  echo '{ \
    "version": "0.2.0", \
    "configurations": [ \
    { \
    "name": "Python: Module", \
    "type": "python",\
    "request": "launch", \
    "module": "geowombat", \
    "justMyCode": false, \
    "env": {"PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT": "25"} \
    } \
    ] \
    }'> ./geowombat/.vscode/launch.json

# install VS Code extensions
RUN code-server    --install-extension ms-python.python \
    --install-extension HoangKimLai.ipython

# start from bash command line
CMD /usr/bin/bash  

# to run debug tests simply run:
# cd geowombat/tests/ && python -m unittest  