Files
awoooi/apps/api/Dockerfile
OG T fb0ddf305c
All checks were successful
E2E Health Check / e2e-health (push) Successful in 17s
fix(api): fix dockerfile to include models.json, remove huge prompt example to fit 4K limit
2026-03-31 14:03:34 +08:00

59 lines
1.9 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.
# AWOOOI API - Production Dockerfile
# Phase 6.4i: 支援 monorepo 本地 packages (lewooogo-brain, lewooogo-data)
#
# 使用方式 (從 monorepo 根目錄):
# docker build -f apps/api/Dockerfile -t awoooi-api:v1.0.0 .
#
# 注意: 必須從 monorepo 根目錄執行,否則無法存取 packages/
FROM python:3.11-slim AS builder
WORKDIR /app
# Install uv (固定版本,禁止 :latest)
COPY --from=ghcr.io/astral-sh/uv:0.6.9 /uv /bin/uv
# Phase 6.4i: 複製本地 packages 到 Docker context
# 順序重要: 先複製 packages再複製 api (利用 Docker layer cache)
COPY packages/lewooogo-data/ /packages/lewooogo-data/
COPY packages/lewooogo-brain/ /packages/lewooogo-brain/
# 複製 API 依賴文件 (pyproject.toml 需要 README.md)
COPY apps/api/pyproject.toml apps/api/README.md ./
# 複製 src 目錄 (hatchling build 需要)
COPY apps/api/src/ ./src/
# 安裝本地 packages 與 API 依賴 (合併 RUN 減少 layer)
# 注意: `uv pip install .` 從 pyproject.toml 安裝依賴
RUN uv pip install --system --no-cache /packages/lewooogo-data && \
uv pip install --system --no-cache /packages/lewooogo-brain && \
uv pip install --system --no-cache .
# Production stage
FROM python:3.11-slim
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code and models config
COPY apps/api/src/ ./src/
COPY apps/api/models.json ./models.json
# Create non-root user
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# Expose port
EXPOSE 8000
# Health check (使用正確的 API 路徑)
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import httpx; httpx.get('http://localhost:8000/api/v1/health', timeout=5)" || exit 1
# Run application
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]