2022-11-16 13:27:37 +01:00
|
|
|
# syntax=docker/dockerfile:1.2
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
# https://askubuntu.com/questions/972516/debian-frontend-environment-variable
|
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
FROM debian:11 AS base
|
|
|
|
|
2022-12-03 17:19:34 +01:00
|
|
|
FROM --platform=linux/amd64 debian:11 AS base_amd64
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
FROM debian:11-slim AS slim-base
|
|
|
|
|
|
|
|
FROM slim-base AS wget
|
|
|
|
ARG DEBIAN_FRONTEND
|
|
|
|
RUN apt-get update \
|
2022-12-03 17:23:19 +01:00
|
|
|
&& apt-get install -y wget xz-utils \
|
2022-11-22 02:31:39 +01:00
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /rootfs
|
|
|
|
|
2022-12-18 02:39:42 +01:00
|
|
|
FROM base AS nginx
|
2022-12-18 00:53:34 +01:00
|
|
|
ARG DEBIAN_FRONTEND
|
2023-06-30 14:28:48 +02:00
|
|
|
ENV CCACHE_DIR /root/.ccache
|
|
|
|
ENV CCACHE_MAXSIZE 2G
|
2022-12-18 00:53:34 +01:00
|
|
|
|
2023-01-06 13:48:41 +01:00
|
|
|
# bind /var/cache/apt to tmpfs to speed up nginx build
|
|
|
|
RUN --mount=type=tmpfs,target=/tmp --mount=type=tmpfs,target=/var/cache/apt \
|
|
|
|
--mount=type=bind,source=docker/build_nginx.sh,target=/deps/build_nginx.sh \
|
2023-06-30 14:28:48 +02:00
|
|
|
--mount=type=cache,target=/root/.ccache \
|
2023-01-06 13:48:41 +01:00
|
|
|
/deps/build_nginx.sh
|
2022-11-22 02:31:39 +01:00
|
|
|
|
|
|
|
FROM wget AS go2rtc
|
|
|
|
ARG TARGETARCH
|
|
|
|
WORKDIR /rootfs/usr/local/go2rtc/bin
|
2023-05-21 14:53:25 +02:00
|
|
|
RUN wget -qO go2rtc "https://github.com/AlexxIT/go2rtc/releases/download/v1.5.0/go2rtc_linux_${TARGETARCH}" \
|
2022-11-22 02:31:39 +01:00
|
|
|
&& chmod +x go2rtc
|
|
|
|
|
2022-12-30 17:53:17 +01:00
|
|
|
|
|
|
|
####
|
|
|
|
#
|
|
|
|
# OpenVino Support
|
|
|
|
#
|
|
|
|
# 1. Download and convert a model from Intel's Public Open Model Zoo
|
|
|
|
# 2. Build libUSB without udev to handle NCS2 enumeration
|
|
|
|
#
|
|
|
|
####
|
2022-12-03 17:19:34 +01:00
|
|
|
# Download and Convert OpenVino model
|
|
|
|
FROM base_amd64 AS ov-converter
|
|
|
|
ARG DEBIAN_FRONTEND
|
|
|
|
|
|
|
|
# Install OpenVino Runtime and Dev library
|
|
|
|
COPY requirements-ov.txt /requirements-ov.txt
|
|
|
|
RUN apt-get -qq update \
|
|
|
|
&& apt-get -qq install -y wget python3 python3-distutils \
|
|
|
|
&& wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \
|
|
|
|
&& python3 get-pip.py "pip" \
|
|
|
|
&& pip install -r /requirements-ov.txt
|
|
|
|
|
|
|
|
# Get OpenVino Model
|
|
|
|
RUN mkdir /models \
|
|
|
|
&& cd /models && omz_downloader --name ssdlite_mobilenet_v2 \
|
|
|
|
&& cd /models && omz_converter --name ssdlite_mobilenet_v2 --precision FP16
|
|
|
|
|
|
|
|
|
|
|
|
# libUSB - No Udev
|
|
|
|
FROM wget as libusb-build
|
|
|
|
ARG TARGETARCH
|
|
|
|
ARG DEBIAN_FRONTEND
|
2023-06-30 14:28:48 +02:00
|
|
|
ENV CCACHE_DIR /root/.ccache
|
|
|
|
ENV CCACHE_MAXSIZE 2G
|
2022-12-03 17:19:34 +01:00
|
|
|
|
|
|
|
# Build libUSB without udev. Needed for Openvino NCS2 support
|
|
|
|
WORKDIR /opt
|
2023-06-30 14:28:48 +02:00
|
|
|
RUN apt-get update && apt-get install -y unzip build-essential automake libtool ccache
|
|
|
|
RUN --mount=type=cache,target=/root/.ccache wget -q https://github.com/libusb/libusb/archive/v1.0.25.zip -O v1.0.25.zip && \
|
2022-12-03 17:19:34 +01:00
|
|
|
unzip v1.0.25.zip && cd libusb-1.0.25 && \
|
|
|
|
./bootstrap.sh && \
|
2023-06-30 14:28:48 +02:00
|
|
|
./configure CC='ccache gcc' CCX='ccache g++' --disable-udev --enable-shared && \
|
2022-12-03 17:19:34 +01:00
|
|
|
make -j $(nproc --all)
|
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends libusb-1.0-0-dev && \
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /opt/libusb-1.0.25/libusb
|
|
|
|
RUN /bin/mkdir -p '/usr/local/lib' && \
|
|
|
|
/bin/bash ../libtool --mode=install /usr/bin/install -c libusb-1.0.la '/usr/local/lib' && \
|
|
|
|
/bin/mkdir -p '/usr/local/include/libusb-1.0' && \
|
|
|
|
/usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0' && \
|
|
|
|
/bin/mkdir -p '/usr/local/lib/pkgconfig' && \
|
|
|
|
cd /opt/libusb-1.0.25/ && \
|
|
|
|
/usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig' && \
|
|
|
|
ldconfig
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
FROM wget AS models
|
|
|
|
|
|
|
|
# Get model and labels
|
|
|
|
RUN wget -qO edgetpu_model.tflite https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite
|
|
|
|
RUN wget -qO cpu_model.tflite https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess.tflite
|
|
|
|
COPY labelmap.txt .
|
2022-12-03 17:19:34 +01:00
|
|
|
# Copy OpenVino model
|
|
|
|
COPY --from=ov-converter /models/public/ssdlite_mobilenet_v2/FP16 openvino-model
|
2023-01-06 14:03:16 +01:00
|
|
|
RUN wget -q https://github.com/openvinotoolkit/open_model_zoo/raw/master/data/dataset_classes/coco_91cl_bkgr.txt -O openvino-model/coco_91cl_bkgr.txt && \
|
|
|
|
sed -i 's/truck/car/g' openvino-model/coco_91cl_bkgr.txt
|
2023-07-01 15:18:33 +02:00
|
|
|
# Get Audio Model and labels
|
|
|
|
RUN wget -qO cpu_audio_model.tflite https://tfhub.dev/google/lite-model/yamnet/classification/tflite/1?lite-format=tflite
|
|
|
|
COPY audio-labelmap.txt .
|
2022-11-22 02:31:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
FROM wget AS s6-overlay
|
2022-02-22 04:11:10 +01:00
|
|
|
ARG TARGETARCH
|
2022-11-22 02:31:39 +01:00
|
|
|
RUN --mount=type=bind,source=docker/install_s6_overlay.sh,target=/deps/install_s6_overlay.sh \
|
|
|
|
/deps/install_s6_overlay.sh
|
2022-02-18 14:43:30 +01:00
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
|
|
|
|
FROM base AS wheels
|
|
|
|
ARG DEBIAN_FRONTEND
|
2022-11-24 03:00:45 +01:00
|
|
|
ARG TARGETARCH
|
2022-02-18 14:43:30 +01:00
|
|
|
|
|
|
|
# Use a separate container to build wheels to prevent build dependencies in final image
|
|
|
|
RUN apt-get -qq update \
|
|
|
|
&& apt-get -qq install -y \
|
|
|
|
apt-transport-https \
|
|
|
|
gnupg \
|
|
|
|
wget \
|
2022-07-04 16:06:26 +02:00
|
|
|
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E \
|
|
|
|
&& echo "deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi" | tee /etc/apt/sources.list.d/raspi.list \
|
2022-02-18 14:43:30 +01:00
|
|
|
&& apt-get -qq update \
|
|
|
|
&& apt-get -qq install -y \
|
|
|
|
python3 \
|
|
|
|
python3-dev \
|
|
|
|
wget \
|
|
|
|
# opencv dependencies
|
|
|
|
build-essential cmake git pkg-config libgtk-3-dev \
|
|
|
|
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
|
|
|
|
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
|
|
|
|
gfortran openexr libatlas-base-dev libssl-dev\
|
|
|
|
libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
|
|
|
|
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev \
|
|
|
|
# scipy dependencies
|
2023-06-28 12:39:39 +02:00
|
|
|
gcc gfortran libopenblas-dev liblapack-dev \
|
|
|
|
# faster-fifo dependencies
|
|
|
|
g++ cython3 && \
|
2022-12-30 17:53:17 +01:00
|
|
|
rm -rf /var/lib/apt/lists/*
|
2022-02-18 14:43:30 +01:00
|
|
|
|
|
|
|
RUN wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \
|
|
|
|
&& python3 get-pip.py "pip"
|
|
|
|
|
2022-04-12 14:21:21 +02:00
|
|
|
COPY requirements.txt /requirements.txt
|
|
|
|
RUN pip3 install -r requirements.txt
|
2022-02-18 14:43:30 +01:00
|
|
|
|
2022-04-12 14:21:21 +02:00
|
|
|
COPY requirements-wheels.txt /requirements-wheels.txt
|
2022-04-12 15:30:55 +02:00
|
|
|
RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt
|
2022-02-18 14:43:30 +01:00
|
|
|
|
2023-01-07 15:07:56 +01:00
|
|
|
# Make this a separate target so it can be built/cached optionally
|
|
|
|
FROM wheels as trt-wheels
|
|
|
|
ARG DEBIAN_FRONTEND
|
|
|
|
ARG TARGETARCH
|
|
|
|
|
2022-12-30 17:53:17 +01:00
|
|
|
# Add TensorRT wheels to another folder
|
|
|
|
COPY requirements-tensorrt.txt /requirements-tensorrt.txt
|
|
|
|
RUN mkdir -p /trt-wheels && pip3 wheel --wheel-dir=/trt-wheels -r requirements-tensorrt.txt
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
|
|
|
|
# Collect deps in a single layer
|
|
|
|
FROM scratch AS deps-rootfs
|
|
|
|
COPY --from=nginx /usr/local/nginx/ /usr/local/nginx/
|
|
|
|
COPY --from=go2rtc /rootfs/ /
|
2022-12-03 17:19:34 +01:00
|
|
|
COPY --from=libusb-build /usr/local/lib /usr/local/lib
|
2022-11-22 02:31:39 +01:00
|
|
|
COPY --from=s6-overlay /rootfs/ /
|
|
|
|
COPY --from=models /rootfs/ /
|
|
|
|
COPY docker/rootfs/ /
|
|
|
|
|
|
|
|
|
2022-11-20 14:34:12 +01:00
|
|
|
# Frigate deps (ffmpeg, python, nginx, go2rtc, s6-overlay, etc)
|
2022-11-22 02:31:39 +01:00
|
|
|
FROM slim-base AS deps
|
2022-02-18 14:43:30 +01:00
|
|
|
ARG TARGETARCH
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
ARG DEBIAN_FRONTEND
|
2022-04-24 20:52:12 +02:00
|
|
|
# http://stackoverflow.com/questions/48162574/ddg#49462622
|
|
|
|
ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn
|
2022-11-22 02:31:39 +01:00
|
|
|
|
2022-04-24 20:52:12 +02:00
|
|
|
# https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support)
|
2022-12-31 16:13:08 +01:00
|
|
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
2022-04-24 20:52:12 +02:00
|
|
|
ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility"
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
ENV PATH="/usr/lib/btbn-ffmpeg/bin:/usr/local/go2rtc/bin:/usr/local/nginx/sbin:${PATH}"
|
2022-04-26 14:18:13 +02:00
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
# Install dependencies
|
|
|
|
RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \
|
|
|
|
/deps/install_deps.sh
|
2022-11-02 12:36:09 +01:00
|
|
|
|
2022-11-24 03:00:45 +01:00
|
|
|
RUN --mount=type=bind,from=wheels,source=/wheels,target=/deps/wheels \
|
|
|
|
pip3 install -U /deps/wheels/*.whl
|
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
COPY --from=deps-rootfs / /
|
2022-02-18 14:43:30 +01:00
|
|
|
|
2022-12-03 17:19:34 +01:00
|
|
|
RUN ldconfig
|
|
|
|
|
2022-02-18 14:43:30 +01:00
|
|
|
EXPOSE 5000
|
|
|
|
EXPOSE 1935
|
2022-11-02 12:36:09 +01:00
|
|
|
EXPOSE 8554
|
2023-01-18 14:53:53 +01:00
|
|
|
EXPOSE 8555/tcp 8555/udp
|
|
|
|
|
2022-12-09 03:15:00 +01:00
|
|
|
# Configure logging to prepend timestamps, log to stdout, keep 0 archives and rotate on 10MB
|
|
|
|
ENV S6_LOGGING_SCRIPT="T 1 n0 s10000000 T"
|
2022-12-07 14:47:40 +01:00
|
|
|
|
2022-02-18 14:43:30 +01:00
|
|
|
ENTRYPOINT ["/init"]
|
2022-12-07 14:47:40 +01:00
|
|
|
CMD []
|
2022-02-18 14:43:30 +01:00
|
|
|
|
2022-11-24 03:00:45 +01:00
|
|
|
# Frigate deps with Node.js and NPM for devcontainer
|
|
|
|
FROM deps AS devcontainer
|
2022-11-20 14:34:12 +01:00
|
|
|
|
2022-12-07 14:47:40 +01:00
|
|
|
# Do not start the actual Frigate service on devcontainer as it will be started by VSCode
|
|
|
|
# But start a fake service for simulating the logs
|
2023-01-18 14:53:53 +01:00
|
|
|
COPY docker/fake_frigate_run /etc/s6-overlay/s6-rc.d/frigate/run
|
2022-12-07 14:47:40 +01:00
|
|
|
|
2023-02-19 20:11:12 +01:00
|
|
|
# Create symbolic link to the frigate source code, as go2rtc's create_config.sh uses it
|
|
|
|
RUN mkdir -p /opt/frigate \
|
|
|
|
&& ln -svf /workspace/frigate/frigate /opt/frigate/frigate
|
|
|
|
|
2022-11-20 14:34:12 +01:00
|
|
|
# Install Node 16
|
2022-11-22 02:31:39 +01:00
|
|
|
RUN apt-get update \
|
|
|
|
&& apt-get install wget -y \
|
|
|
|
&& wget -qO- https://deb.nodesource.com/setup_16.x | bash - \
|
2022-11-20 14:34:12 +01:00
|
|
|
&& apt-get install -y nodejs \
|
2022-11-22 02:31:39 +01:00
|
|
|
&& rm -rf /var/lib/apt/lists/* \
|
2022-11-20 14:34:12 +01:00
|
|
|
&& npm install -g npm@9
|
|
|
|
|
|
|
|
WORKDIR /workspace/frigate
|
|
|
|
|
|
|
|
RUN apt-get update \
|
|
|
|
&& apt-get install make -y \
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
RUN --mount=type=bind,source=./requirements-dev.txt,target=/workspace/frigate/requirements-dev.txt \
|
|
|
|
pip3 install -r requirements-dev.txt
|
|
|
|
|
|
|
|
CMD ["sleep", "infinity"]
|
|
|
|
|
|
|
|
|
|
|
|
# Frigate web build
|
2023-06-05 23:13:54 +02:00
|
|
|
# This should be architecture agnostic, so speed up the build on multiarch by not using QEMU.
|
|
|
|
FROM --platform=$BUILDPLATFORM node:16 AS web-build
|
2022-11-20 14:34:12 +01:00
|
|
|
|
|
|
|
WORKDIR /work
|
|
|
|
COPY web/package.json web/package-lock.json ./
|
|
|
|
RUN npm install
|
|
|
|
|
|
|
|
COPY web/ ./
|
2022-12-18 00:55:41 +01:00
|
|
|
RUN npm run build \
|
|
|
|
&& mv dist/BASE_PATH/monacoeditorwork/* dist/assets/ \
|
|
|
|
&& rm -rf dist/BASE_PATH
|
2022-11-20 14:34:12 +01:00
|
|
|
|
2022-11-22 02:31:39 +01:00
|
|
|
# Collect final files in a single layer
|
|
|
|
FROM scratch AS rootfs
|
2022-11-20 14:34:12 +01:00
|
|
|
|
|
|
|
WORKDIR /opt/frigate/
|
|
|
|
COPY frigate frigate/
|
|
|
|
COPY migrations migrations/
|
2022-11-24 03:00:45 +01:00
|
|
|
COPY --from=web-build /work/dist/ web/
|
2022-11-22 02:31:39 +01:00
|
|
|
|
|
|
|
# Frigate final container
|
2022-12-30 17:53:17 +01:00
|
|
|
FROM deps AS frigate
|
2022-11-22 02:31:39 +01:00
|
|
|
|
|
|
|
WORKDIR /opt/frigate/
|
|
|
|
COPY --from=rootfs / /
|
2022-12-30 17:53:17 +01:00
|
|
|
|
2023-07-06 21:20:33 +02:00
|
|
|
# Build TensorRT-specific library
|
|
|
|
FROM nvcr.io/nvidia/tensorrt:23.03-py3 AS trt-deps
|
|
|
|
|
|
|
|
RUN --mount=type=bind,source=docker/support/tensorrt_detector/tensorrt_libyolo.sh,target=/tensorrt_libyolo.sh \
|
|
|
|
/tensorrt_libyolo.sh
|
|
|
|
|
2022-12-30 17:53:17 +01:00
|
|
|
# Frigate w/ TensorRT Support as separate image
|
|
|
|
FROM frigate AS frigate-tensorrt
|
2023-07-06 21:20:33 +02:00
|
|
|
|
|
|
|
#Disable S6 Global timeout
|
|
|
|
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
|
|
|
|
|
|
|
|
ENV TRT_VER=8.5.3
|
|
|
|
ENV YOLO_MODELS="yolov7-tiny-416"
|
|
|
|
|
|
|
|
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
|
|
|
|
COPY --from=trt-deps /usr/local/src/tensorrt_demos /usr/local/src/tensorrt_demos
|
|
|
|
COPY docker/support/tensorrt_detector/rootfs/ /
|
|
|
|
|
2023-01-07 15:07:56 +01:00
|
|
|
RUN --mount=type=bind,from=trt-wheels,source=/trt-wheels,target=/deps/trt-wheels \
|
2023-01-14 20:14:27 +01:00
|
|
|
pip3 install -U /deps/trt-wheels/*.whl && \
|
|
|
|
ldconfig
|
2022-12-30 17:53:17 +01:00
|
|
|
|
|
|
|
# Dev Container w/ TRT
|
|
|
|
FROM devcontainer AS devcontainer-trt
|
|
|
|
|
2023-07-06 21:20:33 +02:00
|
|
|
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
|
|
|
|
COPY --from=trt-deps /usr/local/src/tensorrt_demos /usr/local/src/tensorrt_demos
|
|
|
|
COPY docker/support/tensorrt_detector/rootfs/ /
|
|
|
|
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
|
2023-01-07 15:07:56 +01:00
|
|
|
RUN --mount=type=bind,from=trt-wheels,source=/trt-wheels,target=/deps/trt-wheels \
|
2022-12-30 17:53:17 +01:00
|
|
|
pip3 install -U /deps/trt-wheels/*.whl
|