Files
life-echo/api/Dockerfile
2026-05-25 11:39:38 +08:00

44 lines
1.3 KiB
Docker
Raw Permalink 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.
# Life Echo API Dockerfile
FROM python:3.13-slim
# 安装系统依赖 + uv
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libc6-dev \
libffi-dev \
libxml2-dev \
libxslt1-dev \
libjpeg-dev \
zlib1g-dev \
libpng-dev \
libfreetype6-dev \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
# 先复制依赖清单,利用 Docker 缓存
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project
# 复制应用代码并在镜像内安装项目(避免运行时 uv run 重新 sync 拉 dev 依赖)
COPY . .
RUN uv sync --frozen --no-dev
# 非 root 用户
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8000
HEALTHCHECK --interval=15s --timeout=5s --start-period=120s --retries=6 \
CMD python -c "import http.client; conn = http.client.HTTPConnection('localhost', 8000); conn.request('GET', '/health'); r = conn.getresponse(); exit(0 if r.status == 200 else 1)" || exit 1
# Alembic 迁移放到 FastAPI startup带重试与日志入口仅启动 web 进程。
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]