# Single image for both the OSINT scan (main.py) and opt-out automation (bin/removal.py).
# Uses the official Playwright base which bundles Chromium + all system deps.
FROM mcr.microsoft.com/playwright/python:v1.44.0-jammy

# Extra system dependencies needed by the OSINT tools
# zlib1g-dev + libjpeg-dev are needed by Pillow when building from source
RUN apt-get update && apt-get install -y --no-install-recommends \
    git curl ca-certificates build-essential \
    zlib1g-dev libjpeg-dev \
    && rm -rf /var/lib/apt/lists/*

# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.cargo/bin:/root/.local/bin:$PATH"

# Pin uv to Python 3.12 — has pre-built Pillow wheels on linux/aarch64.
# The Playwright jammy base image ships Python 3.10 (Ubuntu 22.04 default),
# which is below our requires-python floor; uv downloads its own 3.12 instead.
ENV UV_PYTHON=3.12

WORKDIR /app

# Install Python deps first, from the lockfile, for a reproducible + cacheable
# layer. --no-install-project syncs only dependencies (the local package itself
# needs the source + LICENSE, copied later), so this layer is invalidated only
# when pyproject/uv.lock change.
COPY pyproject.toml uv.lock ./
RUN uv sync --no-dev --frozen --no-install-project

# Clone Blackbird (not on PyPI — baked into image).
# Pinned to a specific commit for reproducible + supply-chain-auditable builds:
# an unpinned `--depth 1` clone tracks a moving HEAD. Bump BLACKBIRD_REF
# deliberately after reviewing upstream changes.
ARG BLACKBIRD_REF=b45505080ef51bb3ef52dc29879ee6bef31e5b94
RUN git clone https://github.com/p1ngul1n0/blackbird /opt/blackbird \
    && git -C /opt/blackbird checkout "${BLACKBIRD_REF}" \
    && rm -rf /opt/blackbird/.git

# Copy project source, then install the local package itself (LICENSE + source
# are now present) from the same locked environment.
COPY . .
RUN uv sync --no-dev --frozen

# Register the Chromium bundled in the base image (needs the synced project env).
RUN uv run --no-dev playwright install chromium

# GHunt credentials mount point
RUN mkdir -p /root/.malfrats/ghunt

# Patch ghunt source for Google API response changes (container key + data[24] bounds)
RUN python3 bin/patch-ghunt.py

# Default entrypoint: OSINT scan. Run the built venv's python directly rather
# than `uv run` — the image is already synced, so this avoids a re-sync (and
# a dev-dep download) on every container start.
ENTRYPOINT ["/app/.venv/bin/python", "-m", "eidolon.main"]
