71825df8b2
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
Deploy / Deploy Staging (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been cancelled
Deploy / Deploy Production (push) Has been cancelled
Deploy / Production Browser E2E (push) Has been cancelled
50 lines
1.7 KiB
Docker
50 lines
1.7 KiB
Docker
# ============================================================
|
|
# API Dockerfile - 专门用于 FastAPI 应用
|
|
# 优化:仅包含 API 所需的依赖
|
|
# ============================================================
|
|
|
|
# 基础镜像:Python 3.12
|
|
FROM python:3.12-slim-bookworm
|
|
|
|
# 使用阿里云镜像加速
|
|
RUN sed -i 's|deb.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' /etc/apt/sources.list 2>/dev/null || true
|
|
|
|
# 安装系统依赖
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 复制 requirements.txt(排除 worker 专用依赖)
|
|
# API 需要 psycopg2/sqlalchemy 用于数据库连接
|
|
# 注意:opencv、scipy 等是 worker 专用依赖,不在 API 中安装
|
|
COPY requirements.txt /tmp/requirements.txt
|
|
|
|
# 创建虚拟环境并安装依赖
|
|
RUN python -m venv /opt/venv \
|
|
&& /opt/venv/bin/pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r /tmp/requirements.txt \
|
|
&& rm /tmp/requirements.txt
|
|
|
|
# 复制应用代码
|
|
COPY apps/api/ /app/apps/api/
|
|
COPY packages/ /app/packages/
|
|
COPY alembic.ini /app/alembic.ini
|
|
COPY migrations/ /app/migrations/
|
|
COPY alembic/ /app/alembic/
|
|
|
|
# 设置环境变量
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
ENV PYTHONPATH=/app
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)"
|
|
|
|
# API 入口点
|
|
WORKDIR /app/apps/api
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|