FROM python:3.12-slim

WORKDIR /app

# uvicorn[standard] brings the websockets implementation the agent link needs.
RUN pip install --no-cache-dir "fastapi>=0.115,<1" "uvicorn[standard]>=0.30,<1"

# Copy the whole package rather than naming files: the operator's build also
# carries admin.py and admin.html, while a self-hosted build simply does not
# have them and gets a relay with no admin surface.
COPY . /app/relay/

# Unbuffered so container logs appear immediately rather than in blocks.
ENV PYTHONUNBUFFERED=1
EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/health',timeout=4).status==200 else 1)"

CMD ["uvicorn", "relay.server:app", "--host", "0.0.0.0", "--port", "8080"]
