# This is a Docker container definition file for ShuttleTracker
# [https://pmbm.ippt.pan.pl/software/shuttletracker].
#
#
# Installing Docker under Debian Linux and derivatives:
#
#   sudo apt-get install docker
#
#
# Building a container according to the recipe contained in this file:
#
#   docker build . --tag st-container
#
#
# Running ShuttleTracker within the container:
# 
# First, make sure that docker can use X window system:
# 
#   xhost +local:docker
#
# Then, you may launch ShuttleTracker from within the container:
#
#   docker run -e DISPLAY --net=host st-container
#
# Remember to mount volumes with images to analyze (docker run option: -v).

FROM ubuntu:21.04

LABEL description="This is a custom Docker image for ShuttleTracker."
LABEL maintainer="shuttletracker.software@gmail.com"
LABEL version="1.5.3"

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime && \
    export DEBIAN_FRONTEND=noninteractive && \
    apt-get install -y tzdata && \
    dpkg-reconfigure --frontend noninteractive tzdata && \
    apt-get -y --no-install-recommends install libopencv-core4.5 \
                                               libopencv-imgproc4.5 \
                                               libopencv-highgui4.5 \
                                               libopencv-photo4.5 \
                                               libopencv-ml4.5  \
                                               \
                                               libqt5core5a \
                                               libqt5gui5 \
                                               libqt5widgets5 \
                                               libqt5concurrent5 \
                                               libqt5network5 \
                                               libqt5qml5 \
                                               \
                                               libboost-system1.74.0 \
                                               libboost-filesystem1.74.0 \
                                               libboost-regex1.74.0 \
                                               libboost-system1.74.0 \
                                               && \
    apt-get -y --no-install-recommends install wget curl cmake make g++-10 \
                                               \
                                               libopencv-core-dev \
                                               libopencv-dev \
                                               libopencv-imgproc-dev \
                                               libopencv-highgui-dev \
                                               libopencv-photo-dev \
                                               libopencv-ml-dev \
                                               \
                                               qtbase5-dev \
                                               qtbase5-dev-tools \
                                               qttools5-dev \
                                               qtdeclarative5-dev \
                                               \
                                               libboost-dev \
                                               libboost-system-dev \
                                               libboost-filesystem-dev \
                                               libboost-regex-dev \
                                               && \
    apt-get -y --no-install-recommends install nano xvfb \
                                               mesa-utils libgl1-mesa-glx libgl1-mesa-dri \
                                               fonts-dejavu fonts-dejavu-core fonts-dejavu-extra

RUN apt-get -y --no-install-recommends install ca-certificates && \
    update-ca-certificates -f

RUN ( mkdir -p /opt/local/src  &&  cd /opt/local/src  && \
      wget https://pmbm.ippt.pan.pl/software/shuttletracker/release/shuttletracker-1.5.3-source.tar.gz     && \
      wget https://pmbm.ippt.pan.pl/software/shuttletracker/release/shuttletracker-1.5.3-source.tar.gz.md5 && \
      md5sum -c shuttletracker-1.5.3-source.tar.gz.md5  && \
      tar xfz shuttletracker-1.5.3-source.tar.gz  && \
      cd shuttletracker-1.5.3-source  &&  mkdir build  &&  cd build  && \
      cmake .. -DCMAKE_CXX_COMPILER=g++-10 \
               -DCMAKE_BUILD_TYPE=Release \
               -DCMAKE_INSTALL_PREFIX=/opt/local/  && \
      make -j4  &&  make install  &&  rm -fR ../build/* ) && \
      apt-get -y purge ca-certificates

RUN apt-get -y purge wget cmake cmake-data make g++-10 \
                     \
                     libopencv-core-dev \
                     libopencv-dev \
                     libopencv-imgproc-dev \
                     libopencv-highgui-dev \
                     libopencv-photo-dev \
                     libopencv-ml-dev \
                     \
                     qtbase5-dev \
                     qtbase5-dev-tools \
                     qttools5-dev \
                     qtdeclarative5-dev \
                     \
                     libboost-dev \
                     libboost-system-dev \
                     libboost-filesystem-dev \
                     libboost-regex-dev

#RUN apt-get -y install libxcb1 libxcb-xinerama0 libqt5x11extras5 strace xvfb
#RUN apt-get install -y mesa-utils libgl1-mesa-glx

RUN echo "Y" | apt autoremove -f && \
    apt-get -y --allow-remove-essential purge apt

RUN chmod 666 /opt/local/share/shuttletracker/config/settings.ini

## Optionally, you may want to install Python modules for data analysis within the container.
#RUN apt-get -y --no-install-recommends install python3-numpy python3-pandas python3-matplotlib

CMD /opt/local/bin/ShuttleTracker

#export SHUTTLETRACKER_OPENCV_NUM_THREADS=2
#export XDG_RUNTIME_DIR=/tmp

