From 4b3c6cbee473f28eaa81b7053e615447366d2c0f Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 28 Mar 2026 02:39:29 -0500 Subject: [PATCH] 's' --- .dockerignore | 17 +- .gitignore | 12 + Dockerfile | 33 ++- config/runtime.env.example | 11 + dev.bat | 6 + dev.sh | 8 + docker-compose.yml | 10 + ecosystem.config.cjs | 26 ++ index.html | 10 +- obs.bat | 17 ++ obs.sh | 35 ++- package-lock.json | 327 +++++++++++++++++++++++++ package.json | 17 ++ requirements.txt | 4 +- scripts/env_check.py | 91 +++++++ scripts/launch.py | 245 +++++++++++++++++++ scripts/srt_to_hdmi_drm.example.sh | 10 + src/web_process_backend.py | 371 +++++++++++++++++++++++++++++ start.bat | 6 + start.sh | 9 + web.bat | 11 + web.py | 351 ++++++++++++++++----------- web.sh | 14 +- 23 files changed, 1468 insertions(+), 173 deletions(-) create mode 100644 config/runtime.env.example create mode 100644 dev.bat create mode 100644 dev.sh create mode 100644 docker-compose.yml create mode 100644 ecosystem.config.cjs create mode 100644 obs.bat create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 scripts/env_check.py create mode 100644 scripts/launch.py create mode 100644 scripts/srt_to_hdmi_drm.example.sh create mode 100644 src/web_process_backend.py create mode 100644 start.bat create mode 100644 start.sh create mode 100644 web.bat diff --git a/.dockerignore b/.dockerignore index 190f51b..a5404f7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,13 @@ -.github/workflows/build-image.yml .git -.gitignore -.dockerignore -README.md -LICENSE +.github +**/__pycache__ +**/*.pyc +.venv +venv +node_modules +web-console/node_modules +web-console/.next +*.log +.process_runner +.cursor +mobile diff --git a/.gitignore b/.gitignore index d50e05d..f77ecdc 100644 --- a/.gitignore +++ b/.gitignore @@ -165,3 +165,15 @@ cython_debug/ #.idea/ backup_config/ + +# 根目录 npm(concurrently 等) +node_modules/ + +# Next 开发缓存(静态导出目录 web-console/out 可纳入版本库以便无 Node 环境直接部署) +web-console/.next/ + +# 无 PM2 时的本地进程状态 +.process_runner/ + +# 本机端口/主机覆盖(从 config/runtime.env.example 复制) +config/runtime.env diff --git a/Dockerfile b/Dockerfile index e3c2cb1..860a6bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,28 @@ -FROM python:3.11-slim +# 生产镜像:ffmpeg + 多阶段构建 Next 静态页 + Python API(默认端口 8101,减少与同机 SRS/代理 冲突) +# docker compose up --build +FROM node:20-bookworm-slim AS console +WORKDIR /src/web-console +COPY web-console/package.json web-console/package-lock.json ./ +RUN npm ci +COPY web-console/ ./ +RUN npm run build +FROM python:3.12-slim-bookworm WORKDIR /app +ENV PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=1 \ + PORT=8101 -COPY . /app - -RUN apt-get update && \ - apt-get install -y curl gnupg && \ - curl -sL https://deb.nodesource.com/setup_20.x | bash - && \ - apt-get install -y nodejs +RUN apt-get update \ + && apt-get install -y --no-install-recommends ffmpeg ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && ffmpeg -version +COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt -RUN apt-get update && \ - apt-get install -y ffmpeg tzdata && \ - ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ - dpkg-reconfigure -f noninteractive tzdata +COPY . . +COPY --from=console /src/web-console/out ./web-console/out -CMD ["python", "main.py"] +EXPOSE 8101 +CMD ["sh", "-c", "exec python -m uvicorn web:app --host 0.0.0.0 --port ${PORT}"] diff --git a/config/runtime.env.example b/config/runtime.env.example new file mode 100644 index 0000000..f4bb26f --- /dev/null +++ b/config/runtime.env.example @@ -0,0 +1,11 @@ +# 复制本文件为同目录下的 runtime.env 后生效(已加入 .gitignore,不会提交) +# 启动器 scripts/launch.py 会自动加载 runtime.env 中的键(不覆盖已存在的环境变量) + +# 局域网内任意浏览器访问控制台时,请保持 0.0.0.0 +HOST=0.0.0.0 + +# Web 控制台(FastAPI + 静态页)端口;与同机 SRS / Clash / Neko 等冲突时请改成未占用端口,例如 8101、9200 +PORT=8001 + +# 开发模式时 Next 端口(一般无需改) +# NEXT_DEV_PORT=3000 diff --git a/dev.bat b/dev.bat new file mode 100644 index 0000000..2f1dca3 --- /dev/null +++ b/dev.bat @@ -0,0 +1,6 @@ +@echo off +cd /d "%~dp0" +if not defined PORT set "PORT=8001" +echo [dev] API+Next 开发模式 PORT=%PORT% +echo [dev] 浏览器打开 http://localhost:3000 +python scripts\launch.py --dev --port %PORT% diff --git a/dev.sh b/dev.sh new file mode 100644 index 0000000..2d76c98 --- /dev/null +++ b/dev.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# 开发:API(热重载) + Next dev;浏览器打开 http://localhost:3000 +set -euo pipefail +cd "$(dirname "$0")" +export PORT="${PORT:-8001}" +PY=python3 +command -v python3 >/dev/null 2>&1 || PY=python +exec "$PY" scripts/launch.py --dev --port "$PORT" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e71b3b7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +# 控制台默认 8101(与 SRS 8080/1985、Clash 7890 等错开);改端口请同步修改左侧宿主机映射 +services: + live-console: + build: . + ports: + - "${LIVE_CONSOLE_PORT:-8101}:8101" + restart: unless-stopped + environment: + HOST: "0.0.0.0" + PORT: "8101" diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs new file mode 100644 index 0000000..39abeba --- /dev/null +++ b/ecosystem.config.cjs @@ -0,0 +1,26 @@ +/** + * PM2:在项目根执行 `pm2 start ecosystem.config.cjs` 后 `pm2 save` + * web 使用 scripts/launch.py:若缺少 web-console/out 会自动 npm build 再起 uvicorn + */ +const path = require("path"); +const root = __dirname; +const py = process.env.PYTHON || "python3"; + +module.exports = { + apps: [ + { + name: "web", + cwd: root, + script: path.join(root, "scripts", "launch.py"), + interpreter: py, + env: { + HOST: "0.0.0.0", + PORT: process.env.PORT || "8001", + }, + }, + // { name: "youtube", cwd: root, script: py, args: "youtube.py" }, + // { name: "tiktok", cwd: root, script: py, args: "tiktok.py" }, + // Linux: { name: "obs", cwd: root, script: "bash", args: `-lc ${JSON.stringify(path.join(root, "obs.sh"))}` }, + // Win: { name: "obs", cwd: root, script: "cmd.exe", args: "/c obs.bat" }, + ], +}; diff --git a/index.html b/index.html index 0569b39..0cc8ca0 100644 --- a/index.html +++ b/index.html @@ -84,7 +84,7 @@ button.loading::after{content:" ⏳";animation:spin 1s linear infinite}
正在加载状态与日志...