# Stage 1: compile with Go on the machine's own architecture, output for the target one
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS build
ARG TARGETOS
ARG TARGETARCH
ARG VERSION=dev
WORKDIR /src
COPY go.mod main.go ./
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
    go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/app .

# Stage 2: only the program, nothing else
FROM scratch
COPY --from=build /out/app /app
USER 65534:65534
EXPOSE 8080
ENTRYPOINT ["/app"]
