ARG OS_VERSION=arm64v8/ubuntu:noble-20241011
FROM ${OS_VERSION} AS mtfmapper-builder
RUN apt-get update \
      && DEBIAN_FRONTEND="noninteractive" apt-get install -y \
      build-essential \
      wget \
      zlib1g-dev \
      libopencv-dev \
      libeigen3-dev \
      libtclap-dev \
      libcurl4-openssl-dev \
      cmake \
      zip \
      subversion

WORKDIR /app/src/
COPY ./src/mtfmapper_cmakelist.patch /app/src
RUN svn checkout https://svn.code.sf.net/p/mtfmapper/code/trunk mtfmapper-code \
    && cd mtfmapper-code \
    && mkdir build \
    && mv /app/src/mtfmapper_cmakelist.patch bin \
    && cd bin \
    && patch < ./mtfmapper_cmakelist.patch \
    && cd ../build \
    && cmake .. \
    && make -j8

FROM ${OS_VERSION}
ARG CV=406t64
COPY --from=mtfmapper-builder /app/src/mtfmapper-code/build/bin/mtf_mapper /usr/local/bin/mtf_mapper
RUN apt-get update \
    && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
    zlib1g \
    libcurl4 \
    ca-certificates openssl \
    wget \
    zip \
    unzip \
    libuuid1 \
    libfreetype6 \
    fonts-dejavu-core \
    libraw-bin \
    libopencv-core${CV} libopencv-calib3d${CV} libopencv-imgcodecs${CV} libopencv-imgproc${CV} libopencv-features2d${CV} libopencv-flann${CV}

RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
    python3 \
    python3-click \
    python3-numpy \
    python3-inotify \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app/src
COPY ./src/process.py /app/src
COPY ./src/preprocess.py /app/src
COPY ./src/watcher.py /app/src
RUN chmod a+x /app/src/process.py \
    && chmod a+x /app/src/watcher.py 
ENV PYTHONUNBUFFERED=1
ENV PATH="/app/src:${PATH}"
