Skip to content

Commit dc44a6c

Browse files
authored
Community Supported Boards Framework (blakeblackshear#7114)
* Make main frigate build non rpi specific and build rpi using base image * Add boards to sidebar * Fix docker build * Fix docs build * Update pr branch for testing * remove target from rpi build * Remove manual build * Add push build for rpi * fix typos, improve wording * Add arm build for rpi * Cleanup and add default github ref name * Cleanup docker build file system * Setup to use docker bake * Add ci/cd for bake * Fix path * Fix devcontainer * Set targets * Fix build * Fix syntax * Add wheels target * Move dev container to trt * Update key and fix rpi local * Move requirements files and set intermediate targets * Add back --load * Update docs for community board development * Update installation docs to reflect different builds available * Update docs with official and community supported headers * Update codeowners docs * Update docs * Assemble main and standard builds * Change order of pushes * Remove community board after successful build * Fix rpi bake file names
1 parent d0413e3 commit dc44a6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+384
-100
lines changed

.github/workflows/ci.yml

+32-8
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,48 @@ jobs:
4444
run: make version
4545
- name: Create short sha
4646
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
47-
- name: Build and push
47+
- uses: docker/metadata-action@v4
48+
id: metadata
49+
with:
50+
images: ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ github.ref_name }}-${{ env.SHORT_SHA }}
51+
# avoid overwriting the latest tag because metadata-action does not add a suffix to it
52+
flavor: latest=false,suffix=-${{ matrix.platform }}
53+
# The majority of users running arm64 are rpi users, so the rpi
54+
# build should be the primary arm64 image
55+
- name: Build and push standard build
4856
uses: docker/build-push-action@v4
4957
with:
5058
context: .
59+
file: docker/main/Dockerfile
5160
push: true
5261
platforms: linux/amd64,linux/arm64
5362
target: frigate
5463
tags: |
5564
ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ github.ref_name }}-${{ env.SHORT_SHA }}
5665
cache-from: type=gha
5766
cache-to: type=gha,mode=max
67+
- name: Build and push RPi build
68+
uses: docker/bake-action@v3
69+
with:
70+
push: true
71+
targets: rpi
72+
files: docker/rpi/rpi.hcl
73+
set: |
74+
rpi.tags=ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ github.ref_name }}-${{ env.SHORT_SHA }}-rpi
75+
*.cache-from=type=gha
5876
- name: Build and push TensorRT
59-
uses: docker/build-push-action@v4
77+
uses: docker/bake-action@v3
6078
with:
61-
context: .
6279
push: true
63-
platforms: linux/amd64
64-
target: frigate-tensorrt
65-
tags: |
66-
ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ github.ref_name }}-${{ env.SHORT_SHA }}-tensorrt
67-
cache-from: type=gha
80+
targets: tensorrt
81+
files: docker/tensorrt/trt.hcl
82+
set: |
83+
tensorrt.tags=ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ github.ref_name }}-${{ env.SHORT_SHA }}-tensorrt
84+
*.cache-from=type=gha
85+
- name: Assemble and push default build
86+
uses: int128/docker-manifest-create-action@v1
87+
with:
88+
tags: ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ github.ref_name }}-${{ env.SHORT_SHA }}
89+
suffixes: |
90+
-amd64
91+
-rpi

.github/workflows/pull_request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: Install requirements
7272
run: |
7373
python3 -m pip install -U pip
74-
python3 -m pip install -r requirements-dev.txt
74+
python3 -m pip install -r docker/main/requirements-dev.txt
7575
- name: Check black
7676
run: |
7777
black --check --diff frigate migrations docker *.py

