# Dockerfile for building and running an example riskscape cli

ARG BASE_IMAGE=gitlab.catalyst.net.nz:4567/riskscape/riskscape/base
FROM ${BASE_IMAGE}

USER root

# cpython plugin is enabled by default, so make sure python3 is installed
RUN apt-get update \
    && apt-get install -y python3 python3-pip python3-numpy python3-scipy python3-pandas python3-matplotlib \
      python3-shapely python3-rasterio python3-geopandas python3-requests python3-bs4 python3-lxml \
      python3-tabulate python3-xgboost bash-completion \
    && ln -s /usr/bin/python3 /usr/bin/python \
    && apt-get autoremove -yq \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* \
    rm -rf /var/lib/apt/lists/*

# install common Python packages that risk modellers tend to use
# NB - why are we fixing the version of scikit learn?  Because in the FENZ project we're loading
# A pickled model, and that's very sensitive to the version of the library.
RUN pip install --break-system-packages scikit-learn==1.3.2 markdown_pdf fpdf contextily jax==0.4.33 tensorflow_probability==0.25.0

RUN mkdir /opt/riskscape-cli
COPY engine/app/build/install/riskscape /opt/riskscape-cli
RUN ln -s /opt/riskscape-cli/bin/riskscape /usr/bin/riskscape
COPY engine/app/build/bash-completion /etc/bash_completion.d/riskscape

# include the Kaiju example in the container, as a reference
RUN mkdir -p /opt/riskscape-cli/examples/getting-started
COPY examples/getting-started /opt/riskscape-cli/examples/getting-started

# kludge to display something a little less alarming than "I have no name!" in the prompt.
# if whoami fails, then just display 'user@' in the bash prompt
RUN echo "whoami > /dev/null 2> /dev/null" >> /etc/bash.bashrc && \
    echo "if [ \$? -ne 0 ]; then"          >> /etc/bash.bashrc && \
    echo "    PS1=\"user@\h:\w\$\""        >> /etc/bash.bashrc && \
    echo "fi"                              >> /etc/bash.bashrc

USER riskscape
WORKDIR /home/riskscape

ENTRYPOINT ["/bin/bash"]
