# Substrate addressing-service replica (Phase 1 — read-only, homebase).
#
# Per operator directive 2026-05-27: chain resilience as load-bearing GTM
# property. addressing.arqera.io is single-region (GKE) today; this image
# runs on homebase k3s as addressing-eu.arqera.io.
#
# Image is intentionally small: a FastAPI/uvicorn app that pulls from
# canonical every 60s and serves the addressing read surface. Writes 503.
FROM python:3.12-slim

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

WORKDIR /app

RUN apt-get update \
    && apt-get install -y --no-install-recommends curl ca-certificates \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir \
    "fastapi==0.115.5" \
    "uvicorn[standard]==0.32.1" \
    "httpx==0.27.2"

COPY app.py /app/app.py

# Cache directory must be writable; configmap-mounted env may override path.
RUN mkdir -p /var/cache/substrate-replica/bodies

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -fsS http://localhost:8080/healthz || exit 1

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080", "--log-level", "info"]
