# From Nvidia-supplied tensorrt 7.0.0 image
FROM ubuntu:18.04

WORKDIR /root
# setup environment
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV ROS_DISTRO melodic
ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && apt-get install -q -y \
    dirmngr \
    gnupg2 \
    && rm -rf /var/lib/apt/lists/*

# setup keys
RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

# setup sources.list
RUN echo "deb http://packages.ros.org/ros/ubuntu bionic main" > /etc/apt/sources.list.d/ros-latest.list

RUN apt-get update && apt-get install -q -y --allow-unauthenticated \
    python-catkin-tools \
    python-pip \
    python-tk \
    python-rosdep \
    python-rosinstall \
    python-vcstools

# bootstrap rosdep
RUN rosdep init && \
    rosdep update --rosdistro $ROS_DISTRO

# install ros packages up to perception
RUN apt-get update && apt-get install -y \
    ros-melodic-ros-core=1.4.1-0* \
    ros-melodic-ros-base=1.4.1-0* \
    ros-melodic-perception=1.4.1-0* \
    ros-melodic-rqt-image-view \
    libgl1-mesa-glx \
    libqt5x11extras5 \
    gdal-bin tmux \
    python-gdal \
    && rm -rf /var/lib/apt/lists/*

# -----------------------------------------------------------------------------
# Additional installs so that Spyder can connect to the remote kernel and can
# view Matplotlib results.
RUN pip install \
    anaconda \
    ipython \
    ipykernel \
    matplotlib \
    spyder-kernels
# -----------------------------------------------------------------------------
RUN pip install --no-cache-dir \
    PyGeodesy \
    shapely \
    pyshp \
    simplekml \
    exifread==2.3.2 \
    ujson==1.35 \
    future \
    yacs \
    scipy \
    psutil

RUN pip install Pillow --upgrade

# =================== pull and build rc_genicam_api ==================
RUN git clone https://github.com/roboception/rc_genicam_api.git \
    && cd rc_genicam_api \
    && mkdir build && cd build \
    && cmake -DCMAKE_INSTALL_PREFIX=/usr ..\
    && make && make package \
    && dpkg -i *.deb \
    && rm -rf *.deb

# pull down the need components
SHELL ["/bin/bash", "-c"]
RUN git clone https://gitlab.kitware.com/adapt/adapt_ros_ws.git
RUN cd adapt_ros_ws && \
    git submodule init && \
    git submodule update --recursive && \
    source /opt/ros/melodic/setup.bash \
    && catkin build --force-cmake --no-status --no-summarize --no-notify -DSETUPTOOLS_DEB_LAYOUT=OFF

COPY on_docker_start.sh /root/start_ui.sh

WORKDIR /root/adapt_ros_ws/run_scripts
ENTRYPOINT ["/bin/bash", "/root/start_ui.sh"]
