From 73c43dbf8b253f97f5edaae3e921ac81fbd6f1ab Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Mon, 16 Feb 2026 04:50:24 +0300 Subject: [PATCH] Add CDN dependency download script and update Dockerfiles for offline web UI --- docker/Dockerfile | 15 ++++-- docker/download_cdn.sh | 105 +++++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 12 +++++ docker/hardware.Dockerfile | 15 ++++-- docker/rockchip.Dockerfile | 16 ++++-- 5 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 docker/download_cdn.sh create mode 100644 docker/entrypoint.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 9efded4b..2c095d48 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -26,7 +26,15 @@ COPY . . RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -# 2. Final image +# 2. Download CDN dependencies for offline web UI +FROM alpine AS download-cdn +RUN apk add --no-cache wget +COPY www/ /web/ +COPY docker/download_cdn.sh /tmp/ +RUN sh /tmp/download_cdn.sh /web + + +# 3. Final image FROM python:${PYTHON_VERSION}-alpine AS base # Install ffmpeg, tini (for signal handling), @@ -46,10 +54,11 @@ RUN if [ "${TARGETARCH}" = "amd64" ]; then apk add --no-cache libva-intel-driver # RUN libva-vdpau-driver mesa-vdpau-gallium (+150MB total) COPY --from=build /build/go2rtc /usr/local/bin/ +COPY --from=download-cdn /web /var/www/go2rtc +COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/ EXPOSE 1984 8554 8555 8555/udp -ENTRYPOINT ["/sbin/tini", "--"] +ENTRYPOINT ["/sbin/tini", "--", "/usr/local/bin/entrypoint.sh"] VOLUME /config WORKDIR /config -CMD ["go2rtc", "-config", "/config/go2rtc.yaml"] diff --git a/docker/download_cdn.sh b/docker/download_cdn.sh new file mode 100644 index 00000000..16b5e2d2 --- /dev/null +++ b/docker/download_cdn.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# Downloads CDN dependencies from jsdelivr for offline web UI. +# Automatically parses CDN URLs from HTML files, so updating +# a library version in HTML is all that's needed. +# +# Usage: download_cdn.sh +set -e + +WEB_DIR="${1:?Usage: download_cdn.sh }" +CDN_DIR="$WEB_DIR/cdn" +mkdir -p "$CDN_DIR" + +# Step 1: Extract all jsdelivr CDN URLs from HTML files +URLS=$(grep -roh 'https://cdn\.jsdelivr\.net/npm/[^"'"'"' )`]*' "$WEB_DIR"/*.html | sort -u) + +echo "=== Found CDN URLs ===" +echo "$URLS" +echo "" + +# Step 2: Process each URL +MONACO_VER="" +for url in $URLS; do + # Remove CDN prefix to get npm path + npm_path="${url#https://cdn.jsdelivr.net/npm/}" + + # Extract package@version and file path + pkg_ver=$(echo "$npm_path" | cut -d/ -f1) + remaining=$(echo "$npm_path" | cut -d/ -f2-) + if [ "$remaining" = "$npm_path" ]; then + file_path="" + else + file_path="$remaining" + fi + + pkg_name=$(echo "$pkg_ver" | sed 's/@[^@]*$//') + + # Monaco editor: remember version, download as tarball later + case "$pkg_name" in + monaco-editor) + MONACO_VER=$(echo "$pkg_ver" | sed 's/.*@//') + echo "Monaco editor v$MONACO_VER (will download tarball)" + continue + ;; + esac + + # Determine local file path + if [ -n "$file_path" ]; then + local_file="$CDN_DIR/$pkg_name/$file_path" + else + local_file="$CDN_DIR/$pkg_name/index.js" + fi + + mkdir -p "$(dirname "$local_file")" + echo "Downloading $pkg_ver -> $local_file" + wget -q -O "$local_file" "$url" +done + +# Step 3: Download monaco-editor tarball and extract min/ directory +# The AMD loader dynamically loads modules, so we need the entire min/vs/ tree +if [ -n "$MONACO_VER" ]; then + echo "" + echo "=== Downloading monaco-editor@$MONACO_VER tarball ===" + + TARBALL_URL=$(wget -q -O - "https://registry.npmjs.org/monaco-editor/$MONACO_VER" | \ + grep -o '"tarball":"[^"]*"' | head -1 | cut -d'"' -f4) + + mkdir -p /tmp/monaco "$CDN_DIR/monaco-editor" + wget -q -O /tmp/monaco.tgz "$TARBALL_URL" + tar xzf /tmp/monaco.tgz -C /tmp/monaco + + cp -r /tmp/monaco/package/min "$CDN_DIR/monaco-editor/" + rm -rf /tmp/monaco /tmp/monaco.tgz + + echo " Extracted min/ directory ($(du -sh "$CDN_DIR/monaco-editor/min" | cut -f1))" +fi + +# Step 4: Patch HTML files to use local paths instead of CDN URLs +echo "" +echo "=== Patching HTML files ===" +for url in $URLS; do + npm_path="${url#https://cdn.jsdelivr.net/npm/}" + + pkg_ver=$(echo "$npm_path" | cut -d/ -f1) + remaining=$(echo "$npm_path" | cut -d/ -f2-) + if [ "$remaining" = "$npm_path" ]; then + file_path="" + else + file_path="$remaining" + fi + + pkg_name=$(echo "$pkg_ver" | sed 's/@[^@]*$//') + + if [ -n "$file_path" ]; then + local_url="cdn/$pkg_name/$file_path" + else + local_url="cdn/$pkg_name/index.js" + fi + + echo " $url -> $local_url" + sed -i "s|$url|$local_url|g" "$WEB_DIR"/*.html +done + +echo "" +echo "=== Done ===" +du -sh "$CDN_DIR" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 00000000..0e0bb3cd --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Entrypoint wrapper for go2rtc Docker container. +# If /var/www/go2rtc exists (CDN files bundled), automatically +# configures static_dir to serve web UI without internet access. +if [ -d /var/www/go2rtc ]; then + exec go2rtc \ + -config '{"api":{"static_dir":"/var/www/go2rtc"}}' \ + -config /config/go2rtc.yaml \ + "$@" +else + exec go2rtc -config /config/go2rtc.yaml "$@" +fi diff --git a/docker/hardware.Dockerfile b/docker/hardware.Dockerfile index 563843b5..e972d59b 100644 --- a/docker/hardware.Dockerfile +++ b/docker/hardware.Dockerfile @@ -26,7 +26,15 @@ COPY . . RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -# 2. Final image +# 2. Download CDN dependencies for offline web UI +FROM alpine AS download-cdn +RUN apk add --no-cache wget +COPY www/ /web/ +COPY docker/download_cdn.sh /tmp/ +RUN sh /tmp/download_cdn.sh /web + + +# 3. Final image FROM debian:${DEBIAN_VERSION} # Prepare apt for buildkit cache @@ -48,13 +56,14 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,t apt-get clean && rm -rf /var/lib/apt/lists/* COPY --from=build /build/go2rtc /usr/local/bin/ +COPY --from=download-cdn /web /var/www/go2rtc +COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/ EXPOSE 1984 8554 8555 8555/udp -ENTRYPOINT ["/usr/bin/tini", "--"] +ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"] VOLUME /config WORKDIR /config # https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(Native-GPU-Support) ENV NVIDIA_VISIBLE_DEVICES all ENV NVIDIA_DRIVER_CAPABILITIES compute,video,utility -CMD ["go2rtc", "-config", "/config/go2rtc.yaml"] diff --git a/docker/rockchip.Dockerfile b/docker/rockchip.Dockerfile index 6ab924ee..12bfd002 100644 --- a/docker/rockchip.Dockerfile +++ b/docker/rockchip.Dockerfile @@ -24,7 +24,15 @@ COPY . . RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags "-s -w" -trimpath -# 2. Final image +# 2. Download CDN dependencies for offline web UI +FROM alpine AS download-cdn +RUN apk add --no-cache wget +COPY www/ /web/ +COPY docker/download_cdn.sh /tmp/ +RUN sh /tmp/download_cdn.sh /web + + +# 3. Final image FROM python:${PYTHON_VERSION} # Prepare apt for buildkit cache @@ -42,10 +50,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,t COPY --from=build /build/go2rtc /usr/local/bin/ ADD --chmod=755 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-8-no_extra_dump/ffmpeg /usr/local/bin +COPY --from=download-cdn /web /var/www/go2rtc +COPY --chmod=755 docker/entrypoint.sh /usr/local/bin/ EXPOSE 1984 8554 8555 8555/udp -ENTRYPOINT ["/usr/bin/tini", "--"] +ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"] VOLUME /config WORKDIR /config - -CMD ["go2rtc", "-config", "/config/go2rtc.yaml"]