Files
audio2text/Dockerfile
zikai 00e2a95fb7 Initial commit: audio2text 双语字幕生成服务
- 音频/视频转双语(英/中)SRT 字幕,Docker 容器化,CPU 开发/GPU 生产同一份代码
- faster-whisper ASR(词级时间戳) + 断句时间戳重算 + NLLB 翻译(模型不共驻)
- 分片上传(断点续传) + SQLite 持久化 + 主页/历史/日志页面
- 历史页文件名搜索;缓存定时清理(默认保留7天,可配置)
- 双 Dockerfile(cpu/gpu) + setup/start/stop 脚本
2026-07-06 06:54:19 +00:00

64 lines
2.6 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# audio2text — 一份 DockerfileCPU(dev) / GPU(prod) 双形态。
# docker build --build-arg VARIANT=cpu -t audio2text:cpu .
# docker build --build-arg VARIANT=gpu -t audio2text:gpu .
# 区别仅在基础镜像与 torch 轮子Python 依赖列表完全一致。
ARG VARIANT=cpu
FROM python:3.12-slim AS base-cpu
# GPU 基础镜像带 CUDA 运行时torch 可装 CUDA 轮子
FROM nvidia/cuda:12.1.0-runtime-ubuntu22.04 AS base-gpu
RUN apt-get update -y && apt-get install -y --no-install-recommends \
python3.12 python3.12-venv python3.12-dev python3-pip \
&& rm -rf /var/lib/apt/lists/* \
&& ln -sf /usr/bin/python3.12 /usr/local/bin/python3 \
&& ln -sf /usr/bin/python3.12 /usr/local/bin/python
FROM base-${VARIANT} AS final
ARG VARIANT
ENV VARIANT=${VARIANT} \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
HF_HOME=/models/huggingface \
CT2_CACHE=/models/ctranslate2
# ffmpeg 是核心系统依赖,必须装
RUN apt-get update -y && apt-get install -y --no-install-recommends \
ffmpeg ca-certificates patchelf \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt /app/requirements.txt
# CPU 装 CPU 版 torchGPU 走默认 index带 CUDA 的轮子)
RUN if [ "$VARIANT" = "cpu" ]; then \
pip install --upgrade pip && \
pip install torch --index-url https://download.pytorch.org/whl/cpu ; \
else \
pip install --upgrade pip && \
pip install torch ; \
fi
RUN pip install -r /app/requirements.txt
# ctranslate2 的 .so 带可执行栈标志PT_GNU_STACK X在某些内核 + Docker 组合下
# 会触发 "cannot enable executable stack as shared object requires"。用 patchelf
# 清掉该标志(改为 RW无需放宽容器安全策略。
# 注意:库在 ctranslate2.libs/ 隐藏目录pip wheel 拆分产物),不在 ctranslate2/ 包目录。
RUN for d in /usr/local/lib/python3.12/site-packages/ctranslate2.libs \
/usr/local/lib/python3.12/site-packages/ctranslate2; do \
[ -d "$d" ] && find "$d" -name '*.so*' \
-exec patchelf --clear-execstack {} \; 2>/dev/null || true; \
done; \
python -c "import ctranslate2; print('ctranslate2 stack fix verified', ctranslate2.__version__)"
COPY app /app/app
COPY config.example.yaml /app/config.example.yaml
# 运行时数据:上传 / 中间产物 / 输出字幕 / 模型缓存
# 全部走 volume镜像本身无状态、无敏感数据
VOLUME ["/data", "/models"]
ENV CONFIG_PATH=/app/config.yaml
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]