46 lines
1.0 KiB
Docker
46 lines
1.0 KiB
Docker
FROM python:3.11-slim
|
||
|
||
WORKDIR /app
|
||
|
||
# 安装系统依赖(Playwright需要)
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||
curl \
|
||
wget \
|
||
gnupg \
|
||
libglib2.0-0 \
|
||
libnss3 \
|
||
libnspr4 \
|
||
libatk1.0-0 \
|
||
libatk-bridge2.0-0 \
|
||
libcups2 \
|
||
libdrm2 \
|
||
libxkbcommon0 \
|
||
libxcomposite1 \
|
||
libxdamage1 \
|
||
libxrandr2 \
|
||
libgbm1 \
|
||
libpango-1.0-0 \
|
||
libcairo2 \
|
||
libasound2 \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 复制并安装Python依赖
|
||
COPY requirements.txt .
|
||
RUN pip install --no-cache-dir -r requirements.txt
|
||
|
||
# 安装Playwright浏览器
|
||
RUN playwright install chromium
|
||
RUN playwright install-deps chromium
|
||
|
||
# 复制应用代码
|
||
COPY . .
|
||
|
||
EXPOSE 8000
|
||
|
||
# 健康检查
|
||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
||
CMD curl -f http://localhost:8000/health || exit 1
|
||
|
||
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", \
|
||
"--bind", "0.0.0.0:8000", "--timeout", "120", "--access-logfile", "-"]
|