FROM ubuntu:22.04

LABEL maintainer="Matteo Spanio"

WORKDIR /app

COPY . ./

RUN apt update && apt install libboost-program-options-dev  git build-essential cmake g++ wget unzip python3 python3-pip -y

RUN mkdir opencv_source && cd ./opencv_source && wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.4.zip && wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.4.zip && unzip opencv.zip && unzip opencv_contrib.zip && mkdir -p build && cd ./build && cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.4/modules ../opencv-4.5.4 && make -j4 && make install && cd /app

RUN git clone https://github.com/nlohmann/json.git

RUN cd ./json && mkdir build && cd ./build && cmake .. && make && make install && cd /app

RUN rm -r opencv_source json

RUN cd ./build && cmake .. && make && cd /app

RUN cd ./server && pip install --no-cache-dir -r requirements.txt && cd /app

VOLUME [ "/data" ]

CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--log-config", "server/config.yaml", "--port", "80", "--root-path", "/video-analyzer"]