Files
life-echo/api/Dockerfile

45 lines
1.3 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.
# 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
# 复制应用代码
COPY . .
# 构建时预下载 faster-whisper 模型
ARG ASR_MODEL_SIZE=small
RUN uv run python -c "from faster_whisper import WhisperModel; WhisperModel('${ASR_MODEL_SIZE}', device='cpu', compute_type='int8', download_root='/app/models/whisper')"
# 非 root 用户
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
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 ["sh", "-c", "uv run uvicorn main:app --host 0.0.0.0 --port 8000"]