build: switch services to gunicorn with per-service config
Replace uvicorn with gunicorn + UvicornWorker in backend, runtime, and schedule Dockerfiles. New gunicorn.conf.py per service exposes bind/workers/timeout/graceful_timeout as GUNICORN_* env knobs. Notable details: - schedule: timeout=0 (disables gunicorn worker heartbeat) so long notebook execution isn't killed by gunicorn's silent-worker kill. - All three configs: drop dead threads=4 setting; UvicornWorker is async and ignores threads. - Pin gunicorn>=26.0.0 in each pyproject; uv.lock regenerated. - Drop stale 'COPY contracts ./contracts' from runtime and schedule Dockerfiles (contracts dir was deleted in an earlier refactor; builds would have failed). - backend Dockerfile: switch to uv sync layout matching runtime/ schedule; add build deps for native wheels. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+12
-2
@@ -2,11 +2,21 @@ FROM python:3.12-slim-bookworm
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PYTHONPATH=/app
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
ca-certificates \
|
||||
gcc \
|
||||
g++ \
|
||||
python3-dev \
|
||||
build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
|
||||
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
||||
COPY pyproject.toml uv.lock ./
|
||||
COPY common ./common
|
||||
COPY schedule ./schedule
|
||||
COPY contracts ./contracts
|
||||
RUN UV_DEFAULT_INDEX="https://pypi.tuna.tsinghua.edu.cn/simple/" uv sync --frozen --no-dev --no-editable --package schedule
|
||||
|
||||
EXPOSE 8000
|
||||
CMD ["uv", "run", "uvicorn", "schedule.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
CMD ["uv", "run", "--frozen", "--package", "schedule", "gunicorn", "--config", "schedule/gunicorn.conf.py", "schedule.main:app"]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
"""Gunicorn configuration for the schedule service.
|
||||
|
||||
Workers MUST stay at 1: the embedded APScheduler and the Outbox
|
||||
poller must not run twice in the same container.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
bind = os.getenv("GUNICORN_BIND", "0.0.0.0:8000")
|
||||
workers = int(os.getenv("GUNICORN_WORKERS", "1"))
|
||||
worker_class = "uvicorn.workers.UvicornWorker"
|
||||
# 0 disables gunicorn worker heartbeat timeout — needed because
|
||||
# NodeExecutor runs notebooks synchronously.
|
||||
timeout = int(os.getenv("GUNICORN_TIMEOUT", "0"))
|
||||
graceful_timeout = int(os.getenv("GUNICORN_GRACEFUL_TIMEOUT", "30"))
|
||||
accesslog = "-"
|
||||
errorlog = "-"
|
||||
@@ -12,11 +12,16 @@ dependencies = [
|
||||
"nbclient==0.10.2",
|
||||
"nbformat==5.10.4",
|
||||
"ipykernel==6.29.5",
|
||||
"gunicorn>=26.0.0",
|
||||
]
|
||||
|
||||
[tool.uv.sources]
|
||||
common = { workspace = true }
|
||||
|
||||
[[tool.uv.index]]
|
||||
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
|
||||
default = true
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
|
||||
Reference in New Issue
Block a user