# Build context is the repo root (see docker-compose.yml) so the sibling
# packages Core/, Persistance/, Extraction/, models/ and indicadores_kit/
# can be copied.
FROM python:3.12-slim

# Tesseract (with Spanish data) for scanned documents; pytesseract only wraps the binary.
RUN apt-get update && apt-get install -y --no-install-recommends \
    tesseract-ocr tesseract-ocr-spa \
    && rm -rf /var/lib/apt/lists/*

COPY --from=ghcr.io/astral-sh/uv:0.7.9 /uv /uvx /bin/

WORKDIR /app
COPY Core/ Core/
COPY Persistance/ Persistance/
COPY Extraction/ Extraction/
COPY models/ models/
COPY indicadores_kit/ indicadores_kit/
COPY WebApi/ WebApi/

# One environment for the API, the migrations and the indicator cycle. The SQL
# drivers serve both the import sources and *_DATABASE_URL on MySQL/PostgreSQL/SQL Server.
RUN cd WebApi && uv sync --locked --no-dev --extra sql-drivers

ENV CACU_DATABASE_URL=sqlite:////data/cacu.db
ENV CAMA_DATABASE_URL=sqlite:////data/cama.db
ENV TEA_DATABASE_URL=sqlite:////data/tea.db
ENV GOVERNANCE_DATABASE_URL=sqlite:////data/governance.db
# MLflow model registry and artifacts, next to the databases so backups cover them.
ENV MLFLOW_TRACKING_URI=sqlite:////data/mlflow.db
ENV MLFLOW_ARTIFACT_ROOT=/data/mlflow-artefactos
# No usage telemetry from MLflow: the server runs on a closed network.
ENV MLFLOW_DISABLE_TELEMETRY=true DO_NOT_TRACK=true
# Aggregate import log and the live indicator queue (webapi.indicadores_vivos).
ENV WEBAPI_REPORT_DIR=/data/reportes
ENV INDICADORES_DIR=/data/indicadores
ENV MLFLOW_DISABLE_AGENT_HINT=1

RUN chmod +x /app/WebApi/docker-entrypoint.sh

EXPOSE 5000
ENTRYPOINT ["/app/WebApi/docker-entrypoint.sh"]
