ARG GO_VERSION=1.24

FROM golang:${GO_VERSION}-bookworm AS build
WORKDIR /src

COPY go.mod ./
RUN go mod download

COPY . .

ARG TARGETOS=linux
ARG TARGETARCH=amd64
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
    go build -trimpath -ldflags="-s -w" -o /out/authproxy ./cmd/authproxy

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/authproxy /authproxy

EXPOSE 8080
USER nonroot:nonroot

ENTRYPOINT ["/authproxy"]
