From 6e97c07e07daee3844dd37dd740b3462bbbd0436 Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Tue, 8 Aug 2023 16:20:15 +0200 Subject: [PATCH] use distroless base image Signed-off-by: Matthias Bertschy --- build/Dockerfile | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 074d48f..25887d7 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,11 +1,20 @@ -FROM golang:1.19 +FROM --platform=$BUILDPLATFORM golang:1.20-bullseye as builder ARG BUILD_VERSION -WORKDIR /app/ -COPY . ./ -ENV CGO_ENABLED=0 -RUN go get ./... -RUN go build -o kube-host-sensor --ldflags "-w -s -X main.BuildVersion=$BUILD_VERSION" - -FROM alpine -COPY --from=0 /app/kube-host-sensor /. -ENTRYPOINT [ "./kube-host-sensor" ] +ENV GO111MODULE=on CGO_ENABLED=0 +WORKDIR /work +ARG TARGETOS TARGETARCH + +RUN --mount=target=. \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/kube-host-sensor --ldflags "-w -s -X main.BuildVersion=$BUILD_VERSION" . + +FROM gcr.io/distroless/static-debian11:latest + +COPY --from=builder /out/kube-host-sensor /usr/bin/kube-host-sensor + +ARG image_version +ENV RELEASE=$image_version + +WORKDIR /root +ENTRYPOINT ["kube-host-sensor"]