# syntax=docker/dockerfile:1
# Meeting-api (v0.12 P4) — the unified modular-monolith control plane (lifecycle · bot_spawn ·
# collector · recordings). The entrypoint ALSO starts the background loops (segment consumer ·
# webhook retry-drain · scheduler tick / join-retry) alongside the HTTP app via the lifespan.
#
# Build context: the v0.12 carve root (compose `context: ../..`). Wider than the other three
# services because meeting_api validates AT THE SEAM (P8): it loads the sealed invocation.v1 /
# lifecycle.v1 / webhook.v1 / runtime.v1 / schedule.v1 schemas BY PATH at import (walking up from
# the module to find `meetings/contracts/...` and `runtime/contracts/...`), so those frozen
# contract files must be vendored into the image alongside src/.
FROM python:3.12-slim@sha256:05cda9777409a9c3ffddd94a4c476b79f0769a0b4857f0c7ed9226b6800b0d6f

# Finalized WebM duration/cues; stream-copy only, no re-encoding.
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*

# uv via PyPI (ghcr.io is unreachable in this build env) — pinned for deterministic resolves.
RUN pip install --no-cache-dir uv==0.11.33

ENV UV_LINK_MODE=copy \
    UV_PROJECT_ENVIRONMENT=/opt/venv \
    PYTHONUNBUFFERED=1 \
    PYTHONPATH=/app/src \
    PATH=/opt/venv/bin:$PATH

WORKDIR /app

COPY core/meetings/services/meeting-api/pyproject.toml core/meetings/services/meeting-api/uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen --no-install-project --no-dev --group production

# The shipped source (src/ on PYTHONPATH).
COPY core/meetings/services/meeting-api/src ./src

# The sealed contracts loaded BY PATH at import. Sources moved under core/ (the domains now live in
# core/); the in-image layout is UNCHANGED — placed under /app/ so the module walk-up
# (Path(__file__).resolve().parents → .../src/meeting_api/... → /app) still resolves
# `meetings/contracts/...` and `runtime/contracts/...`.
COPY core/meetings/contracts/invocation.v1/invocation.schema.json   ./meetings/contracts/invocation.v1/invocation.schema.json
COPY core/meetings/contracts/lifecycle.v1/lifecycle.schema.json     ./meetings/contracts/lifecycle.v1/lifecycle.schema.json
COPY core/meetings/contracts/webhook.v1/webhook.schema.json         ./meetings/contracts/webhook.v1/webhook.schema.json
COPY core/meetings/contracts/transcription-language.v1/catalog.json ./meetings/contracts/transcription-language.v1/catalog.json
COPY core/runtime/contracts/runtime.v1/runtime.schema.json          ./runtime/contracts/runtime.v1/runtime.schema.json
COPY core/runtime/contracts/schedule.v1/schedule.schema.json        ./runtime/contracts/schedule.v1/schedule.schema.json
# The meetings domain's route manifest: route_scopes.py reads, per route, the key scopes of the
# edge rows that reach it, from the same walk-up.
COPY core/meetings/routes.v1.json                                   ./meetings/routes.v1.json
# The meetings domain's MCP tool manifest, served at /.well-known/mcp-tools.json (same walk-up).
COPY core/meetings/mcp.tools.v1.json                                ./meetings/mcp.tools.v1.json

# An unprivileged user runs the service: it writes nothing outside /tmp, and reads its mounted keys
# through the group the deploy surfaces give it (compose's key one-shot, the chart's fsGroup).
RUN groupadd --system --gid 10001 vexa \
 && useradd --system --uid 10001 --gid 10001 --no-create-home --shell /usr/sbin/nologin vexa
USER 10001:10001

EXPOSE 8080
# python -m meeting_api → create_app(real adapters) + the lifespan-driven background loops.
CMD ["python", "-m", "meeting_api"]
