From b923803e7c05e83bec308ab0d6c4b7b76b7e6af9 Mon Sep 17 00:00:00 2001 From: ihmily <114978440+ihmily@users.noreply.github.com> Date: Fri, 11 Apr 2025 20:21:35 +0800 Subject: [PATCH] feat: Add Docker support for simplified project setup - Added Dockerfile for building the application image - Added docker-compose.yml for multi-container orchestration - Updated README with instructions for running the project using Docker - Verified compatibility with existing project dependencies This change enables users to easily set up and run the project in a Docker environment, reducing local setup complexity. --- .dockerignore | 28 +++++++++++++++++++ .env.example | 5 +++- Dockerfile | 42 ++++++++++++++++++++++++++++ README.md | 69 ++++++++++++++++++++++++++++++++++++++++++---- README_EN.md | 68 +++++++++++++++++++++++++++++++++++++++++---- docker-compose.yml | 25 +++++++++++++++++ main.py | 4 ++- 7 files changed, 227 insertions(+), 14 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c452a85 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +# Version Control +**/.git + +# Development Configuration +**/.env* +**/docker-compose*.yml +**/Dockerfile* + +# Documentation and Tests +**/docs +**/tests +**/*.md + +# Build Artifacts and Cache +**/__pycache__ +**/*.pyc +**/*.log +**/node_modules +**/venv + +# IDE Files +**/.vscode +**/.idea + +# Static Assets (Adjust as needed) +**/.iconset/ +**/*.icns +assets/images \ No newline at end of file diff --git a/.env.example b/.env.example index 7ae2b7f..2cedbb6 100644 --- a/.env.example +++ b/.env.example @@ -6,4 +6,7 @@ PLATFORM=desktop HOST=127.0.0.1 # PORT: Web server port number (default: 6006) -PORT=6006 \ No newline at end of file +PORT=6006 + +# Set timezone +TZ=Asia/Shanghai \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e86f08 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM python:3.12-slim AS builder + +WORKDIR /app + +# Install system dependencies for build +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python dependencies +COPY requirements-web.txt . +RUN pip install --no-cache-dir -r requirements-web.txt + +COPY . . +RUN mkdir -p /app/logs /app/downloads + +# Final stage: production image +FROM python:3.12-slim + +WORKDIR /app + +RUN apt-get update && apt-get install -y --no-install-recommends \ + ffmpeg \ + tzdata \ + curl \ + gnupg \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y --no-install-recommends nodejs \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Set timezone +ENV TZ=Asia/Shanghai +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo "$TZ" > /etc/timezone + +# Copy Python dependencies and project files from the builder stage +COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages +COPY --from=builder /usr/local/bin /usr/local/bin +COPY --from=builder /app/ ./ + +CMD ["sh", "-c", "python main.py --web --host 0.0.0.0"] \ No newline at end of file diff --git a/README.md b/README.md index d0cf5b4..bb9de27 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,11 @@
@@ -16,10 +18,12 @@ + StreamCap 是一个基于FFmpeg和StreamGet的多平台直播流录制客户端,覆盖 40+ 国内外主流直播平台,支持批量录制、循环监控、定时监控和自动转码等功能。 ## ✨功能特性 +- **多端支持**:支持Windows/MacOS/Web运行 - **循环监控**:实时监控直播间状态,开播即录。 - **定时任务**:根据设定时间范围检查直播间状态。 - **多种输出格式**:支持 ts、flv、mkv、mov、mp4、mp3、m4a 等格式。 @@ -53,20 +57,73 @@ cd StreamCap 2.**安装依赖**: ```bash +# 桌面端 pip install -r requirements.txt -# 或者 -poetry install + +# Web端 +pip install -r requirements-web.txt ``` -3.**运行程序**: -使用以下命令启动程序: +3.**配置运行环境**: + +将.env.example示例配置文件复制一份并将文件重命名为.env + +```bash +cp .env.example .env +``` + +4.**运行程序**: + +在Windows和macOS上默认以桌面程序的方式运行,使用以下命令启动程序: ```bash python main.py ``` +修改 `.env` 文件,将 `PLATFORM` 的值改为 `web`,即可以Web方式运行。 + +或者,无需修改配置文件,直接使用以下命令启动 + +```bash +# Linux请使用web方式运行 + +python main.py --web +``` + +启动成功后,通过 `http://ip:6006` 访问。 + 如果程序提示缺少 FFmpeg,请访问 FFmpeg 官方下载页面[Download FFmpeg](https://ffmpeg.org/download.html),下载预编译的 FFmpeg 可执行文件,并配置环境变量。 +## 🐋容器运行 + +本机无需Python环境运行,在运行命令之前,请确保您的机器上安装了 [Docker](https://docs.docker.com/get-docker/) 和 [Docker Compose](https://docs.docker.com/compose/install/) + +1.**快速启动** + +最简单方法是运行项目中的 [docker-compose.yml](https://github.com/ihmily/StreamCap/blob/main/docker-compose.yml) 文件,进入项目根目录后,只需简单执行以下命令(确保已经存在`.env`文件): + +```bash +docker compose up +``` + +可选 `-d` 在后台运行。注意容器内时区问题,默认使用的是 `Asia/Shanghai` ,如需修改可以在.env文件配置。 + +2.**停止容器实例** + +```bash +docker compose stop +``` + +3.**构建镜像** + +Docker镜像仓库中代码版本可能不是最新的,如要运行本仓库主分支最新代码,可以本地自定义构建,通过修改 [docker-compose.yml](https://github.com/ihmily/StreamCap/blob/main/docker-compose.yml) 文件 + +```bash +docker build -t streamcap . +``` + +构建完成后,请先将docker-compose.yml文件中的镜像名称修改为 `streamcap` 后再使用`docker compose` 运行。 + ## 😺已支持平台 **国内平台(30+)**: diff --git a/README_EN.md b/README_EN.md index 7f0d666..f41b4bf 100644 --- a/README_EN.md +++ b/README_EN.md @@ -4,9 +4,11 @@ @@ -15,10 +17,12 @@