From 4165a1d82cf47a34f72ab9a1b52bbaea34e88745 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Tue, 19 Jul 2022 22:18:32 -0300 Subject: [PATCH] Make it easier to run the devcontainer --- .devcontainer/devcontainer.json | 3 +- .devcontainer/initialize.sh | 10 ++++++ Makefile | 2 +- config/config.yml.example | 16 +++++++++ docker-compose.yml | 5 +-- docker/Dockerfile | 59 ++++++++++++++++++++++++++++++--- docker/Dockerfile.dev | 27 --------------- web/.dockerignore | 3 ++ 8 files changed, 90 insertions(+), 35 deletions(-) create mode 100755 .devcontainer/initialize.sh create mode 100644 config/config.yml.example delete mode 100644 docker/Dockerfile.dev create mode 100644 web/.dockerignore diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 259bd9c7c..87a224592 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,14 +3,15 @@ "dockerComposeFile": "../docker-compose.yml", "service": "dev", "workspaceFolder": "/lab/frigate", + "initializeCommand": ".devcontainer/initialize.sh", "extensions": [ + "ms-python.vscode-pylance", "ms-python.python", "visualstudioexptteam.vscodeintellicode", "mhutchie.git-graph", "ms-azuretools.vscode-docker", "streetsidesoftware.code-spell-checker", "esbenp.prettier-vscode", - "ms-python.vscode-pylance", "dbaeumer.vscode-eslint", "mikestead.dotenv", "csstools.postcss", diff --git a/.devcontainer/initialize.sh b/.devcontainer/initialize.sh new file mode 100755 index 000000000..35eebc816 --- /dev/null +++ b/.devcontainer/initialize.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +if [[ -f "config/config.yml" ]]; then + echo "config/config.yml already exists, skipping initialization" >&2 +else + echo "initializing config/config.yml" >&2 + cp -fv config/config.yml.example config/config.yml +fi diff --git a/Makefile b/Makefile index 6702690b9..88e5f2051 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ nginx_frigate: docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag blakeblackshear/frigate-nginx:1.0.2 --file docker/Dockerfile.nginx . local: - DOCKER_BUILDKIT=1 docker build -t frigate -f docker/Dockerfile . + DOCKER_BUILDKIT=1 docker build --tag frigate:latest --file docker/Dockerfile . amd64: docker buildx build --platform linux/amd64 --tag blakeblackshear/frigate:$(VERSION)-$(COMMIT_HASH) --file docker/Dockerfile . diff --git a/config/config.yml.example b/config/config.yml.example new file mode 100644 index 000000000..87deab160 --- /dev/null +++ b/config/config.yml.example @@ -0,0 +1,16 @@ +mqtt: + host: mqtt + +cameras: + test: + ffmpeg: + inputs: + - path: /media/frigate/car-stopping.mp4 + input_args: -re -stream_loop -1 -fflags +genpts + roles: + - detect + - rtmp + detect: + height: 1080 + width: 1920 + fps: 5 diff --git a/docker-compose.yml b/docker-compose.yml index 84547503a..20b24feac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,10 +12,11 @@ services: shm_size: "256mb" build: context: . - dockerfile: docker/Dockerfile.dev + dockerfile: docker/Dockerfile + target: dev devices: - /dev/bus/usb:/dev/bus/usb - - /dev/dri:/dev/dri # for intel hwaccel, needs to be updated for your hardware + # - /dev/dri:/dev/dri # for intel hwaccel, needs to be updated for your hardware volumes: - /etc/localtime:/etc/localtime:ro - .:/lab/frigate:cached diff --git a/docker/Dockerfile b/docker/Dockerfile index 61658fd61..3ad34a6a3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -42,8 +42,8 @@ RUN pip3 install -r requirements.txt COPY requirements-wheels.txt /requirements-wheels.txt RUN pip3 wheel --wheel-dir=/wheels -r requirements-wheels.txt -# Frigate Container -FROM debian:11-slim +# Frigate without web +FROM debian:11-slim AS frigate-without-web ARG TARGETARCH ARG JELLYFIN_FFMPEG_VERSION=5.0.1-7 @@ -118,8 +118,6 @@ WORKDIR /opt/frigate/ ADD frigate frigate/ ADD migrations migrations/ -COPY web/dist web/ - COPY docker/rootfs/ / # s6-overlay @@ -136,3 +134,56 @@ EXPOSE 1935 ENTRYPOINT ["/init"] CMD ["python3", "-u", "-m", "frigate"] + + +# Frigate with Node.js and NPM +FROM frigate-without-web AS frigate-with-node + +# Install Node 16 +RUN apt-get update -y \ + && apt-get install -y curl \ + && curl -sL https://deb.nodesource.com/setup_16.x | bash - \ + && apt-get install -y nodejs + +RUN npm install -g npm@latest + + +# Build of the Frigate web +FROM frigate-with-node AS web-build + +WORKDIR /work +COPY web/package.json web/package-lock.json ./ +RUN npm install + +COPY web/ ./ +RUN npm run build + + +# Frigate Container +FROM frigate-without-web + +COPY --from=build-web /work/dist web/ + + +# Devcontainer +FROM frigate-with-node AS dev + +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Create the user +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \ + # + # [Optional] Add sudo support. Omit if you don't need to install software after connecting. + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +RUN apt-get update \ + && apt-get install -y git curl vim htop + +COPY requirements-dev.txt /opt/frigate/requirements-dev.txt +RUN pip3 install -r requirements-dev.txt diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev deleted file mode 100644 index 7f47c3768..000000000 --- a/docker/Dockerfile.dev +++ /dev/null @@ -1,27 +0,0 @@ -FROM frigate:latest - -ARG USERNAME=vscode -ARG USER_UID=1000 -ARG USER_GID=$USER_UID - -# Create the user -RUN groupadd --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \ - # - # [Optional] Add sudo support. Omit if you don't need to install software after connecting. - && apt-get update \ - && apt-get install -y sudo \ - && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ - && chmod 0440 /etc/sudoers.d/$USERNAME - -RUN apt-get update \ - && apt-get install -y git curl vim htop - -COPY requirements-dev.txt /opt/frigate/requirements-dev.txt -RUN pip3 install -r requirements-dev.txt - -# Install Node 16 -RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \ - && apt-get install -y nodejs - -RUN npm install -g npm@latest diff --git a/web/.dockerignore b/web/.dockerignore new file mode 100644 index 000000000..8814504e3 --- /dev/null +++ b/web/.dockerignore @@ -0,0 +1,3 @@ +.git/ +dist/ +node_modules/