diff --git a/Dockerfile.gitlab-operator-build-base b/Dockerfile.gitlab-operator-build-base index 8820901..82e4702 100644 --- a/Dockerfile.gitlab-operator-build-base +++ b/Dockerfile.gitlab-operator-build-base @@ -1,4 +1,28 @@ -FROM golang:1.14 +ARG GOLANG_VERSION=1.16 + +## Kustomize +FROM golang:${GOLANG_VERSION}-alpine as kustomize + +ARG KUSTOMIZE_VERSION=3.8.10 +ENV GOPROXY="https://proxy.golang.org/" + +RUN apk add --no-cache gcc musl-dev +RUN mkdir /src && cd /src; \ + go mod init tmp && \ + go get sigs.k8s.io/kustomize/kustomize/v3@v${KUSTOMIZE_VERSION} + +## Controller-gen +FROM golang:${GOLANG_VERSION}-alpine as controller-gen + +ARG CONTROLLER_GEN_VERSION=0.3.0 +ENV GOPROXY="https://proxy.golang.org/" + +RUN mkdir /src && cd /src; \ + go mod init tmp \ + && go get sigs.k8s.io/controller-tools/cmd/controller-gen@v${CONTROLLER_GEN_VERSION} + +## Build +FROM golang:${GOLANG_VERSION}-alpine as build LABEL maintainer="GitLab Distribution Team" \ description="Build base image for the GitLab Operator project." @@ -7,17 +31,33 @@ ARG KUBEBUILDER_VERSION=2.3.1 ARG YQ_VERSION=4.7.0 ARG HELM_VERSION=3.5.2 +RUN apk add --no-cache podman curl make gcc musl-dev git RUN go get -u \ github.com/onsi/ginkgo/ginkgo \ - golang.org/x/lint/golint \ - && curl --retry 6 -Ls https://go.kubebuilder.io/dl/${KUBEBUILDER_VERSION}/linux/amd64 | tar -xz -C /tmp/ \ - && mv /tmp/kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64 /usr/local/kubebuilder \ - && ln -sfv /usr/local/kubebuilder/bin/* /usr/local/bin \ - && curl --retry 6 -LsO https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64 \ - && chmod +x yq_linux_amd64 \ - && mv yq_linux_amd64 /usr/local/bin/yq \ - && curl --retry 6 -Ls "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar -xz -C /tmp/ \ - && chmod +x /tmp/linux-amd64/helm \ - && mv /tmp/linux-amd64/helm /usr/local/bin/helm \ - && rm -rf /var/lib/apt/lists/* /tmp/* + golang.org/x/lint/golint +# Kubebuilder +RUN curl --retry 6 -Ls https://go.kubebuilder.io/dl/${KUBEBUILDER_VERSION}/linux/amd64 | tar -xz -C /tmp/ \ + && mv /tmp/kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64 /usr/local/kubebuilder \ + && ln -sfv /usr/local/kubebuilder/bin/* /usr/local/bin + +# Yq +RUN curl --retry 6 -LsO https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64 \ + && chmod +x yq_linux_amd64 \ + && mv yq_linux_amd64 /usr/local/bin/yq + +# Helm +RUN curl --retry 6 -Ls "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar -xz -C /tmp/ \ + && chmod +x /tmp/linux-amd64/helm \ + && mv /tmp/linux-amd64/helm /usr/local/bin/helm + +# Kustomize +COPY --from=kustomize /go/bin/kustomize /usr/local/bin/kustomize +# Controller-gen +COPY --from=controller-gen /go/bin/controller-gen /usr/local/bin/controller-gen + +## Final image +FROM golang:${GOLANG_VERSION}-alpine +LABEL maintainer="GitLab Distribution Team" \ + description="Build base image for the GitLab Operator project." +COPY --from=build / / \ No newline at end of file