From 46a9d47923638f353cb70f3bc3f0fa6467108537 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Sun, 19 Feb 2023 14:20:24 -0300 Subject: [PATCH] Avoid creating go2rtc config multiple times --- Dockerfile | 4 ++++ docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run | 16 +++++++++------- docker/rootfs/usr/local/go2rtc/create_config.py | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 448d5ebf8..204fc7c81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -207,6 +207,10 @@ FROM deps AS devcontainer # But start a fake service for simulating the logs COPY docker/fake_frigate_run /etc/s6-overlay/s6-rc.d/frigate/run +# Create symbolic link to the frigate source code, as go2rtc's create_config.sh uses it +RUN mkdir -p /opt/frigate \ + && ln -svf /workspace/frigate/frigate /opt/frigate/frigate + # Install Node 16 RUN apt-get update \ && apt-get install wget -y \ diff --git a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run index 9a0b616c0..40110808f 100755 --- a/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run +++ b/docker/rootfs/etc/s6-overlay/s6-rc.d/go2rtc/run @@ -41,17 +41,19 @@ function get_ip_and_port_from_supervisor() { export FRIGATE_GO2RTC_WEBRTC_CANDIDATE_INTERNAL="${ip_address}:${webrtc_port}" } -echo "[INFO] Preparing go2rtc config..." >&2 +if [[ ! -f "/dev/shm/go2rtc.yaml" ]]; then + echo "[INFO] Preparing go2rtc config..." >&2 -if [[ -n "${SUPERVISOR_TOKEN:-}" ]]; then - # Running as a Home Assistant add-on, infer the IP address and port - get_ip_and_port_from_supervisor + if [[ -n "${SUPERVISOR_TOKEN:-}" ]]; then + # Running as a Home Assistant add-on, infer the IP address and port + get_ip_and_port_from_supervisor + fi + + python3 /usr/local/go2rtc/create_config.py fi -raw_config=$(python3 /usr/local/go2rtc/create_config.py) - echo "[INFO] Starting go2rtc..." >&2 # Replace the bash process with the go2rtc process, redirecting stderr to stdout exec 2>&1 -exec go2rtc -config="${raw_config}" +exec go2rtc -config=/dev/shm/go2rtc.yaml diff --git a/docker/rootfs/usr/local/go2rtc/create_config.py b/docker/rootfs/usr/local/go2rtc/create_config.py index 28f884fe6..dfe6a5f9b 100644 --- a/docker/rootfs/usr/local/go2rtc/create_config.py +++ b/docker/rootfs/usr/local/go2rtc/create_config.py @@ -8,6 +8,7 @@ import yaml sys.path.insert(0, "/opt/frigate") from frigate.const import BIRDSEYE_PIPE, BTBN_PATH from frigate.ffmpeg_presets import parse_preset_hardware_acceleration_encode + sys.path.remove("/opt/frigate") @@ -95,5 +96,6 @@ if config.get("birdseye", {}).get("restream", False): else: go2rtc_config["streams"] = {"birdseye": ffmpeg_cmd} - -print(json.dumps(go2rtc_config)) +# Write go2rtc_config to /dev/shm/go2rtc.yaml +with open("/dev/shm/go2rtc.yaml", "w") as f: + yaml.dump(go2rtc_config, f)