# syntax = docker/dockerfile-upstream:master-labs # https://askubuntu.com/questions/972516/debian-frontend-environment-variable ARG DEBIAN_FRONTEND=noninteractive FROM debian:11 AS base FROM --platform=linux/amd64 debian:11 AS base_amd64 FROM debian:11-slim AS slim-base FROM slim-base AS wget ARG DEBIAN_FRONTEND RUN apt-get update \ && apt-get install -y wget xz-utils \ && rm -rf /var/lib/apt/lists/* WORKDIR /rootfs FROM base AS nginx ARG DEBIAN_FRONTEND ARG NGINX_VERSION=1.22.1 ARG VOD_MODULE_VERSION=1.30 ARG SECURE_TOKEN_MODULE_VERSION=1.4 ARG RTMP_MODULE_VERSION=1.2.1 RUN --mount=type=tmpfs,target=/tmp --mount=type=tmpfs,target=/var/cache/apt < /etc/pip.conf \ && echo "extra-index-url=https://www.piwheels.org/simple" >> /etc/pip.conf; \ fi COPY requirements.txt /requirements.txt RUN pip3 install -r requirements.txt COPY requirements-wheels.txt /requirements-wheels.txt RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt # 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 # Collect deps in a single layer FROM scratch AS deps-rootfs COPY --from=nginx /usr/local/nginx/ /usr/local/nginx/ COPY --from=go2rtc /rootfs/ / COPY --from=libusb-build /usr/local/lib /usr/local/lib COPY --from=s6-overlay /rootfs/ / COPY --from=models /rootfs/ / COPY docker/rootfs/ / # Frigate deps (ffmpeg, python, nginx, go2rtc, s6-overlay, etc) FROM slim-base AS deps ARG TARGETARCH ARG DEBIAN_FRONTEND # http://stackoverflow.com/questions/48162574/ddg#49462622 ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn # https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support) ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" ENV PATH="/usr/lib/btbn-ffmpeg/bin:/usr/local/go2rtc/bin:/usr/local/nginx/sbin:${PATH}" # Install dependencies RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \ /deps/install_deps.sh RUN --mount=type=bind,from=wheels,source=/wheels,target=/deps/wheels \ pip3 install -U /deps/wheels/*.whl COPY --from=deps-rootfs / / RUN ldconfig EXPOSE 5000 EXPOSE 1935 EXPOSE 8554 EXPOSE 8555 # Fails if cont-init.d fails ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2 # Wait indefinitely for cont-init.d to finish before starting services ENV S6_CMD_WAIT_FOR_SERVICES=1 ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 # Give services (including Frigate) 30 seconds to stop before killing them # But this is not working currently because of: # https://github.com/just-containers/s6-overlay/issues/503 ENV S6_SERVICES_GRACETIME=30000 # Configure logging to prepend timestamps, log to stdout, keep 0 archives and rotate on 10MB ENV S6_LOGGING_SCRIPT="T 1 n0 s10000000 T" # TODO: remove after a new version of s6-overlay is released. See: # https://github.com/just-containers/s6-overlay/issues/460#issuecomment-1327127006 ENV S6_SERVICES_READYTIME=50 ENTRYPOINT ["/init"] CMD [] # Frigate deps with Node.js and NPM for devcontainer FROM deps AS devcontainer # 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 COPY docker/fake_frigate_run /etc/services.d/frigate/run # Install Node 16 RUN apt-get update \ && apt-get install wget -y \ && wget -qO- https://deb.nodesource.com/setup_16.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* \ && 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 # force this to run on amd64 because QEMU is painfully slow FROM --platform=linux/amd64 node:16 AS web-build WORKDIR /work COPY web/package.json web/package-lock.json ./ RUN npm install COPY web/ ./ RUN npm run build \ && mv dist/BASE_PATH/monacoeditorwork/* dist/assets/ \ && rm -rf dist/BASE_PATH # Collect final files in a single layer FROM scratch AS rootfs WORKDIR /opt/frigate/ COPY frigate frigate/ COPY migrations migrations/ COPY --from=web-build /work/dist/ web/ # Frigate final container FROM deps AS frigate WORKDIR /opt/frigate/ COPY --from=rootfs / / # Frigate w/ TensorRT Support as separate image FROM frigate AS frigate-tensorrt RUN --mount=type=bind,from=wheels,source=/trt-wheels,target=/deps/trt-wheels \ pip3 install -U /deps/trt-wheels/*.whl # Dev Container w/ TRT FROM devcontainer AS devcontainer-trt RUN --mount=type=bind,from=wheels,source=/trt-wheels,target=/deps/trt-wheels \ pip3 install -U /deps/trt-wheels/*.whl