FROM docker.io/library/python:3.12-slim

# ca-certificates: mitmproxy verifies upstream TLS against the system store.
# mitmproxy pinned to a working major; the image is built once by install.sh.
RUN apt-get update \
    && apt-get install -y --no-install-recommends ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && pip install --no-cache-dir "mitmproxy>=11,<12"

COPY egress_policy.py /opt/umwelt/egress_policy.py
COPY egress_addon.py /opt/umwelt/egress_addon.py
COPY egress_socks5.py /opt/umwelt/egress_socks5.py
COPY egress-gw/entrypoint.sh /opt/umwelt/entrypoint.sh
RUN chmod +x /opt/umwelt/entrypoint.sh

# run.py launches the gateway --read-only with a /tmp tmpfs; only /audit.jsonl
# (bind) is writable. Ports are container-internal constants, not host binds.
ENV PYTHONPATH=/opt/umwelt \
    PYTHONDONTWRITEBYTECODE=1 \
    EGRESS_POLICY_FILE=/policy.json \
    EGRESS_AUDIT_FILE=/audit.jsonl \
    EGRESS_MITM_PORT=8080 \
    EGRESS_SOCKS_PORT=1080

ENTRYPOINT ["/opt/umwelt/entrypoint.sh"]
