Files
yingqing/core/backend/Dockerfile
T
zycandClaude Opus 4.8 9c3e4e5c8b 图片生成改为每张一条并行请求,根治多图生成超时 500
根因:多图生成走一条 HTTP 串行出 N 张,4 张累计 >120s 被 gunicorn 强杀 worker → 500
(日志实锤 SystemExit on ARK response.begin)。采纳用户建议拆成「每张一条请求」:

- App.tsx generateImages: 拆成 N 条并行单张请求(Promise.allSettled),单张约 30s 不超时,
  并行后总耗时≈单张(比串行快 N 倍),任一张失败只丢那张(各自独立扣费/回滚)
- Dockerfile: gunicorn --timeout 120→300,给慢 ARK 留余量(双保险)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 15:38:08 +08:00

38 lines
1.8 KiB
Docker

# ---- AirShelf core backend: Django + DRF + gunicorn / celery ----
FROM docker.m.daocloud.io/python:3.12-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
WORKDIR /app
# 视频导出(stage5 拼接)靠 ffmpeg 二进制;字幕用 Pillow 渲染 PNG 需中文字体(fonts-noto-cjk),
# 否则线上导出报 "No such file or directory: 'ffmpeg'" / 中文字幕变方块。slim 镜像默认两者都无。
# 换阿里云 apt 源避免国内构建超时(兼容 bookworm 的 deb822 与旧 sources.list 两种格式)。
RUN (sed -i 's|deb.debian.org|mirrors.aliyun.com|g; s|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null \
|| sed -i 's|deb.debian.org|mirrors.aliyun.com|g; s|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list 2>/dev/null || true) \
&& apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg fonts-noto-cjk \
&& rm -rf /var/lib/apt/lists/*
# PyMySQL is pure-python (install_as_MySQLdb), boto3/gunicorn need no C deps,
# so the slim image is enough — no build-essential required.
COPY requirements.txt .
RUN pip install --upgrade pip && pip install -r requirements.txt
COPY . .
# Collected admin/static lands here; served by WhiteNoise (see settings/production.py)
RUN mkdir -p /app/staticfiles
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
EXPOSE 8000
ENTRYPOINT ["docker-entrypoint.sh"]
# timeout 300:前端已把多图生成拆成「每张一条请求」,单张约 30s;300s 给慢 ARK 留充足余量,
# 不再因一条请求串行出多张而超时(旧 120s 下生成 4 张必被 worker 强杀 → 500)。
CMD ["gunicorn", "airshelf.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "300"]