From 07414fd91ccfc2d10aeeb7e2fcd4aba65a8a5d04 Mon Sep 17 00:00:00 2001 From: Michel Thebeau Date: Mon, 3 Oct 2022 08:27:32 -0400 Subject: [PATCH] reduce size of stx-oidc-client image Use Docker multi-stage build to start stx-oidc-client image from 'scratch' after using the upstream go image as builder. Build the stx-oidc-client executable as statically linked. This commit removes the build image and module downloads which are approximately 500MB. Instead of those artifacts take a snapshot of the go version and downloaded file list. Test plan: PASS: build image PASS: sanity on isolated executable PASS: inspect image content/size PASS: application sanity; authenticate and run kubectl command, review logs Story: 2009831 Task: 46463 Change-Id: I7d911a133fa95537b957ef964916fc6e4ca5dcf1 Signed-off-by: Michel Thebeau --- stx-oidc-client/debian/docker/Dockerfile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stx-oidc-client/debian/docker/Dockerfile b/stx-oidc-client/debian/docker/Dockerfile index 1f874d1..c155c1e 100644 --- a/stx-oidc-client/debian/docker/Dockerfile +++ b/stx-oidc-client/debian/docker/Dockerfile @@ -1,8 +1,18 @@ -FROM golang:latest +FROM golang:latest as builder WORKDIR /app ADD . /app/ RUN go mod download -RUN go build -o stx-oidc-client . + +ENV CGO_ENABLED=0 +RUN go build --ldflags '-extldflags "-static"' -o stx-oidc-client . + +RUN go version > go.version.txt +RUN find /go -type f > go.dl.txt + +FROM scratch + +WORKDIR /app +COPY --from=builder /app ./ EXPOSE 5555 CMD ["./stx-oidc-client"]