From 149616321435ecce2ce1ce394863d33dc0a5cb5c Mon Sep 17 00:00:00 2001 From: Mitchell Nielsen Date: Thu, 28 Jan 2021 12:37:23 -0500 Subject: [PATCH] Reduce size of operator base image - Uses the multi-stage pattern so the final stage is smaller (using the alpine variant) and copies in only what is needed from the dependencies stage. - Reduces the image size from roughly 1.19GB to roughly 654MB. --- Dockerfile.gitlab-operator-build-base | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Dockerfile.gitlab-operator-build-base b/Dockerfile.gitlab-operator-build-base index dbd14a0..00d9b8a 100644 --- a/Dockerfile.gitlab-operator-build-base +++ b/Dockerfile.gitlab-operator-build-base @@ -1,7 +1,4 @@ -FROM golang:1.14 - -LABEL maintainer="GitLab Distribution Team" \ - description="Build base image for the GitLab Operator project." +FROM golang:1.14 AS dependencies ARG KUBEBUILDER_VERSION=2.3.1 ARG YQ_VERSION=2.4.1 @@ -16,3 +13,14 @@ RUN go get -u \ RUN curl --retry 6 -LsO https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 \ && chmod +x yq_linux_amd64 \ && mv yq_linux_amd64 /usr/local/bin/yq + + +FROM golang:1.14-alpine + +LABEL maintainer="GitLab Distribution Team" \ + description="Build base image for the GitLab Operator project." + +COPY --from=dependencies /go /go +COPY --from=dependencies /usr/local/kubebuilder /usr/local/kubebuilder +COPY --from=dependencies /usr/local/bin/ /usr/local/bin/ +COPY --from=dependencies /usr/local/bin/yq /usr/local/bin/yq