From e36dc576d38eb2d8b4cf6c4fa4c573ff4e309e5d Mon Sep 17 00:00:00 2001 From: Chris King Date: Tue, 21 Jan 2025 10:51:54 -0800 Subject: [PATCH] Add webonly build and push options to Makefile Change container repo to private Gitea Add webonly build Dockerfile Add .node-version for fnm Do not route settings, config, or logs to non admin users Do not show settings, system logs, system restart or config editor links to non admin users Add list of admin usernames to user.ts --- Makefile | 14 ++- docker/webonly/Dockerfile | 19 +++ web/.node-version | 1 + web/src/App.tsx | 13 ++- web/src/components/menu/GeneralSettings.tsx | 122 ++++++++++++-------- web/src/types/user.ts | 2 + 6 files changed, 116 insertions(+), 55 deletions(-) create mode 100644 docker/webonly/Dockerfile create mode 100644 web/.node-version diff --git a/Makefile b/Makefile index 1c1d19a0c..01633d27a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ default_target: local COMMIT_HASH := $(shell git log -1 --pretty=format:"%h"|tail -1) VERSION = 0.14.1 -IMAGE_REPO ?= ghcr.io/blakeblackshear/frigate +#IMAGE_REPO ?= ghcr.io/blakeblackshear/frigate +IMAGE_REPO ?= gitea.tremendousturtle.tools/chris/frigate GITHUB_REF_NAME ?= $(shell git rev-parse --abbrev-ref HEAD) CURRENT_UID := $(shell id -u) CURRENT_GID := $(shell id -g) @@ -23,15 +24,24 @@ local: version amd64: docker buildx build --platform linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile . +amd64_web: + docker buildx build --platform linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile . + arm64: - docker buildx build --platform linux/arm64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile . + docker buildx build --platform linux/arm64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/webonly/Dockerfile . build: version amd64 arm64 docker buildx build --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/main/Dockerfile . +build_web: version amd64 arm64 + docker buildx build --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):$(VERSION)-$(COMMIT_HASH) --file docker/webonly/Dockerfile . + push: push-boards docker buildx build --push --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) --file docker/main/Dockerfile . +push_web: push-boards + docker buildx build --push --platform linux/arm64/v8,linux/amd64 --target=frigate --tag $(IMAGE_REPO):${GITHUB_REF_NAME}-$(COMMIT_HASH) --file docker/webonly/Dockerfile . + run: local docker run --rm --publish=5000:5000 --volume=${PWD}/config:/config frigate:latest diff --git a/docker/webonly/Dockerfile b/docker/webonly/Dockerfile new file mode 100644 index 000000000..5253cb46e --- /dev/null +++ b/docker/webonly/Dockerfile @@ -0,0 +1,19 @@ +# syntax=docker/dockerfile:1.6 + +# Frigate web build +# This should be architecture agnostic, so speed up the build on multiarch by not using QEMU. +FROM --platform=$BUILDPLATFORM node:20 AS web-build + +WORKDIR /work +COPY web/package.json web/package-lock.json ./ +RUN npm install + +COPY web/ ./ +RUN npm run build \ + && mv dist/BASE_PATH/monacoeditorwork/* dist/assets/ \ + && rm -rf dist/BASE_PATH + +FROM --platform=$BUILDPLATFORM ghcr.io/blakeblackshear/frigate:stable AS frigate +WORKDIR /opt/frigate/ +RUN rm -rf web/ && mkdir web +COPY --from=web-build /work/dist/ web/ diff --git a/web/.node-version b/web/.node-version new file mode 100644 index 000000000..209e3ef4b --- /dev/null +++ b/web/.node-version @@ -0,0 +1 @@ +20 diff --git a/web/src/App.tsx b/web/src/App.tsx index 93e980f2c..cda13dd5f 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -10,6 +10,8 @@ import { Suspense, lazy } from "react"; import { Redirect } from "./components/navigation/Redirect"; import { cn } from "./lib/utils"; import { isPWA } from "./utils/isPWA"; +import { ADMIN_USERS } from "@/types/user"; +import useSWR from "swr"; const Live = lazy(() => import("@/pages/Live")); const Events = lazy(() => import("@/pages/Events")); @@ -22,6 +24,7 @@ const UIPlayground = lazy(() => import("@/pages/UIPlayground")); const Logs = lazy(() => import("@/pages/Logs")); function App() { + const { data: profile } = useSWR("profile"); return ( @@ -47,9 +50,13 @@ function App() { } /> } /> } /> - } /> - } /> - } /> + {ADMIN_USERS.includes(profile?.username) && ( + <> + } /> + } /> + } /> + + )} } /> } /> diff --git a/web/src/components/menu/GeneralSettings.tsx b/web/src/components/menu/GeneralSettings.tsx index 34637d57e..7ef973712 100644 --- a/web/src/components/menu/GeneralSettings.tsx +++ b/web/src/components/menu/GeneralSettings.tsx @@ -68,6 +68,8 @@ import { import { TooltipPortal } from "@radix-ui/react-tooltip"; import { cn } from "@/lib/utils"; import { baseUrl } from "@/api/baseUrl"; +import useSWR from "swr"; +import { ADMIN_USERS } from "@/types/user"; type GeneralSettingsProps = { className?: string; @@ -80,6 +82,8 @@ export default function GeneralSettings({ className }: GeneralSettingsProps) { const { send: sendRestart } = useRestart(); + const { data: profile } = useSWR("profile"); + useEffect(() => { let countdownInterval: NodeJS.Timeout; @@ -169,48 +173,58 @@ export default function GeneralSettings({ className }: GeneralSettingsProps) { System metrics - - - - System logs - - + {ADMIN_USERS.includes(profile?.username) && ( + + + + System logs + + + )} - - Configuration - - + {ADMIN_USERS.includes(profile?.username) && ( + <> + + Configuration + + + + )} - - - - Settings - - - - - - Configuration editor - - + {ADMIN_USERS.includes(profile?.username) && ( + <> + + + + Settings + + + + + + Configuration editor + + + + )} Appearance @@ -358,16 +372,24 @@ export default function GeneralSettings({ className }: GeneralSettingsProps) { GitHub - - setRestartDialogOpen(true)} - > - - Restart Frigate - + {ADMIN_USERS.includes(profile?.username) && ( + <> + + setRestartDialogOpen(true)} + > + + Restart Frigate + + + )} diff --git a/web/src/types/user.ts b/web/src/types/user.ts index fcb37c168..1a0ad9b56 100644 --- a/web/src/types/user.ts +++ b/web/src/types/user.ts @@ -1,3 +1,5 @@ export type User = { username: string; }; + +export const ADMIN_USERS: string[] = ["admin", "cking91977", "akadmin"];