# MCP Server Dockerfile
# Generated by Agent Builder Platform (template 1.1.0)
#
# Built on the platform's MCP server base image: Chainguard Python with the
# packages in requirements.txt already installed, a non-root user (1000) and
# no pip. This image adds only the server's own files.
#
#   docker build -t <server>:<version> .
#   docker build --build-arg BASE_IMAGE=<local base image> -t ... .
ARG BASE_IMAGE=kyndryl.jfrog.io/kc-ai-agent-factory-docker-local/mcp-server-base:1.1.0

# Stage 1: the server's extra Python packages, if requirements.txt lists any.
# The base image's build image (<base image>-build: the base image plus uv) installs
# them with its vendor-install script: only the packages added go on to
# /vendor, and one that would change a package the base image already has stops
# the build. uv never reaches the server's image.
FROM ${BASE_IMAGE}-build AS vendor
COPY requirements.txt constraints.txt /tmp/
RUN vendor-install /tmp/requirements.txt /vendor /tmp/constraints.txt

# Stage 2: the server: the base image, its extra packages and its files.
FROM ${BASE_IMAGE}

LABEL maintainer="Agent Builder Platform"
LABEL description="Read-only sample data for Agentic Landing Zone discovery (Meridian Retail Group) - scope, estate scans, CMDB and ITSM, inventory, schemas, dependencies, network and the run's MCP call log."
LABEL version="0.2.2"
LABEL server.id="alz-discovery-sample"
LABEL template.version="1.1.0"

COPY --from=vendor /vendor /app/vendor/
COPY server.py mcp_connection.py /app/

# Environment
# The ConfigMap's SERVER_PORT overrides this, so the container, Service and probes agree
ENV SERVER_PORT=8110
ENV LOG_LEVEL=INFO
ENV LOG_FORMAT=json

# Expose port
EXPOSE 8110

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "import os, urllib.request; urllib.request.urlopen('http://localhost:%s/health' % (os.getenv('MCP_SERVER_PORT') or os.getenv('SERVER_PORT') or '8110'))" || exit 1

# Run the server
CMD ["python", "server.py"]
