# Stage 1: Builder
FROM python:3.11-slim AS builder

WORKDIR /build

RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

COPY requirements.txt .
COPY setup.py pyproject.toml MANIFEST.in README.md LICENSE ./

RUN pip install --no-cache-dir -r requirements.txt

COPY kosty/ ./kosty/

# MANIFEST.in is what ships plugins.sha256 (the plugin integrity manifest);
# without it the image had no manifest and strict_plugins refused every check.
RUN pip install --no-cache-dir . && \
    python -c "import os, kosty; p = os.path.join(os.path.dirname(kosty.__file__), 'providers', 'aws', 'services', 'plugins.sha256'); assert os.path.exists(p), 'plugins.sha256 missing from the image'"

# Stage 2: Runner (Distroless)
FROM gcr.io/distroless/python3-debian12:nonroot


COPY --from=builder --chown=nonroot:nonroot /opt/venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH" \
    PYTHONPATH="/opt/venv/lib/python3.11/site-packages" \
    PYTHONUNBUFFERED=1

WORKDIR /home/nonroot

USER nonroot

ENTRYPOINT ["python3", "-m", "kosty.cli"]
