# =============================================================
#  Default Dockerfile for ENTR Adapter
#  Ships with entr-adapter-core — adapters inherit this unless
#  they provide their own in deploy/Dockerfile (shadow override).
#
#  Build: uv-based Python 3.12, single-stage
#  Port:  8096 (Core–Adapter contract)
# =============================================================

FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

# Install the project into /app
WORKDIR /app

# --- Build-time optimisations --------------------------------
# Compile .pyc files at install time for faster cold starts
ENV UV_COMPILE_BYTECODE=1
# Copy files instead of hard-linking (safer inside containers)
ENV UV_LINK_MODE=copy

# --- Install dependencies first (layer caching) --------------
# Only pyproject.toml + lockfile are needed here, so source
# changes don't invalidate the (expensive) dependency layer.
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,source=uv.lock,target=uv.lock \
    --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
    uv sync --frozen --no-install-project --no-dev

# --- Copy project source and install the project itself ------
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --frozen --no-dev

# --- Runtime PATH --------------------------------------------
# Make virtualenv binaries (uvicorn, python, etc.) available
ENV PATH="/app/.venv/bin:$PATH"

# --- Entrypoint reset ----------------------------------------
# Allow docker-compose CMD / command overrides without
# prepending the default entrypoint
ENTRYPOINT []

# --- Network --------------------------------------------------
EXPOSE 8096

# --- Default command ------------------------------------------
# Runs the adapter's FastAPI app via uvicorn
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8096"]
