Presets / Go 1.22 → binaire statique (scratch)
preset Go

Go 1.22 → binaire statique (scratch)

dockerfile  ·  Go

Build statique CGO_ENABLED=0 puis image finale 'scratch' ultra-minimale.

go scratch static minimal
FROM golang:1.22-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags='-s -w' -o /out/app ./cmd/app

FROM scratch
COPY --from=build /out/app /app
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
EXPOSE 8080
ENTRYPOINT ["/app"]