# {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

# Stages the correct-platform libonnxruntime.so once so the build and
# final stages don't each re-download it — the blessed path per
# v5-implementation-plan.md's open decision #2 ("bundle it into the
# Dockerfile's build stage as the default, matching every other target's
# 'Docker is the blessed path' precedent"). See README.md for the
# bare-metal/non-Docker fallback.
FROM debian:bookworm-slim AS onnxruntime
ARG ONNXRUNTIME_VERSION=1.27.0
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
    && curl -sL -o /tmp/onnxruntime.tgz \
        "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz" \
    && mkdir -p /onnxruntime \
    && tar -xzf /tmp/onnxruntime.tgz -C /onnxruntime --strip-components=1 \
    && rm /tmp/onnxruntime.tgz

FROM golang:1.26-bookworm AS build
WORKDIR /src
COPY --from=onnxruntime /onnxruntime/lib/libonnxruntime.so* /usr/lib/
COPY go.mod ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=1 go build -o /app/{{ project_name }} ./cmd/{{ project_name }}
RUN CGO_ENABLED=1 go build -o /app/populate-embeddings ./cmd/populate-embeddings

FROM debian:bookworm-slim AS final
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
    && rm -rf /var/lib/apt/lists/*
COPY --from=onnxruntime /onnxruntime/lib/libonnxruntime.so* /usr/lib/
COPY --from=build /app/{{ project_name }} ./{{ project_name }}
COPY --from=build /app/populate-embeddings ./populate-embeddings
COPY mcp_store.db ./mcp_store.db

# mcp_store.db leaves the generator with an empty semantic_endpoints table
# (vectors are computed here, not by mcpify itself — see the plan's
# embeddings decision), and the sibling chromem-go collection this target
# actually queries (v5-implementation-plan.md's deliberate divergence,
# open decision #3) doesn't exist yet either, so both must be populated
# before the image is usable.
RUN ./populate-embeddings

HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
    CMD ["./{{ project_name }}", "test-connection"]

ENTRYPOINT ["./{{ project_name }}"]
