# Test image for nodepal-mcp. Build the test target, then run pytest + ruff with the folder mounted:
#   docker build -q --target test -t nodepal-mcp-test .
#   docker run --rm -v "$(cd .. && pwd -W):/portal" -w /portal/mcp nodepal-mcp-test sh -c "python -m pytest -q && ruff check ."
# (the whole portal is mounted: tests/test_parity.py reads backend/tests/data/api_routes.json)
FROM python:3.12-slim AS test
WORKDIR /app
COPY pyproject.toml README.md ./
COPY src ./src
RUN pip install --no-cache-dir -e ".[dev]"
CMD ["sh", "-c", "python -m pytest -q && ruff check ."]

# Stdio image (optional): stdio server, token passed through the environment.
FROM python:3.12-slim AS stdio
WORKDIR /app
COPY pyproject.toml README.md ./
COPY src ./src
RUN pip install --no-cache-dir .
ENTRYPOINT ["nodepal-mcp"]

# Remote endpoint (Streamable HTTP at /mcp on 8080), the image the portal stack runs as service `mcp`.
# Build context = the mcp/ folder (scripts/release-local.sh archives it). Not root; no port is published.
FROM python:3.12-slim AS runner
WORKDIR /app
COPY pyproject.toml README.md ./
COPY src ./src
RUN pip install --no-cache-dir . && useradd --system --uid 10001 --no-create-home nodepal
USER 10001
ENV NODEPAL_MCP_MODE=http PYTHONUNBUFFERED=1
EXPOSE 8080
HEALTHCHECK --interval=15s --timeout=4s --start-period=10s --retries=3 \
  CMD ["python", "-c", "import urllib.request as u; u.urlopen('http://127.0.0.1:8080/healthz', timeout=3)"]
ENTRYPOINT ["nodepal-mcp"]
