|
| 1 | +# syntax=docker/dockerfile:1.4 |
| 2 | + |
| 3 | +# https://askubuntu.com/questions/972516/debian-frontend-environment-variable |
| 4 | +ARG DEBIAN_FRONTEND=noninteractive |
| 5 | + |
| 6 | +ARG BASE_IMAGE |
| 7 | +FROM ${BASE_IMAGE} AS build-wheels |
| 8 | +ARG DEBIAN_FRONTEND |
| 9 | + |
| 10 | +# Use a separate container to build wheels to prevent build dependencies in final image |
| 11 | +RUN apt-get -qq update \ |
| 12 | + && apt-get -qq install -y --no-install-recommends \ |
| 13 | + python3.9 python3.9-dev \ |
| 14 | + wget build-essential cmake git \ |
| 15 | + && rm -rf /var/lib/apt/lists/* |
| 16 | + |
| 17 | +# Ensure python3 defaults to python3.9 |
| 18 | +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 |
| 19 | + |
| 20 | +RUN wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \ |
| 21 | + && python3 get-pip.py "pip" |
| 22 | + |
| 23 | + |
| 24 | +FROM build-wheels AS trt-wheels |
| 25 | +ARG DEBIAN_FRONTEND |
| 26 | +ARG TARGETARCH |
| 27 | + |
| 28 | +# python-tensorrt build deps are 3.4 GB! |
| 29 | +RUN apt-get update \ |
| 30 | + && apt-get install -y ccache cuda-cudart-dev-* cuda-nvcc-* libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev \ |
| 31 | + && ([ -e /usr/local/cuda ] || ln -s /usr/local/cuda-* /usr/local/cuda) \ |
| 32 | + && rm -rf /var/lib/apt/lists/*; |
| 33 | + |
| 34 | +# Determine version of tensorrt already installed in base image, e.g. "Version: 8.4.1-1+cuda11.4" |
| 35 | +RUN NVINFER_VER=$(dpkg -s libnvinfer8 | grep -Po "Version: \K.*") \ |
| 36 | + && echo $NVINFER_VER | grep -Po "^\d+\.\d+\.\d+" > /etc/TENSORRT_VER |
| 37 | + |
| 38 | +RUN --mount=type=bind,source=docker/tensorrt/detector/build_python_tensorrt.sh,target=/deps/build_python_tensorrt.sh \ |
| 39 | + --mount=type=cache,target=/root/.ccache \ |
| 40 | + export PATH="/usr/lib/ccache:$PATH" CCACHE_DIR=/root/.ccache CCACHE_MAXSIZE=2G \ |
| 41 | + && TENSORRT_VER=$(cat /etc/TENSORRT_VER) /deps/build_python_tensorrt.sh |
| 42 | + |
| 43 | +COPY docker/tensorrt/requirements-arm64.txt /requirements-tensorrt.txt |
| 44 | +RUN pip3 wheel --wheel-dir=/trt-wheels -r /requirements-tensorrt.txt |
| 45 | + |
| 46 | +FROM build-wheels AS trt-model-wheels |
| 47 | +ARG DEBIAN_FRONTEND |
| 48 | + |
| 49 | +RUN apt-get update \ |
| 50 | + && apt-get install -y protobuf-compiler libprotobuf-dev \ |
| 51 | + && rm -rf /var/lib/apt/lists/* |
| 52 | +RUN --mount=type=bind,source=docker/tensorrt/requirements-models-arm64.txt,target=/requirements-tensorrt-models.txt \ |
| 53 | + pip3 wheel --wheel-dir=/trt-model-wheels -r /requirements-tensorrt-models.txt |
| 54 | + |
| 55 | +FROM wget AS jetson-ffmpeg |
| 56 | +ARG DEBIAN_FRONTEND |
| 57 | +ENV CCACHE_DIR /root/.ccache |
| 58 | +ENV CCACHE_MAXSIZE 2G |
| 59 | +RUN --mount=type=bind,source=docker/tensorrt/build_jetson_ffmpeg.sh,target=/deps/build_jetson_ffmpeg.sh \ |
| 60 | + --mount=type=cache,target=/root/.ccache \ |
| 61 | + /deps/build_jetson_ffmpeg.sh |
| 62 | + |
| 63 | +# Frigate w/ TensorRT for NVIDIA Jetson platforms |
| 64 | +FROM tensorrt-base AS frigate-tensorrt |
| 65 | +RUN apt-get update \ |
| 66 | + && apt-get install -y python-is-python3 libprotobuf17 \ |
| 67 | + && rm -rf /var/lib/apt/lists/* |
| 68 | + |
| 69 | +RUN rm -rf /usr/lib/btbn-ffmpeg/ |
| 70 | +COPY --from=jetson-ffmpeg /rootfs / |
| 71 | + |
| 72 | +COPY --from=trt-wheels /etc/TENSORRT_VER /etc/TENSORRT_VER |
| 73 | +RUN --mount=type=bind,from=trt-wheels,source=/trt-wheels,target=/deps/trt-wheels \ |
| 74 | + --mount=type=bind,from=trt-model-wheels,source=/trt-model-wheels,target=/deps/trt-model-wheels \ |
| 75 | + pip3 install -U /deps/trt-wheels/*.whl /deps/trt-model-wheels/*.whl \ |
| 76 | + && ldconfig |
| 77 | + |
| 78 | +WORKDIR /opt/frigate/ |
| 79 | +COPY --from=rootfs / / |
0 commit comments