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.
This commit is contained in:
Mitchell Nielsen 2021-01-28 12:37:23 -05:00
parent 0c9578d59b
commit 1496163214

View file

@ -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