From f4b2c3f37121e61ae113180e3a85827dc72f555c Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Mon, 14 Nov 2022 20:43:58 -0300 Subject: [PATCH] Setup everything with one click --- .devcontainer/devcontainer.json | 28 ++++++++++++++++++++++++++++ .devcontainer/initialize.sh | 3 +++ .devcontainer/post_create.sh | 17 +++++++++++++++++ Dockerfile | 17 ++++++++++------- docker-compose.yml | 8 +------- 5 files changed, 59 insertions(+), 14 deletions(-) create mode 100755 .devcontainer/post_create.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 359a62829..81ddfc91f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,11 +4,39 @@ "service": "devcontainer", "workspaceFolder": "/workspace/frigate", "initializeCommand": ".devcontainer/initialize.sh", + "postCreateCommand": ".devcontainer/post_create.sh", "overrideCommand": false, "remoteUser": "vscode", "features": { "ghcr.io/devcontainers/features/common-utils:1": {} }, + "forwardPorts": [5000, 5001, 5173, 1935, 8554, 8555], + "portsAttributes": { + "5000": { + "label": "NGINX", + "onAutoForward": "silent" + }, + "5001": { + "label": "Frigate API", + "onAutoForward": "silent" + }, + "5173": { + "label": "Vite Server", + "onAutoForward": "silent" + }, + "1935": { + "label": "RTMP", + "onAutoForward": "silent" + }, + "8554": { + "label": "gortc RTSP", + "onAutoForward": "silent" + }, + "8555": { + "label": "go2rtc WebRTC", + "onAutoForward": "silent" + } + }, "extensions": [ "ms-python.vscode-pylance", "ms-python.python", diff --git a/.devcontainer/initialize.sh b/.devcontainer/initialize.sh index 35eebc816..2300df187 100755 --- a/.devcontainer/initialize.sh +++ b/.devcontainer/initialize.sh @@ -2,6 +2,9 @@ set -euo pipefail +# These folders needs to be created and owned by the host user +mkdir -p debug web/dist + if [[ -f "config/config.yml" ]]; then echo "config/config.yml already exists, skipping initialization" >&2 else diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh new file mode 100755 index 000000000..9dd1249c6 --- /dev/null +++ b/.devcontainer/post_create.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -euxo pipefail + +# Frigate normal container runs as root, so it have permission to create +# the folders. But the devcontainer runs as the host user, so we need to +# create the folders and give the host user permission to write to them. +sudo mkdir -p /media/frigate +sudo chown -R "$(id -u):$(id -g)" /media/frigate + +make version + +cd web + +npm install + +npm run build diff --git a/Dockerfile b/Dockerfile index 14cdbce4c..33a41d8e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -141,6 +141,12 @@ RUN S6_ARCH="${TARGETARCH}" \ && 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"] # Frigate deps with Node.js and NPM FROM deps AS deps-node @@ -156,6 +162,10 @@ FROM deps-node AS devcontainer WORKDIR /workspace/frigate +RUN apt-get update \ + && apt-get install make -y \ + && rm -rf /var/lib/apt/lists/* + RUN --mount=type=bind,source=./requirements-dev.txt,target=/workspace/frigate/requirements-dev.txt \ pip3 install -r requirements-dev.txt @@ -186,11 +196,4 @@ COPY frigate frigate/ COPY migrations migrations/ COPY --from=web-dist / web/ -EXPOSE 5000 -EXPOSE 1935 -EXPOSE 8554 -EXPOSE 8555 - -ENTRYPOINT ["/init"] - CMD ["python3", "-u", "-m", "frigate"] diff --git a/docker-compose.yml b/docker-compose.yml index e151c6f1e..3ed08493c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,17 +17,11 @@ services: # - /dev/dri:/dev/dri # for intel hwaccel, needs to be updated for your hardware volumes: - .:/workspace/frigate:cached + - ./web/dist:/opt/frigate/web:cached - /etc/localtime:/etc/localtime:ro - ./config/config.yml:/config/config.yml:ro - ./debug:/media/frigate - /dev/bus/usb:/dev/bus/usb - ports: - - "1935:1935" - - "3000:3000" - - "5000:5000" - - "5001:5001" - - "8080:8080" - - "8554:8554" mqtt: container_name: mqtt image: eclipse-mosquitto:1.6