# SPDX-License-Identifier: Apache-2.0

FROM rust:1.95.0-alpine3.23@sha256:606fd313a0f49743ee2a7bd49a0914bab7deedb12791f3a846a34a4711db7ed2 AS chef
RUN apk add --no-cache musl-dev && cargo install cargo-chef
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json -p aptu-mcp
COPY . .
RUN cargo build --release -p aptu-mcp

FROM gcr.io/distroless/static-debian12:nonroot@sha256:a9329520abc449e3b14d5bc3a6ffae065bdde0f02667fa10880c49b35c109fd1

LABEL org.opencontainers.image.title="aptu-mcp" \
      org.opencontainers.image.description="MCP server for AI-powered GitHub triage and review" \
      org.opencontainers.image.source="https://github.com/clouatre-labs/aptu" \
      org.opencontainers.image.licenses="Apache-2.0" \
      org.opencontainers.image.vendor="Clouatre Labs" \
      io.modelcontextprotocol.server.name="clouatre-labs/aptu-mcp"

COPY --from=builder /app/target/release/aptu-mcp /aptu-mcp

EXPOSE 8080
ENTRYPOINT ["/aptu-mcp"]
CMD ["--transport", "http", "--host", "0.0.0.0", "--port", "8080"]
