FROM golang:1.22-bookworm AS builder

ENV GOTOOLCHAIN=auto

# Pin to a specific release tag
ARG VERSION=v2.10.2

WORKDIR /app
RUN git clone --depth 1 --branch ${VERSION} https://github.com/sigbit/mcp-auth-proxy .
RUN go mod download

ARG TARGETARCH
ARG TARGETOS
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
    go build -trimpath -ldflags "-w -s" -o /app/bin/mcp-auth-proxy .

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/bin/mcp-auth-proxy /usr/local/bin/mcp-auth-proxy
ENV DATA_PATH=/data

ENTRYPOINT ["/usr/local/bin/mcp-auth-proxy"]
