ARG APP_VERSION="develop"
ARG VERSION_PKG="github.com/reportportal/reportportal-mcp-server/internal/config"

FROM golang:1.25.0 AS build
# allow this step access to build arg
ARG APP_VERSION
ARG VERSION_PKG
# Set the working directory
WORKDIR /build

RUN go env -w GOMODCACHE=/root/.cache/go-build

# Install dependencies
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build go mod download

COPY . ./
# Build the server
RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags="-s -w -X ${VERSION_PKG}.Version=${APP_VERSION} -X ${VERSION_PKG}.Commit=$(git rev-parse HEAD) -X ${VERSION_PKG}.Date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
    -o reportportal-mcp-server cmd/reportportal-mcp-server/main.go

# Make a stage to run the app
FROM gcr.io/distroless/base-debian12
# Set the working directory
WORKDIR /server
# Copy the binary from the build stage
COPY --from=build /build/reportportal-mcp-server .

# Expose default HTTP port (can be overridden by MCP_SERVER_PORT)
EXPOSE 8080

# Run the server - will read MCP_MODE environment variable
ENTRYPOINT ["./reportportal-mcp-server"]