# syntax=docker/dockerfile:1.7

# ---------- build ----------
FROM golang:1.23-alpine3.21 AS build

ENV CGO_ENABLED=0 \
    GOOS=linux \
    GOFLAGS="-trimpath"

WORKDIR /src

COPY services/testagent-transform/go.mod ./services/testagent-transform/
RUN --mount=type=cache,target=/root/.cache/go-build \
    --mount=type=cache,target=/go/pkg/mod \
    cd services/testagent-transform && go mod download

COPY services/testagent-transform/ ./services/testagent-transform/

WORKDIR /src/services/testagent-transform
RUN --mount=type=cache,target=/root/.cache/go-build \
    --mount=type=cache,target=/go/pkg/mod \
    go vet ./... && \
    go test ./... && \
    go build -ldflags="-s -w" -o /out/testagent-transform ./cmd/testagent-transform

# ---------- runtime ----------
# Distroless static+nonroot. The projected ServiceAccount token lives on
# a tmpfs volume mounted by kubelet into /var/run/secrets/tokens/trust-api,
# so the container only needs read access to that path at runtime.
FROM gcr.io/distroless/static-debian12:nonroot

COPY --from=build /out/testagent-transform /testagent-transform

USER 65532:65532
ENTRYPOINT ["/testagent-transform"]
