Use hassio-addon as docker base image

This commit is contained in:
Felipe Santos 2022-11-14 13:37:14 -03:00
parent c97aac6c94
commit d28d6f6099
8 changed files with 73 additions and 31 deletions

View File

@ -43,7 +43,8 @@ COPY requirements-wheels.txt /requirements-wheels.txt
RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt
# Frigate Container # Frigate Container
FROM debian:11-slim # https://github.com/hassio-addons/addon-debian-base/releases
FROM ghcr.io/hassio-addons/debian-base:6.1.3
ARG TARGETARCH ARG TARGETARCH
# https://askubuntu.com/questions/972516/debian-frontend-environment-variable # https://askubuntu.com/questions/972516/debian-frontend-environment-variable
@ -55,6 +56,9 @@ ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility"
ENV FLASK_ENV=development ENV FLASK_ENV=development
# https://github.com/home-assistant/core/issues/79976
ENV S6_SERVICES_READYTIME=50
COPY --from=wheels /wheels /wheels COPY --from=wheels /wheels /wheels
# Install ffmpeg # Install ffmpeg
@ -116,7 +120,7 @@ RUN apt-get -qq update \
&& apt-get autoremove -y \ && apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
ENV PATH=$PATH:/usr/lib/btbn-ffmpeg/bin ENV PATH="/usr/lib/btbn-ffmpeg/bin:$PATH"
# install go2rtc # install go2rtc
RUN wget -O go2rtc "https://github.com/AlexxIT/go2rtc/releases/download/v0.1-rc.2/go2rtc_linux_${TARGETARCH}" \ RUN wget -O go2rtc "https://github.com/AlexxIT/go2rtc/releases/download/v0.1-rc.2/go2rtc_linux_${TARGETARCH}" \
@ -124,8 +128,12 @@ RUN wget -O go2rtc "https://github.com/AlexxIT/go2rtc/releases/download/v0.1-rc.
&& mkdir -p /usr/local/go2rtc/sbin/ \ && mkdir -p /usr/local/go2rtc/sbin/ \
&& mv go2rtc /usr/local/go2rtc/sbin/go2rtc && mv go2rtc /usr/local/go2rtc/sbin/go2rtc
ENV PATH="/usr/local/go2rtc/sbin:$PATH"
COPY --from=nginx /usr/local/nginx/ /usr/local/nginx/ COPY --from=nginx /usr/local/nginx/ /usr/local/nginx/
ENV PATH="/usr/local/nginx/sbin:$PATH"
# get model and labels # get model and labels
COPY labelmap.txt /labelmap.txt COPY labelmap.txt /labelmap.txt
RUN wget -q https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite -O /edgetpu_model.tflite RUN wget -q https://github.com/google-coral/test_data/raw/release-frogfish/ssdlite_mobiledet_coco_qat_postprocess_edgetpu.tflite -O /edgetpu_model.tflite
@ -139,19 +147,7 @@ COPY web/dist web/
COPY docker/rootfs/ / COPY docker/rootfs/ /
# s6-overlay
RUN S6_ARCH="${TARGETARCH}" \
&& if [ "${TARGETARCH}" = "amd64" ]; then S6_ARCH="amd64"; fi \
&& if [ "${TARGETARCH}" = "arm" ]; then S6_ARCH="armhf"; fi \
&& if [ "${TARGETARCH}" = "arm64" ]; then S6_ARCH="aarch64"; fi \
&& wget -O /tmp/s6-overlay-installer "https://github.com/just-containers/s6-overlay/releases/download/v2.2.0.3/s6-overlay-${S6_ARCH}-installer" \
&& chmod +x /tmp/s6-overlay-installer && /tmp/s6-overlay-installer /
EXPOSE 5000 EXPOSE 5000
EXPOSE 1935 EXPOSE 1935
EXPOSE 8554 EXPOSE 8554
EXPOSE 8555 EXPOSE 8555
ENTRYPOINT ["/init"]
CMD ["python3", "-u", "-m", "frigate"]

View File

@ -0,0 +1,12 @@
#!/command/with-contenv bashio
# ==============================================================================
# Take down the S6 supervision tree when Frigate fails
# ==============================================================================
# shellcheck shell=bash
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
bashio::log.warning "Frigate crashed, halting container..."
/run/s6/basedir/bin/halt
fi
bashio::log.info "Frigate stopped, restarting..."

View File

@ -0,0 +1,9 @@
#!/command/with-contenv bashio
# ==============================================================================
# Runs Frigate
# ==============================================================================
# shellcheck shell=bash
bashio::log.info 'Starting Frigate...'
exec python3 -u -m frigate

15
docker/rootfs/etc/services.d/go2rtc/finish Normal file → Executable file
View File

@ -1,5 +1,12 @@
#!/usr/bin/execlineb -S1 #!/command/with-contenv bashio
if { s6-test ${1} -ne 0 } # ==============================================================================
if { s6-test ${1} -ne 256 } # Take down the S6 supervision tree when go2rtc fails
# ==============================================================================
# shellcheck shell=bash
s6-svscanctl -t /var/run/s6/services if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
bashio::log.warning "go2rtc crashed, halting container..."
/run/s6/basedir/bin/halt
fi
bashio::log.info "go2rtc stopped, restarting..."

17
docker/rootfs/etc/services.d/go2rtc/run Normal file → Executable file
View File

@ -1,12 +1,17 @@
#!/bin/bash #!/command/with-contenv bashio
# ==============================================================================
# Runs go2rtc
# ==============================================================================
# shellcheck shell=bash
# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425?permalink_comment_id=3945021 bashio::log.info 'Starting go2rtc...'
set -euo pipefail
declare config_path
if [[ -f "/config/frigate-go2rtc.yaml" ]]; then if [[ -f "/config/frigate-go2rtc.yaml" ]]; then
CONFIG_PATH=/config/frigate-go2rtc.yaml config_path="/config/frigate-go2rtc.yaml"
else else
CONFIG_PATH=/usr/local/go2rtc/sbin/go2rtc.yaml config_path="/usr/local/go2rtc/sbin/go2rtc.yaml"
fi fi
exec /usr/local/go2rtc/sbin/go2rtc -config="$CONFIG_PATH" exec go2rtc -config="$config_path"

15
docker/rootfs/etc/services.d/nginx/finish Normal file → Executable file
View File

@ -1,5 +1,12 @@
#!/usr/bin/execlineb -S1 #!/command/with-contenv bashio
if { s6-test ${1} -ne 0 } # ==============================================================================
if { s6-test ${1} -ne 256 } # Take down the S6 supervision tree when NGINX fails
# ==============================================================================
# shellcheck shell=bash
s6-svscanctl -t /var/run/s6/services if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
bashio::log.warning "NGINX crashed, halting container..."
/run/s6/basedir/bin/halt
fi
bashio::log.info "NGINX stopped, restarting..."

11
docker/rootfs/etc/services.d/nginx/run Normal file → Executable file
View File

@ -1,2 +1,9 @@
#!/usr/bin/execlineb -P #!/command/with-contenv bashio
/usr/local/nginx/sbin/nginx # ==============================================================================
# Runs NGINX
# ==============================================================================
# shellcheck shell=bash
bashio::log.info 'Starting NGINX...'
exec nginx -g "daemon off;"

View File

@ -1,4 +1,3 @@
daemon off;
user root; user root;
worker_processes 1; worker_processes 1;