From 2895e12476368f9b494a37191cf362a88632c383 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 18 Jan 2024 07:45:35 -0600 Subject: [PATCH] Build a static executable, from scratch container This reduces the size of the container image from 150 MB to 10 MB. --- Containerfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Containerfile b/Containerfile index f627193..76ae3a9 100644 --- a/Containerfile +++ b/Containerfile @@ -1,12 +1,17 @@ -FROM docker.io/library/golang:1.21 AS build +FROM docker.io/library/golang:1.21-alpine AS build + +RUN --mount=type=cache,target=/var/cache \ + apk add \ + git \ + && : RUN go install github.com/lucab/local_exporter@latest -FROM registry.fedoraproject.org/fedora-minimal:38 +FROM scratch -COPY --from=build /go/bin/local_exporter /usr/local/bin/local_exporter +COPY --from=build /go/bin/local_exporter /local_exporter -ENTRYPOINT ["local_exporter"] +ENTRYPOINT ["/local_exporter"] USER 252:252