mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Faster image builds with caching (#4491)
* fix makefile variable * add branch for testing * fix arm32 build * use amd64 for web build * install wheels in a separate layer for better parallel builds * try build-push-action * try using gh context * use short sha * cleanup
This commit is contained in:
parent
f4187d6b83
commit
370276a7b6
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@ -26,7 +26,15 @@ jobs:
|
|||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Build image
|
- name: Create short sha
|
||||||
run: make push
|
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
|
||||||
env:
|
- name: Build and push
|
||||||
IMAGE_REPO: ghcr.io/${{ github.actor }}/frigate
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
tags: |
|
||||||
|
ghcr.io/blakeblackshear/frigate:${{ github.ref_name }}-${{ env.SHORT_SHA }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
23
Dockerfile
23
Dockerfile
@ -41,6 +41,7 @@ RUN --mount=type=bind,source=docker/install_s6_overlay.sh,target=/deps/install_s
|
|||||||
|
|
||||||
FROM base AS wheels
|
FROM base AS wheels
|
||||||
ARG DEBIAN_FRONTEND
|
ARG DEBIAN_FRONTEND
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
# Use a separate container to build wheels to prevent build dependencies in final image
|
# Use a separate container to build wheels to prevent build dependencies in final image
|
||||||
RUN apt-get -qq update \
|
RUN apt-get -qq update \
|
||||||
@ -106,9 +107,11 @@ ENV PATH="/usr/lib/btbn-ffmpeg/bin:/usr/local/go2rtc/bin:/usr/local/nginx/sbin:$
|
|||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \
|
RUN --mount=type=bind,source=docker/install_deps.sh,target=/deps/install_deps.sh \
|
||||||
--mount=type=bind,from=wheels,source=/wheels,target=/deps/wheels \
|
|
||||||
/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 / /
|
COPY --from=deps-rootfs / /
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
@ -118,8 +121,8 @@ EXPOSE 8555
|
|||||||
|
|
||||||
ENTRYPOINT ["/init"]
|
ENTRYPOINT ["/init"]
|
||||||
|
|
||||||
# Frigate deps with Node.js and NPM
|
# Frigate deps with Node.js and NPM for devcontainer
|
||||||
FROM deps AS deps-node
|
FROM deps AS devcontainer
|
||||||
|
|
||||||
# Install Node 16
|
# Install Node 16
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
@ -129,9 +132,6 @@ RUN apt-get update \
|
|||||||
&& rm -rf /var/lib/apt/lists/* \
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
&& npm install -g npm@9
|
&& npm install -g npm@9
|
||||||
|
|
||||||
# Devcontainer
|
|
||||||
FROM deps-node AS devcontainer
|
|
||||||
|
|
||||||
WORKDIR /workspace/frigate
|
WORKDIR /workspace/frigate
|
||||||
|
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
@ -145,7 +145,8 @@ CMD ["sleep", "infinity"]
|
|||||||
|
|
||||||
|
|
||||||
# Frigate web build
|
# Frigate web build
|
||||||
FROM deps-node AS web-build
|
# force this to run on amd64 because QEMU is painfully slow
|
||||||
|
FROM --platform=linux/amd64 node:16 AS web-build
|
||||||
|
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
COPY web/package.json web/package-lock.json ./
|
COPY web/package.json web/package-lock.json ./
|
||||||
@ -154,19 +155,13 @@ RUN npm install
|
|||||||
COPY web/ ./
|
COPY web/ ./
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Frigate web dist files
|
|
||||||
FROM scratch AS web-dist
|
|
||||||
|
|
||||||
COPY --from=web-build /work/dist/ /
|
|
||||||
|
|
||||||
# Collect final files in a single layer
|
# Collect final files in a single layer
|
||||||
FROM scratch AS rootfs
|
FROM scratch AS rootfs
|
||||||
|
|
||||||
WORKDIR /opt/frigate/
|
WORKDIR /opt/frigate/
|
||||||
COPY frigate frigate/
|
COPY frigate frigate/
|
||||||
COPY migrations migrations/
|
COPY migrations migrations/
|
||||||
COPY --from=web-dist / web/
|
COPY --from=web-build /work/dist/ web/
|
||||||
|
|
||||||
|
|
||||||
# Frigate final container
|
# Frigate final container
|
||||||
FROM deps
|
FROM deps
|
||||||
|
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ default_target: local
|
|||||||
|
|
||||||
COMMIT_HASH := $(shell git log -1 --pretty=format:"%h"|tail -1)
|
COMMIT_HASH := $(shell git log -1 --pretty=format:"%h"|tail -1)
|
||||||
VERSION = 0.12.0
|
VERSION = 0.12.0
|
||||||
IMAGE_OWNER ?= ghcr.io/blakeblackshear/frigate
|
IMAGE_REPO ?= ghcr.io/blakeblackshear/frigate
|
||||||
CURRENT_UID := $(shell id -u)
|
CURRENT_UID := $(shell id -u)
|
||||||
CURRENT_GID := $(shell id -g)
|
CURRENT_GID := $(shell id -g)
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@ sed -i -e's/ main/ main contrib non-free/g' /etc/apt/sources.list
|
|||||||
apt-get -qq update
|
apt-get -qq update
|
||||||
apt-get -qq install --no-install-recommends --no-install-suggests -y \
|
apt-get -qq install --no-install-recommends --no-install-suggests -y \
|
||||||
libedgetpu1-max python3-tflite-runtime python3-pycoral
|
libedgetpu1-max python3-tflite-runtime python3-pycoral
|
||||||
pip3 install -U /deps/wheels/*.whl
|
|
||||||
|
|
||||||
# btbn-ffmpeg -> amd64 / arm64
|
# btbn-ffmpeg -> amd64 / arm64
|
||||||
if [[ "${TARGETARCH}" == "amd64" || "${TARGETARCH}" == "arm64" ]]; then
|
if [[ "${TARGETARCH}" == "amd64" || "${TARGETARCH}" == "arm64" ]]; then
|
||||||
@ -69,7 +68,7 @@ if [[ "${TARGETARCH}" == "arm" ]]; then
|
|||||||
libgtk-3-dev \
|
libgtk-3-dev \
|
||||||
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
|
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
|
||||||
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
|
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
|
||||||
gfortran openexr libatlas-base-dev libssl-devlibtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
|
gfortran openexr libatlas-base-dev libtbb-dev libdc1394-22-dev libopenexr-dev \
|
||||||
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
|
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user