2025-06-16 01:43:21 +08:00
|
|
|
FROM ghcr.io/astral-sh/uv:python3.11-alpine
|
2025-04-25 04:38:10 +08:00
|
|
|
|
2025-06-15 20:29:47 +08:00
|
|
|
ENV ENV_MODE production
|
2025-04-28 05:21:59 +08:00
|
|
|
WORKDIR /app
|
2025-04-25 05:15:40 +08:00
|
|
|
|
2025-07-01 01:41:32 +08:00
|
|
|
RUN apk add --no-cache curl
|
|
|
|
|
2025-04-28 05:21:59 +08:00
|
|
|
# Install Python dependencies
|
2025-06-16 01:43:21 +08:00
|
|
|
COPY pyproject.toml uv.lock ./
|
2025-06-15 20:29:47 +08:00
|
|
|
ENV UV_LINK_MODE=copy
|
|
|
|
RUN --mount=type=cache,target=/root/.cache/uv uv sync --locked --quiet
|
2025-04-25 04:38:10 +08:00
|
|
|
|
2025-04-28 05:21:59 +08:00
|
|
|
# Copy application code
|
2025-06-15 20:29:47 +08:00
|
|
|
COPY . .
|
2025-04-18 10:22:35 +08:00
|
|
|
|
2025-04-28 05:21:59 +08:00
|
|
|
# Calculate optimal worker count based on 16 vCPUs
|
|
|
|
# Using (2*CPU)+1 formula for CPU-bound applications
|
2025-06-16 01:43:21 +08:00
|
|
|
ENV WORKERS=33
|
|
|
|
ENV THREADS=2
|
2025-04-28 05:21:59 +08:00
|
|
|
ENV WORKER_CONNECTIONS=2000
|
|
|
|
|
2025-06-24 17:04:13 +08:00
|
|
|
ENV PYTHONPATH=/app
|
2025-05-26 00:50:21 +08:00
|
|
|
EXPOSE 8000
|
|
|
|
|
2025-04-28 05:21:59 +08:00
|
|
|
# Gunicorn configuration
|
2025-06-15 20:29:47 +08:00
|
|
|
CMD ["sh", "-c", "uv run gunicorn api:app \
|
|
|
|
--workers $WORKERS \
|
|
|
|
--worker-class uvicorn.workers.UvicornWorker \
|
|
|
|
--bind 0.0.0.0:8000 \
|
|
|
|
--timeout 1800 \
|
|
|
|
--graceful-timeout 600 \
|
|
|
|
--keep-alive 1800 \
|
|
|
|
--max-requests 0 \
|
|
|
|
--max-requests-jitter 0 \
|
|
|
|
--forwarded-allow-ips '*' \
|
|
|
|
--worker-connections $WORKER_CONNECTIONS \
|
|
|
|
--worker-tmp-dir /dev/shm \
|
|
|
|
--preload \
|
|
|
|
--log-level info \
|
|
|
|
--access-logfile - \
|
|
|
|
--error-logfile - \
|
|
|
|
--capture-output \
|
|
|
|
--enable-stdio-inheritance \
|
|
|
|
--threads $THREADS"]
|