FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /app

# System deps: postgres client lib is provided by psycopg binary; only ca-certificates
# needs to be present for outbound HTTPS to the providers.
RUN apt-get update && apt-get install -y --no-install-recommends \
        ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

COPY app /app/app
COPY migrations /app/migrations
COPY voice_profiles /app/voice_profiles

# Brief output webroot. By default this is local to the container; production
# bind-mounts /var/www/just2done.com/brief here (see docker-compose.yml).
RUN mkdir -p /brief-output
VOLUME ["/brief-output"]

EXPOSE 8000

# Run migrations then boot uvicorn — keeps deploys dependency-free.
CMD ["sh", "-c", "python -m app.migrate && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 1"]