mirror of
https://github.com/kennethreitz/rhymepad.org.git
synced 2026-07-21 22:09:30 +00:00
66de2b06b0
The rhyme engine never cared which framework wrapped it; this trades the FastAPI shell for Responder. Routes become (req, resp) views, static serves from the site root so no asset URL moves, and the CPU-heavy handlers stay sync to keep running in the threadpool. Granian replaces uvicorn as the server. Tests drive the engine directly now that views aren't plain callables. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
33 lines
1.2 KiB
Docker
33 lines
1.2 KiB
Docker
FROM python:3.12-slim
|
|
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
|
|
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
UV_COMPILE_BYTECODE=1 \
|
|
UV_LINK_MODE=copy
|
|
|
|
WORKDIR /app
|
|
|
|
# Dependencies only (rhymepad is a single-module app, not a packaged project)
|
|
COPY pyproject.toml uv.lock ./
|
|
RUN uv sync --frozen --no-dev --no-install-project
|
|
|
|
COPY app.py rhymes.py ./
|
|
COPY static ./static
|
|
COPY data ./data
|
|
|
|
# Pre-warm NLTK data so g2p-en never downloads at request time
|
|
# (--no-sync: use the env built above; don't try to install the project)
|
|
RUN uv run --no-sync python -c "import nltk;\
|
|
[nltk.download(p, quiet=True) for p in ('averaged_perceptron_tagger','averaged_perceptron_tagger_eng','cmudict')]" || true
|
|
|
|
EXPOSE 8000
|
|
|
|
# Swarm swaps traffic only once the new container is actually serving —
|
|
# boot includes model warmup, so give it a generous start period
|
|
HEALTHCHECK --interval=10s --timeout=3s --start-period=180s --retries=3 \
|
|
CMD ["python3", "-c", "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2).status==200 else 1)"]
|
|
|
|
CMD ["uv", "run", "--no-sync", "granian", "--interface", "asgi", "--host", "0.0.0.0", "--port", "8000", "app:api"]
|