From d28d6f6099f6bf6eef2f7fade004026619bb3708 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Mon, 14 Nov 2022 13:37:14 -0300 Subject: [PATCH] Use hassio-addon as docker base image --- docker/Dockerfile | 24 ++++++++----------- docker/rootfs/etc/services.d/frigate/finish | 12 ++++++++++ docker/rootfs/etc/services.d/frigate/run | 9 +++++++ docker/rootfs/etc/services.d/go2rtc/finish | 15 ++++++++---- docker/rootfs/etc/services.d/go2rtc/run | 17 ++++++++----- docker/rootfs/etc/services.d/nginx/finish | 15 ++++++++---- docker/rootfs/etc/services.d/nginx/run | 11 +++++++-- docker/rootfs/usr/local/nginx/conf/nginx.conf | 1 - 8 files changed, 73 insertions(+), 31 deletions(-) create mode 100755 docker/rootfs/etc/services.d/frigate/finish create mode 100755 docker/rootfs/etc/services.d/frigate/run mode change 100644 => 100755 docker/rootfs/etc/services.d/go2rtc/finish mode change 100644 => 100755 docker/rootfs/etc/services.d/go2rtc/run mode change 100644 => 100755 docker/rootfs/etc/services.d/nginx/finish mode change 100644 => 100755 docker/rootfs/etc/services.d/nginx/run diff --git a/docker/Dockerfile b/docker/Dockerfile index 5e3c592c4..5d73d7215 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -43,7 +43,8 @@ COPY requirements-wheels.txt /requirements-wheels.txt RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt # 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 # https://askubuntu.com/questions/972516/debian-frontend-environment-variable @@ -55,6 +56,9 @@ ENV NVIDIA_DRIVER_CAPABILITIES="compute,video,utility" ENV FLASK_ENV=development +# https://github.com/home-assistant/core/issues/79976 +ENV S6_SERVICES_READYTIME=50 + COPY --from=wheels /wheels /wheels # Install ffmpeg @@ -116,7 +120,7 @@ RUN apt-get -qq update \ && apt-get autoremove -y \ && rm -rf /var/lib/apt/lists/* -ENV PATH=$PATH:/usr/lib/btbn-ffmpeg/bin +ENV PATH="/usr/lib/btbn-ffmpeg/bin:$PATH" # install go2rtc 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/ \ && mv go2rtc /usr/local/go2rtc/sbin/go2rtc +ENV PATH="/usr/local/go2rtc/sbin:$PATH" + COPY --from=nginx /usr/local/nginx/ /usr/local/nginx/ +ENV PATH="/usr/local/nginx/sbin:$PATH" + # get model and labels 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 @@ -139,19 +147,7 @@ COPY web/dist web/ 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 1935 EXPOSE 8554 EXPOSE 8555 - -ENTRYPOINT ["/init"] - -CMD ["python3", "-u", "-m", "frigate"] diff --git a/docker/rootfs/etc/services.d/frigate/finish b/docker/rootfs/etc/services.d/frigate/finish new file mode 100755 index 000000000..9c2e8a52a --- /dev/null +++ b/docker/rootfs/etc/services.d/frigate/finish @@ -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..." diff --git a/docker/rootfs/etc/services.d/frigate/run b/docker/rootfs/etc/services.d/frigate/run new file mode 100755 index 000000000..f71b736f9 --- /dev/null +++ b/docker/rootfs/etc/services.d/frigate/run @@ -0,0 +1,9 @@ +#!/command/with-contenv bashio +# ============================================================================== +# Runs Frigate +# ============================================================================== +# shellcheck shell=bash + +bashio::log.info 'Starting Frigate...' + +exec python3 -u -m frigate diff --git a/docker/rootfs/etc/services.d/go2rtc/finish b/docker/rootfs/etc/services.d/go2rtc/finish old mode 100644 new mode 100755 index 24482e77f..0306719cf --- a/docker/rootfs/etc/services.d/go2rtc/finish +++ b/docker/rootfs/etc/services.d/go2rtc/finish @@ -1,5 +1,12 @@ -#!/usr/bin/execlineb -S1 -if { s6-test ${1} -ne 0 } -if { s6-test ${1} -ne 256 } +#!/command/with-contenv bashio +# ============================================================================== +# Take down the S6 supervision tree when go2rtc fails +# ============================================================================== +# shellcheck shell=bash -s6-svscanctl -t /var/run/s6/services \ No newline at end of file +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..." diff --git a/docker/rootfs/etc/services.d/go2rtc/run b/docker/rootfs/etc/services.d/go2rtc/run old mode 100644 new mode 100755 index 55d206414..5062ad074 --- a/docker/rootfs/etc/services.d/go2rtc/run +++ b/docker/rootfs/etc/services.d/go2rtc/run @@ -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 -set -euo pipefail +bashio::log.info 'Starting go2rtc...' + +declare config_path if [[ -f "/config/frigate-go2rtc.yaml" ]]; then - CONFIG_PATH=/config/frigate-go2rtc.yaml + config_path="/config/frigate-go2rtc.yaml" else - CONFIG_PATH=/usr/local/go2rtc/sbin/go2rtc.yaml + config_path="/usr/local/go2rtc/sbin/go2rtc.yaml" fi -exec /usr/local/go2rtc/sbin/go2rtc -config="$CONFIG_PATH" \ No newline at end of file +exec go2rtc -config="$config_path" diff --git a/docker/rootfs/etc/services.d/nginx/finish b/docker/rootfs/etc/services.d/nginx/finish old mode 100644 new mode 100755 index 24482e77f..cf73cfc91 --- a/docker/rootfs/etc/services.d/nginx/finish +++ b/docker/rootfs/etc/services.d/nginx/finish @@ -1,5 +1,12 @@ -#!/usr/bin/execlineb -S1 -if { s6-test ${1} -ne 0 } -if { s6-test ${1} -ne 256 } +#!/command/with-contenv bashio +# ============================================================================== +# Take down the S6 supervision tree when NGINX fails +# ============================================================================== +# shellcheck shell=bash -s6-svscanctl -t /var/run/s6/services \ No newline at end of file +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..." diff --git a/docker/rootfs/etc/services.d/nginx/run b/docker/rootfs/etc/services.d/nginx/run old mode 100644 new mode 100755 index 5aba51c91..e5b98bc50 --- a/docker/rootfs/etc/services.d/nginx/run +++ b/docker/rootfs/etc/services.d/nginx/run @@ -1,2 +1,9 @@ -#!/usr/bin/execlineb -P -/usr/local/nginx/sbin/nginx \ No newline at end of file +#!/command/with-contenv bashio +# ============================================================================== +# Runs NGINX +# ============================================================================== +# shellcheck shell=bash + +bashio::log.info 'Starting NGINX...' + +exec nginx -g "daemon off;" diff --git a/docker/rootfs/usr/local/nginx/conf/nginx.conf b/docker/rootfs/usr/local/nginx/conf/nginx.conf index 1363e3b75..fb0d4fd58 100644 --- a/docker/rootfs/usr/local/nginx/conf/nginx.conf +++ b/docker/rootfs/usr/local/nginx/conf/nginx.conf @@ -1,4 +1,3 @@ -daemon off; user root; worker_processes 1;