# AgentGate as a central Streamable HTTP gateway.
#   docker build -t agentgate .
#   docker run -p 8765:8765 -e UPSTREAM=http://mcp-server:8000/mcp -e SERVER=github agentgate
ARG BASE_IMAGE=python:3.12-slim
FROM ${BASE_IMAGE}

RUN useradd --create-home --uid 10001 agentgate
WORKDIR /app
COPY pyproject.toml README.md LICENSE ./
COPY src ./src
COPY policies ./policies
# Behind a TLS-intercepting proxy, pass its CA as an optional build secret:
#   docker build --secret id=ca_bundle,src=/path/to/ca.pem -t agentgate .
RUN --mount=type=secret,id=ca_bundle,required=false \
    if [ -f /run/secrets/ca_bundle ]; then export PIP_CERT=/run/secrets/ca_bundle; fi; \
    pip install --no-cache-dir ".[http]"

USER agentgate
ENV AGENTGATE_HOME=/home/agentgate/.agentgate \
    AGENTGATE_AUDIT=stderr \
    UPSTREAM="" SERVER="upstream" PORT=8765
EXPOSE 8765
# Audit events go to stderr so `docker logs` / a log shipper (Wazuh, Splunk) can collect them.
CMD ["sh", "-c", "exec agentgate serve --host 0.0.0.0 --port \"$PORT\" --server \"$SERVER\" --upstream \"$UPSTREAM\""]
