mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-12-19 19:06:16 +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
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build image
|
||||
run: make push
|
||||
env:
|
||||
IMAGE_REPO: ghcr.io/${{ github.actor }}/frigate
|
||||
- name: Create short sha
|
||||
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
|
||||
- name: Build and push
|
||||
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
|
||||
ARG DEBIAN_FRONTEND
|
||||
ARG TARGETARCH
|
||||
|
||||
# Use a separate container to build wheels to prevent build dependencies in final image
|
||||
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
|
||||
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
|
||||
|
||||
RUN --mount=type=bind,from=wheels,source=/wheels,target=/deps/wheels \
|
||||
pip3 install -U /deps/wheels/*.whl
|
||||
|
||||
COPY --from=deps-rootfs / /
|
||||
|
||||
EXPOSE 5000
|
||||
@ -118,8 +121,8 @@ EXPOSE 8555
|
||||
|
||||
ENTRYPOINT ["/init"]
|
||||
|
||||
# Frigate deps with Node.js and NPM
|
||||
FROM deps AS deps-node
|
||||
# Frigate deps with Node.js and NPM for devcontainer
|
||||
FROM deps AS devcontainer
|
||||
|
||||
# Install Node 16
|
||||
RUN apt-get update \
|
||||
@ -129,9 +132,6 @@ RUN apt-get update \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& npm install -g npm@9
|
||||
|
||||
# Devcontainer
|
||||
FROM deps-node AS devcontainer
|
||||
|
||||
WORKDIR /workspace/frigate
|
||||
|
||||
RUN apt-get update \
|
||||
@ -145,7 +145,8 @@ CMD ["sleep", "infinity"]
|
||||
|
||||
|
||||
# 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
|
||||
COPY web/package.json web/package-lock.json ./
|
||||
@ -154,19 +155,13 @@ RUN npm install
|
||||
COPY web/ ./
|
||||
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
|
||||
FROM scratch AS rootfs
|
||||
|
||||
WORKDIR /opt/frigate/
|
||||
COPY frigate frigate/
|
||||
COPY migrations migrations/
|
||||
COPY --from=web-dist / web/
|
||||
|
||||
COPY --from=web-build /work/dist/ web/
|
||||
|
||||
# Frigate final container
|
||||
FROM deps
|
||||
|
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ default_target: local
|
||||
|
||||
COMMIT_HASH := $(shell git log -1 --pretty=format:"%h"|tail -1)
|
||||
VERSION = 0.12.0
|
||||
IMAGE_OWNER ?= ghcr.io/blakeblackshear/frigate
|
||||
IMAGE_REPO ?= ghcr.io/blakeblackshear/frigate
|
||||
CURRENT_UID := $(shell id -u)
|
||||
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 install --no-install-recommends --no-install-suggests -y \
|
||||
libedgetpu1-max python3-tflite-runtime python3-pycoral
|
||||
pip3 install -U /deps/wheels/*.whl
|
||||
|
||||
# btbn-ffmpeg -> amd64 / arm64
|
||||
if [[ "${TARGETARCH}" == "amd64" || "${TARGETARCH}" == "arm64" ]]; then
|
||||
@ -69,7 +68,7 @@ if [[ "${TARGETARCH}" == "arm" ]]; then
|
||||
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-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
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user