Skip to content

Commit

Permalink
add nginx and change default file locations
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeblackshear committed Jan 27, 2021
1 parent eced06e commit b7c09a9
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand All @@ -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"]
4 changes: 1 addition & 3 deletions docker/Dockerfile.wheels
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ RUN pip3 wheel --wheel-dir=/wheels \
paho-mqtt \
PyYAML \
matplotlib \
click \
peewee \
voluptuous
click

FROM scratch

Expand Down
4 changes: 1 addition & 3 deletions docker/Dockerfile.wheels.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ RUN pip3 wheel --wheel-dir=/wheels \
paho-mqtt \
PyYAML \
matplotlib \
click \
peewee \
voluptuous
click

FROM scratch

Expand Down
2 changes: 1 addition & 1 deletion frigate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def init_config(self):
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)

Expand Down
4 changes: 2 additions & 2 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
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
}
)

Expand Down
75 changes: 75 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
4 changes: 4 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

service nginx start
python3 -u -m frigate

0 comments on commit b7c09a9

Please sign in to comment.