Files
WebApi/docker-entrypoint.sh
edgar 7d06f9db9d The cycle builds the cohorts dbt defines; models' moved modules
The `cohorts` and `estimate` steps take the project's cohorts from dbt's manifest (`cohort_urls`) and build each one
with models' `build_of` over dbt's queries, instead of the Python-frame TOMLs in models/cohorts, which are gone; without
a manifest a project has no cohort steps. The recruitment window and cut-off are dbt's vars. The live estimator reads
cin2_logistic through `Scenario` and `KitBuild`, and governance imports `models.reports.experiment`, where models now
keeps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
2026-11-20 20:18:00 -06:00

64 lines
2.6 KiB
Bash

#!/bin/sh
set -e
# The notebook runner shares the image but runs with no network, a read-only
# system and only the jobs folder (models.reports.notebook_jobs): it never touches /data.
if [ "$1" = "notebooks" ]; then
exec /app/WebApi/.venv/bin/python -m models notebooks serve
fi
mkdir -p /data
# SQLite won't create a missing parent directory for its database file.
for url in "$CACU_DATABASE_URL" "$CAMA_DATABASE_URL" "$TEA_DATABASE_URL" "$GOVERNANCE_DATABASE_URL"; do
case "$url" in
sqlite:///*) mkdir -p "$(dirname "${url#sqlite:///}")" ;;
esac
done
cd /app/WebApi
# dbt's manifest for the deployment's engine: the image's is SQLite's; on
# another engine it's compiled now, against the configured databases, into
# /data (webapi.dbt_manifest prints the path to use, or nothing to keep the
# image's).
if compiled="$(uv run --no-sync python -m webapi.dbt_manifest)"; then
[ -n "$compiled" ] && export DBT_MANIFEST="$compiled"
else
echo "dbt manifest: compilation failed; the measure routes will stay unregistered" >&2
fi
# The live indicator worker (webapi.recomputation) shares the image; the
# API container runs the migrations, so the worker starts after it.
if [ "$1" = "indicadores" ]; then
exec uv run --no-sync python -m webapi.recomputation
fi
# One-shot training of the CaCu model on the loaded data (compose profile
# `entrenar`): the trained version goes into production and the worker's next
# cycle estimates with it. `--source dbt` (dbt's cohort, not the kit's numbered
# builds) is required: a PROD run needs its cohort build named (ML-03), and
# --export --source dbt is the only way to do that without knowing the build
# number ahead of time; it also makes the promotion gate's cohort-link check
# portable (tag-based, no live lookup of a local build row), unlike the kit's.
if [ "$1" = "entrenar" ]; then
exec uv run --no-sync python -m models run cacu cin2_logistic --export --source dbt --manifest "$DBT_MANIFEST" \
--environment prod --train --promote
fi
# --no-sync: the environment was synced at build time; syncing at startup
# would try to reach the package index (and pull dev deps).
for domain in cacu cama tea governance; do
uv run --no-sync alembic -c "/app/Persistance/persistance/$domain/alembic.ini" upgrade head
done
PORT="${PORT:-5000}"
# gunicorn, not Flask's development server. Long timeout: OCR over a
# multi-page scanned PDF runs inside a single request.
exec uv run --no-sync gunicorn \
--bind "0.0.0.0:${PORT}" \
--workers "${WEBAPI_WORKERS:-2}" \
--timeout "${WEBAPI_TIMEOUT:-600}" \
--access-logfile - \
"webapi:create_app()"