From b7c09a9b38d39ff70973851d7bcc071c9b673903 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Mon, 2 Nov 2020 05:44:16 -0600 Subject: [PATCH] add nginx and change default file locations --- README.md | 4 +- docker/Dockerfile.base | 13 +++++- docker/Dockerfile.wheels | 4 +- docker/Dockerfile.wheels.aarch64 | 4 +- frigate/__main__.py | 2 +- frigate/config.py | 4 +- nginx/nginx.conf | 75 ++++++++++++++++++++++++++++++++ run.sh | 4 ++ 8 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 nginx/nginx.conf create mode 100644 run.sh diff --git a/README.md b/README.md index b778b6497..12ccde301 100644 --- a/README.md +++ b/README.md @@ -179,10 +179,10 @@ save_clips: # will begin to expire and the resulting clip will be the last x seconds of the event. max_seconds: 300 # Optional: Location to save event clips. (default: shown below) - clips_dir: /clips + clips_dir: /media/frigate/clips # Optional: Location to save cache files for creating clips. (default: shown below) # NOTE: To reduce wear on SSDs and SD cards, use a tmpfs volume. - cache_dir: /cache + cache_dir: /tmp/cache # Optional: Global ffmpeg args # "ffmpeg" + global_args + input_args + "-i" + input + output_args diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base index 130697b52..4ac01783d 100644 --- a/docker/Dockerfile.base +++ b/docker/Dockerfile.base @@ -15,7 +15,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get -qq update \ && apt-get upgrade -y \ && apt-get -qq install --no-install-recommends -y \ - gnupg wget unzip tzdata \ + gnupg wget unzip tzdata nginx \ && apt-get -qq install --no-install-recommends -y \ python3-pip \ && pip3 install -U /wheels/*.whl \ @@ -27,6 +27,12 @@ RUN apt-get -qq update \ && rm -rf /var/lib/apt/lists/* /wheels \ && (apt-get autoremove -y; apt-get autoclean -y) +RUN pip3 install \ + peewee \ + voluptuous + +COPY nginx/nginx.conf /etc/nginx/nginx.conf + # get model and labels ARG MODEL_REFS=7064b94dd5b996189242320359dbab8b52c94a84 COPY labelmap.txt /labelmap.txt @@ -38,4 +44,7 @@ RUN mkdir /cache /clips WORKDIR /opt/frigate/ ADD frigate frigate/ -CMD ["python3", "-u", "-m", "frigate"] +COPY run.sh /run.sh +RUN chmod +x /run.sh + +CMD ["/run.sh"] diff --git a/docker/Dockerfile.wheels b/docker/Dockerfile.wheels index 46126002b..15f244671 100644 --- a/docker/Dockerfile.wheels +++ b/docker/Dockerfile.wheels @@ -32,9 +32,7 @@ RUN pip3 wheel --wheel-dir=/wheels \ paho-mqtt \ PyYAML \ matplotlib \ - click \ - peewee \ - voluptuous + click FROM scratch diff --git a/docker/Dockerfile.wheels.aarch64 b/docker/Dockerfile.wheels.aarch64 index 6637e741a..006f569cf 100644 --- a/docker/Dockerfile.wheels.aarch64 +++ b/docker/Dockerfile.wheels.aarch64 @@ -42,9 +42,7 @@ RUN pip3 wheel --wheel-dir=/wheels \ paho-mqtt \ PyYAML \ matplotlib \ - click \ - peewee \ - voluptuous + click FROM scratch diff --git a/frigate/__main__.py b/frigate/__main__.py index e5f0f58e7..1bfd6be27 100644 --- a/frigate/__main__.py +++ b/frigate/__main__.py @@ -36,7 +36,7 @@ class FrigateApp(): raw_config = f.read() if config_file.endswith(".yml"): - config = yaml.load(raw_config) + config = yaml.safe_load(raw_config) elif config_file.endswith(".json"): config = json.loads(raw_config) diff --git a/frigate/config.py b/frigate/config.py index 2611783f1..089167e1b 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -30,8 +30,8 @@ MQTT_SCHEMA = vol.Schema( SAVE_CLIPS_SCHEMA = vol.Schema( { vol.Optional('max_seconds', default=300): int, - vol.Optional('clips_dir', default='/clips'): str, - vol.Optional('cache_dir', default='/cache'): str + vol.Optional('clips_dir', default='/media/frigate/clips'): str, + vol.Optional('cache_dir', default='/tmp/cache'): str } ) diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 000000000..19cc18fc2 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,75 @@ +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + client_max_body_size 50M; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + + location /stream/ { + add_header 'Cache-Control' 'no-cache'; + add_header 'Access-Control-Allow-Origin' "$http_origin" always; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Expose-Headers' 'Content-Length'; + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' "$http_origin"; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + + types { + application/dash+xml mpd; + application/vnd.apple.mpegurl m3u8; + video/mp2t ts; + image/jpeg jpg; + } + + root /tmp; + } + + location /frigate/ { + add_header 'Access-Control-Allow-Origin' "$http_origin" always; + add_header 'Access-Control-Allow-Credentials' 'true'; + add_header 'Access-Control-Expose-Headers' 'Content-Length'; + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' "$http_origin"; + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain charset=UTF-8'; + add_header 'Content-Length' 0; + return 204; + } + + types { + video/mp4 mp4; + image/jpeg jpg; + } + + autoindex on; + root /media; + } + } +} \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 000000000..52277327b --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +service nginx start +python3 -u -m frigate \ No newline at end of file