FROM nvidia/cuda:11.2.0-cudnn8-runtime-ubuntu20.04

ENV DEBIAN_FRONTEND noninteractive

# Add cmake repository: https://apt.kitware.com/
RUN apt-get update -y \
 && apt-get install -y apt-transport-https ca-certificates gnupg software-properties-common wget \
 && wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null \
 && apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'

# Install system packages
RUN apt-get update -y && apt-get install -y build-essential git cmake python3 python3-pip libeigen3-dev libopencv-dev libtbb-dev sqlite3 libsqlite3-dev libtiff-dev libssl-dev libblas-dev liblapack-dev

# Install python packages
RUN pip3 install tensorflow-gpu numpy imageio tqdm matplotlib columnar tensorflow-addons timerun pyquaternion pyntcloud pandas ciso8601 colour_demosaicing opencv-python lyft_dataset_sdk nuscenes-devkit open3d pyarrow
RUN pip3 install git+https://github.com/autonomousvision/kitti360Scripts.git

# Build packages from source
RUN git clone https://github.com/USCiLab/cereal && cd cereal && cmake -DJUST_INSTALL_CEREAL=ON . && make -j8 && make install -j8 && cd .. && rm -rf cereal
RUN git clone https://github.com/curl/curl && cd curl && cmake . && make -j8 && make install -j8 && cd .. && rm -rf curl
RUN git clone https://github.com/OSGeo/PROJ.git && cd PROJ && cmake -DBUILD_TESTING=OFF . && make -j8 && make install -j8 && cd .. && rm -rf PROJ
RUN git clone https://github.com/pybind/pybind11 && cd pybind11 && cmake . && make -j8 && make install -j8 && cd .. && rm -rf pybind11
RUN git clone https://github.com/catchorg/Catch2 && cd Catch2 && mkdir build && cd build && cmake .. && make -j8 && make install -j8 && cd ../.. && rm -rf Catch2
RUN git clone https://github.com/JosephP91/curlcpp && cd curlcpp && cmake . && make -j8 && make install -j8 && cd .. && rm -rf curlcpp

RUN git clone https://github.com/xtensor-stack/xtl && cd xtl && cmake . && make -j8 && make install -j8 && cd .. && rm -rf xtl
RUN git clone https://github.com/xtensor-stack/xsimd && cd xsimd && cmake . && make -j8 && make install -j8 && cd .. && rm -rf xsimd
RUN git clone https://github.com/xtensor-stack/xtensor && cd xtensor && cmake . && make -j8 && make install -j8 && cd .. && rm -rf xtensor
RUN git clone https://github.com/xtensor-stack/xtensor-python && cd xtensor-python && cmake . && make -j8 && make install -j8 && cd .. && rm -rf xtensor-python
RUN git clone https://github.com/xtensor-stack/xtensor-blas && cd xtensor-blas && cmake . && make -j8 && make install -j8 && cd .. && rm -rf xtensor-blas
RUN git clone https://github.com/gulrak/filesystem && cd filesystem && cmake -DGHC_FILESYSTEM_BUILD_TESTING=OFF -DGHC_FILESYSTEM_BUILD_EXAMPLES=OFF -DGHC_FILESYSTEM_WITH_INSTALL=ON . && make -j8 && make install -j8 && cd .. && rm -rf filesystem
RUN git clone https://github.com/xtensor-stack/xtensor-io && cd xtensor-io && cmake . && make -j8 && make install -j8 && cd .. && rm -rf xtensor-io

# Build our packages from source
ADD packages /packages

RUN cd /packages/xtensor-interfaces && cmake . && make -j8 && make install -j8
RUN cd /packages/cosy && mkdir build && cd build && cmake .. && make -j8 && make install -j8 && pip3 install -e ./python
RUN cd /packages/tiledwebmaps && mkdir build && cd build && cmake .. && make -j8 && make install -j8 && pip3 install -e ./python
RUN pip3 install -e /packages/mlog
RUN pip3 install -e /packages/tinylogdir
RUN pip3 install -e /packages/tinyobserver
RUN pip3 install -e /packages/tinypl
RUN pip3 install -e /packages/tfcv
RUN cd /packages/georegdata && mkdir build && cd build && cmake .. && make -j8 && pip3 install -e .

ENV PYTHONPATH /packages/georeg
WORKDIR /packages/georeg
