File size: 1,026 Bytes
35e80ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# syntax=docker/dockerfile:1
FROM python:3.11-slim AS build
WORKDIR /src
COPY pyproject.toml README.md ./
COPY src ./src
RUN pip install --no-cache-dir --prefix=/install ".[api]"

FROM python:3.11-slim
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 \
    COACH_CACHE_PATH=/data/responses.sqlite3 \
    COACH_LOG_DIR=/data/logs \
    COACH_ENV=prod
COPY --from=build /install /usr/local
RUN useradd --system --uid 10001 --home-dir /nonexistent coach && mkdir /data && chown coach /data
USER coach
VOLUME /data
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
  CMD python -c "import urllib.request as u; u.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"
# One worker on purpose: the response cache's single-flight and the in-memory budget guard live in the process.
# Scale by running more containers behind a load balancer, each with its own /data (or a shared budget store later).
CMD ["uvicorn", "ai_coach.api:create_app", "--factory", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]