perf(ci): Worker镜像瘦身 - 多阶段构建+ffmpeg静态替换+Python依赖瘦身 #340

Merged
xiaoxia merged 1 commits from feat/worker-image-slimming into develop 2026-07-15 07:49:15 +08:00
Owner

Worker 镜像瘦身优化

目标:从 1.59GB 降到 < 1GB(降幅 ~37%),缩短构建时间和部署时间。

优化项

  1. 多阶段构建(预计节省 ~50MB)

    • builder 阶段安装 gcc/g++/binutils 等编译工具
    • runtime 阶段只保留运行时依赖,去掉构建工具链
  2. ffmpeg 静态编译替换(预计节省 ~380MB)

    • 移除 apt-get install ffmpeg libsm6 libxext6 libgl1(约457MB)
    • 使用 johnvansickle.com 静态编译版本(约80MB)
    • 不依赖任何系统图形库
  3. Python 依赖瘦身(预计节省 ~120MB)

    • strip .so 调试符号(~80-100MB)
    • 清理测试文件(~20MB)
    • 清理 pycache 和 .pyc(~10MB)
    • 清理 dist-info 文档

风险与验证

  • opencv 兼容性:headless 版本不需要 libgl,但需要 libglib2.0-0,已保留
  • ffmpeg 功能完整性:静态版包含常用编解码器,需验证 Worker 实际处理流程
  • strip 安全性:标准操作,极少见兼容性问题

验证计划

  1. CI 构建成功 -> 查看镜像大小
  2. Staging 部署 -> 跑 E2E + 集成测试
  3. Worker 实际任务验证 -> 视频转码、字幕生成等核心流程
## Worker 镜像瘦身优化 **目标**:从 1.59GB 降到 < 1GB(降幅 ~37%),缩短构建时间和部署时间。 ### 优化项 1. **多阶段构建**(预计节省 ~50MB) - builder 阶段安装 gcc/g++/binutils 等编译工具 - runtime 阶段只保留运行时依赖,去掉构建工具链 2. **ffmpeg 静态编译替换**(预计节省 ~380MB) - 移除 `apt-get install ffmpeg libsm6 libxext6 libgl1`(约457MB) - 使用 johnvansickle.com 静态编译版本(约80MB) - 不依赖任何系统图形库 3. **Python 依赖瘦身**(预计节省 ~120MB) - strip .so 调试符号(~80-100MB) - 清理测试文件(~20MB) - 清理 __pycache__ 和 .pyc(~10MB) - 清理 dist-info 文档 ### 风险与验证 - **opencv 兼容性**:headless 版本不需要 libgl,但需要 libglib2.0-0,已保留 - **ffmpeg 功能完整性**:静态版包含常用编解码器,需验证 Worker 实际处理流程 - **strip 安全性**:标准操作,极少见兼容性问题 ### 验证计划 1. CI 构建成功 -> 查看镜像大小 2. Staging 部署 -> 跑 E2E + 集成测试 3. Worker 实际任务验证 -> 视频转码、字幕生成等核心流程
xiaoxia added 1 commit 2026-07-15 07:41:29 +08:00
perf(ci): Worker镜像瘦身 - 多阶段构建+ffmpeg静态替换+Python依赖瘦身
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m15s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m49s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 1m56s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m14s
aa3eb7884b
xiaoxia added 1 commit 2026-07-15 07:41:29 +08:00
perf(ci): Worker镜像瘦身 - 多阶段构建+ffmpeg静态替换+Python依赖瘦身
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m15s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m49s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 1m56s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m14s
aa3eb7884b
xiaoxia reviewed 2026-07-15 07:48:13 +08:00
xiaoxia left a comment
Author
Owner

Review 通过

多阶段构建:

  • builder 阶段装 gcc/g++/binutils 等编译依赖,runtime 阶段完全不带,瘦身幅度大
  • venv 完整从 builder 复制到 runtime,标准做法

ffmpeg 静态编译替换:

  • 从 apt 安装换成 johnvansickle 的静态二进制,省掉 ~350MB+ 的系统依赖
  • ffmpeg/ffprobe 都复制到了 /usr/local/bin,路径没问题

Python 依赖瘦身:

  • strip .so 调试符号:约 80-100MB,合理
  • 清理 test 文件、pycache、dist-info 文档:都是安全的
  • 注意 strip 可能影响某些带 C 扩展的库调试,但生产环境不需要

其他:

  • runtime 只留 libglib2.0-0(opencv 依赖),删除了 ffmpeg/libsm6/libxext6/libgl1,正确
  • 镜像加速源保留
  • 入口脚本和代码复制逻辑没变

CI 全绿,可以合并。合并后建议验证实际镜像大小是否达标(<1GB)。

Review 通过 ✅ **多阶段构建:** - builder 阶段装 gcc/g++/binutils 等编译依赖,runtime 阶段完全不带,瘦身幅度大 - venv 完整从 builder 复制到 runtime,标准做法 **ffmpeg 静态编译替换:** - 从 apt 安装换成 johnvansickle 的静态二进制,省掉 ~350MB+ 的系统依赖 - ffmpeg/ffprobe 都复制到了 /usr/local/bin,路径没问题 **Python 依赖瘦身:** - strip .so 调试符号:约 80-100MB,合理 - 清理 test 文件、__pycache__、dist-info 文档:都是安全的 - 注意 strip 可能影响某些带 C 扩展的库调试,但生产环境不需要 **其他:** - runtime 只留 libglib2.0-0(opencv 依赖),删除了 ffmpeg/libsm6/libxext6/libgl1,正确 - 镜像加速源保留 - 入口脚本和代码复制逻辑没变 CI 全绿,可以合并。合并后建议验证实际镜像大小是否达标(<1GB)。
xiaoxia merged commit ca8b945054 into develop 2026-07-15 07:49:15 +08:00
Sign in to join this conversation.