Files
WebApi/Dockerfile
T

65 lines
3.0 KiB
Docker

# Build context is the repo root (see docker-compose.yml) so the sibling
# packages Core/, Persistance/, Extraction/ and models/
# can be copied, and Transformation/ compiled.
# dbt's manifest: the measures' definitions and the compiled SQL of their event
# models. The API serves the measures from it and the indicator cycle creates
# the views. The manifest built here is SQLite's, the image's default engine;
# the same environments compile it again at start-up against MySQL/MariaDB,
# PostgreSQL or SQL Server when *_DATABASE_URL points there (docker-entrypoint.sh),
# because those adapters open a connection to compile. dbt-mysql needs an
# older dbt-core, so it gets an environment of its own.
FROM python:3.12-slim AS manifest
COPY --from=ghcr.io/astral-sh/uv:0.7.9 /uv /uvx /bin/
WORKDIR /app/Transformation
COPY Transformation/ ./
RUN uv sync --group sqlite --group sqlserver --group postgres \
&& UV_PROJECT_ENVIRONMENT=.venv-mysql uv sync --only-group mysql \
&& uv run --no-sync dbt compile --profiles-dir . --profile cacu --target sqlite --no-introspect
FROM python:3.12-slim
# Tesseract (with Spanish data) for scanned documents; pytesseract only wraps the binary. Graphviz's `dot` draws each
# trained version's dataflow (`diagramas/pipeline.svg`); without it only the `.dot` source is stored.
RUN apt-get update && apt-get install -y --no-install-recommends \
tesseract-ocr tesseract-ocr-spa graphviz \
&& 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 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.recomputation).
ENV WEBAPI_REPORT_DIR=/data/reportes
ENV INDICADORES_DIR=/data/indicadores
ENV MLFLOW_DISABLE_AGENT_HINT=1
# Without it the measure routes (/<domain>/indicadores, /<domain>/fhir) aren't
# registered. The entrypoint replaces it with one compiled against the
# deployment's engine when that engine isn't SQLite (webapi.dbt_manifest).
COPY --from=manifest /app/Transformation /app/Transformation
ENV DBT_MANIFEST=/app/Transformation/target/manifest.json
ENV TRANSFORMATION_DIR=/app/Transformation
RUN chmod +x /app/WebApi/docker-entrypoint.sh
EXPOSE 5000
ENTRYPOINT ["/app/WebApi/docker-entrypoint.sh"]