Makefile

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,34 @@ default_target: local
33
COMMIT_HASH := $(shell git log -1 --pretty=format:"%h"|tail -1)
44
VERSION = 0.13.0
55
IMAGE_REPO ?= ghcr.io/blakeblackshear/frigate
6+
GITHUB_REF_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
67
CURRENT_UID := $(shell id -u)
78
CURRENT_GID := $(shell id -g)
9+
BOARDS= #Initialized empty
10+
11+
include docker/*/*.mk
12+
13+
build-boards: $(BOARDS:%=build-%)
14+
15+
push-boards: $(BOARDS:%=push-%)
816

917
version:
1018
echo 'VERSION = "$(VERSION)-$(COMMIT_HASH)"' > frigate/version.py
1119

1220
local: version
13-
docker buildx build --target=frigate --tag frigate:latest --load .
14-
15-
local-trt: version
16-
docker buildx build --target=frigate-tensorrt --tag frigate:latest-tensorrt --load .
21+
docker buildx build --target=frigate --tag frigate:latest --load --file docker/main/Dockerfile .
1722

1823
amd64:
19-
docker buildx build --platform linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) .
20-
docker buildx build --platform linux/amd64 --target=frigate-tensorrt --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH)-tensorrt .
24+
docker buildx build --platform linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile .
2125

2226
arm64:
23-
docker buildx build --platform linux/arm64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) .
27+
docker buildx build --platform linux/arm64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile .
2428

2529
build: version amd64 arm64
26-
docker buildx build --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) .
30+
docker buildx build --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile .
2731

28-
push: build
29-
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) .
30-
docker buildx build --push --platform linux/amd64 --target=frigate-tensorrt --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH)-tensorrt .
32+
push: push-boards
33+
docker buildx build --push --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) --file docker/main/Dockerfile .
3134

3235
run: local
3336
docker run --rm --publish=5000:5000 --volume=${PWD}/config:/config frigate:latest

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
shm_size: "256mb"
1212
build:
1313
context: .
14+
dockerfile: docker/main/Dockerfile
1415
# Use target devcontainer-trt for TensorRT dev
1516
target: devcontainer
1617
deploy:

Dockerfile docker/main/Dockerfile

+12-54
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# syntax=docker/dockerfile:1.2
1+
# syntax=docker/dockerfile:1.4
22

33
# https://askubuntu.com/questions/972516/debian-frontend-environment-variable
44
ARG DEBIAN_FRONTEND=noninteractive
@@ -23,7 +23,7 @@ ENV CCACHE_MAXSIZE 2G
2323

2424
# bind /var/cache/apt to tmpfs to speed up nginx build
2525
RUN --mount=type=tmpfs,target=/tmp --mount=type=tmpfs,target=/var/cache/apt \
26-
--mount=type=bind,source=docker/build_nginx.sh,target=/deps/build_nginx.sh \
26+
--mount=type=bind,source=docker/main/build_nginx.sh,target=/deps/build_nginx.sh \
2727
--mount=type=cache,target=/root/.ccache \
2828
/deps/build_nginx.sh
2929

@@ -47,7 +47,7 @@ FROM base_amd64 AS ov-converter
4747
ARG DEBIAN_FRONTEND
4848

4949
# Install OpenVino Runtime and Dev library
50-
COPY requirements-ov.txt /requirements-ov.txt
50+
COPY docker/main/requirements-ov.txt /requirements-ov.txt
5151
RUN apt-get -qq update \
5252
&& apt-get -qq install -y wget python3 python3-distutils \
5353
&& wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \
@@ -105,7 +105,7 @@ COPY audio-labelmap.txt .
105105

106106
FROM wget AS s6-overlay
107107
ARG TARGETARCH
108-
RUN --mount=type=bind,source=docker/install_s6_overlay.sh,target=/deps/install_s6_overlay.sh \
108+
RUN --mount=type=bind,source=docker/main/install_s6_overlay.sh,target=/deps/install_s6_overlay.sh \
109109
/deps/install_s6_overlay.sh
110110

111111

@@ -119,8 +119,8 @@ RUN apt-get -qq update \
119119
apt-transport-https \
120120
gnupg \
121121
wget \
122-
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E \
123-
&& echo "deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi" | tee /etc/apt/sources.list.d/raspi.list \
122+
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138 \
123+
&& echo "deb http://deb.debian.org/debian bullseye main contrib non-free" | tee /etc/apt/sources.list.d/raspi.list \
124124
&& apt-get -qq update \
125125
&& apt-get -qq install -y \
126126
python3 \
@@ -140,21 +140,12 @@ RUN apt-get -qq update \
140140
RUN wget -q https://bootstrap.pypa.io/get-pip.py -O get-pip.py \
141141
&& python3 get-pip.py "pip"
142142

143-
COPY requirements.txt /requirements.txt
143+
COPY docker/main/requirements.txt /requirements.txt
144144
RUN pip3 install -r requirements.txt
145145

146-
COPY requirements-wheels.txt /requirements-wheels.txt
146+
COPY docker/main/requirements-wheels.txt /requirements-wheels.txt
147147
RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt
148148

149-
# Make this a separate target so it can be built/cached optionally
150-
FROM wheels as trt-wheels
151-
ARG DEBIAN_FRONTEND
152-
ARG TARGETARCH
153-
154-
# Add TensorRT wheels to another folder
155-
COPY requirements-tensorrt.txt /requirements-tensorrt.txt
156-
RUN mkdir -p /trt-wheels && pip3 wheel --wheel-dir=/trt-wheels -r requirements-tensorrt.txt
157-
158149

159150
# Collect deps in a single layer
160151
FROM scratch AS deps-rootfs
@@ -163,7 +154,7 @@ COPY --from=go2rtc /rootfs/ /
163154
COPY --from=libusb-build /usr/local/lib /usr/local/lib
164155
COPY --from=s6-overlay /rootfs/ /
165156
COPY --from=models /rootfs/ /
166-
COPY docker/rootfs/ /
157+
COPY docker/main/rootfs/ /
167158

168159

169160
# Frigate deps (ffmpeg, python, nginx, go2rtc, s6-overlay, etc)
@@ -181,7 +172,7 @@ ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility"
181172
ENV PATH="/usr/lib/btbn-ffmpeg/bin:/usr/local/go2rtc/bin:/usr/local/nginx/sbin:${PATH}"
182173

183174
# Install dependencies
184-
RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \
175+
RUN --mount=type=bind,source=docker/main/install_deps.sh,target=/deps/install_deps.sh \
185176
/deps/install_deps.sh
186177

187178
RUN --mount=type=bind,from=wheels,source=/wheels,target=/deps/wheels \
@@ -207,7 +198,7 @@ FROM deps AS devcontainer
207198

208199
# Do not start the actual Frigate service on devcontainer as it will be started by VSCode
209200
# But start a fake service for simulating the logs
210-
COPY docker/fake_frigate_run /etc/s6-overlay/s6-rc.d/frigate/run
201+
COPY docker/main/fake_frigate_run /etc/s6-overlay/s6-rc.d/frigate/run
211202

212203
# Create symbolic link to the frigate source code, as go2rtc's create_config.sh uses it
213204
RUN mkdir -p /opt/frigate \
@@ -227,7 +218,7 @@ RUN apt-get update \
227218
&& apt-get install make -y \
228219
&& rm -rf /var/lib/apt/lists/*
229220

230-
RUN --mount=type=bind,source=./requirements-dev.txt,target=/workspace/frigate/requirements-dev.txt \
221+
RUN --mount=type=bind,source=./docker/main/requirements-dev.txt,target=/workspace/frigate/requirements-dev.txt \
231222
pip3 install -r requirements-dev.txt
232223

233224
CMD ["sleep", "infinity"]
@@ -259,36 +250,3 @@ FROM deps AS frigate
259250

260251
WORKDIR /opt/frigate/
261252
COPY --from=rootfs / /
262-
263-
# Build TensorRT-specific library
264-
FROM nvcr.io/nvidia/tensorrt:23.03-py3 AS trt-deps
265-
266-
RUN --mount=type=bind,source=docker/support/tensorrt_detector/tensorrt_libyolo.sh,target=/tensorrt_libyolo.sh \
267-
/tensorrt_libyolo.sh
268-
269-
# Frigate w/ TensorRT Support as separate image
270-
FROM frigate AS frigate-tensorrt
271-
272-
#Disable S6 Global timeout
273-
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
274-
275-
ENV TRT_VER=8.5.3
276-
ENV YOLO_MODELS="yolov7-tiny-416"
277-
278-
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
279-
COPY --from=trt-deps /usr/local/src/tensorrt_demos /usr/local/src/tensorrt_demos
280-
COPY docker/support/tensorrt_detector/rootfs/ /
281-
282-
RUN --mount=type=bind,from=trt-wheels,source=/trt-wheels,target=/deps/trt-wheels \
283-
pip3 install -U /deps/trt-wheels/*.whl && \
284-
ldconfig
285-
286-
# Dev Container w/ TRT
287-
FROM devcontainer AS devcontainer-trt
288-
289-
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
290-
COPY --from=trt-deps /usr/local/src/tensorrt_demos /usr/local/src/tensorrt_demos
291-
COPY docker/support/tensorrt_detector/rootfs/ /
292-
COPY --from=trt-deps /usr/local/lib/libyolo_layer.so /usr/local/lib/libyolo_layer.so
293-
RUN --mount=type=bind,from=trt-wheels,source=/trt-wheels,target=/deps/trt-wheels \
294-
pip3 install -U /deps/trt-wheels/*.whl
File renamed without changes.
File renamed without changes.

docker/install_deps.sh docker/main/install_deps.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ fi
4141

4242
# ffmpeg -> arm64
4343
if [[ "${TARGETARCH}" == "arm64" ]]; then
44-
# add raspberry pi repo
45-
gpg --no-default-keyring --keyring /usr/share/keyrings/raspbian.gpg --keyserver keyserver.ubuntu.com --recv-keys 82B129927FA3303E
46-
echo "deb [signed-by=/usr/share/keyrings/raspbian.gpg] https://archive.raspberrypi.org/debian/ bullseye main" | tee /etc/apt/sources.list.d/raspi.list
47-
apt-get -qq update
48-
apt-get -qq install --no-install-recommends --no-install-suggests -y ffmpeg
44+
mkdir -p /usr/lib/btbn-ffmpeg
45+
wget -qO btbn-ffmpeg.tar.xz "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2022-07-31-12-37/ffmpeg-n5.1-2-g915ef932a3-linuxarm64-gpl-5.1.tar.xz"
46+
tar -xf btbn-ffmpeg.tar.xz -C /usr/lib/btbn-ffmpeg --strip-components 1
47+
rm -rf btbn-ffmpeg.tar.xz /usr/lib/btbn-ffmpeg/doc /usr/lib/btbn-ffmpeg/bin/ffplay
4948
fi
5049

5150
# arch specific packages
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docker/rpi/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# syntax=docker/dockerfile:1.4
2+
3+
# https://askubuntu.com/questions/972516/debian-frontend-environment-variable
4+
ARG DEBIAN_FRONTEND=noninteractive
5+
6+
FROM deps AS rpi-deps
7+
ARG TARGETARCH
8+
9+
RUN rm -rf /usr/lib/btbn-ffmpeg/
10+
11+
# Install dependencies
12+
RUN --mount=type=bind,source=docker/rpi/install_deps.sh,target=/deps/install_deps.sh \
13+
/deps/install_deps.sh
14+
15+
WORKDIR /opt/frigate/
16+
COPY --from=rootfs / /

docker/rpi/install_deps.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
apt-get -qq update
6+
7+
apt-get -qq install --no-install-recommends -y \
8+
apt-transport-https \
9+
gnupg \
10+
wget \
11+
procps vainfo \
12+
unzip locales tzdata libxml2 xz-utils \
13+
python3-pip \
14+
curl \
15+
jq \
16+
nethogs
17+
18+
mkdir -p -m 600 /root/.gnupg
19+
20+
# enable non-free repo
21+
sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list
22+
23+
# ffmpeg -> arm64
24+
if [[ "${TARGETARCH}" == "arm64" ]]; then
25+
# add raspberry pi repo
26+
gpg --no-default-keyring --keyring /usr/share/keyrings/raspbian.gpg --keyserver keyserver.ubuntu.com --recv-keys 82B129927FA3303E
27+
echo "deb [signed-by=/usr/share/keyrings/raspbian.gpg] https://archive.raspberrypi.org/debian/ bullseye main" | tee /etc/apt/sources.list.d/raspi.list
28+
apt-get -qq update
29+
apt-get -qq install --no-install-recommends --no-install-suggests -y ffmpeg
30+
fi

docker/rpi/rpi.hcl

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
target deps {
2+
dockerfile = "docker/main/Dockerfile"
3+
platforms = ["linux/arm64"]
4+
target = "deps"
5+
}
6+
7+
target rootfs {
8+
dockerfile = "docker/main/Dockerfile"
9+
platforms = ["linux/arm64"]
10+
target = "rootfs"
11+
}
12+
13+
target rpi {
14+
dockerfile = "docker/rpi/Dockerfile"
15+
contexts = {
16+
deps = "target:deps",
17+
rootfs = "target:rootfs"
18+
}
19+
platforms = ["linux/arm64"]
20+
}

docker/rpi/rpi.mk

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
BOARDS += rpi
2+
3+
local-rpi: version
4+
docker buildx bake --load --file=docker/rpi/rpi.hcl --set rpi.tags=frigate:latest-rpi rpi
5+
6+
build-rpi: version
7+
docker buildx bake --file=docker/rpi/rpi.hcl --set rpi.tags=$(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH)-rpi rpi
8+
9+
push-rpi: build-rpi
10+
docker buildx bake --push --file=docker/rpi/rpi.hcl --set rpi.tags=$(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH)-rpi rpi

0 commit comments

Comments
 (0)