From b9f3f410e7e11afe405404145ebc177960a2fcc2 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 5 Apr 2023 16:15:35 -0400 Subject: [PATCH 1/3] Make build-image arm64 compatible Signed-off-by: Tiger Kaovilai --- hack/build-image/Dockerfile | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/hack/build-image/Dockerfile b/hack/build-image/Dockerfile index 7d00e1b24..9f3c6ca82 100644 --- a/hack/build-image/Dockerfile +++ b/hack/build-image/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=linux/amd64 golang:1.21-bookworm +FROM --platform=$TARGETPLATFORM golang:1.21-bookworm ARG GOPROXY @@ -21,12 +21,12 @@ ENV GO111MODULE=on ENV GOPROXY=${GOPROXY} # kubebuilder test bundle is separated from kubebuilder. Need to setup it for CI test. -RUN curl -sSLo envtest-bins.tar.gz https://go.kubebuilder.io/test-tools/1.22.1/linux/amd64 && \ +RUN curl -sSLo envtest-bins.tar.gz https://go.kubebuilder.io/test-tools/1.22.1/linux/$(go env GOARCH) && \ mkdir /usr/local/kubebuilder && \ tar -C /usr/local/kubebuilder --strip-components=1 -zvxf envtest-bins.tar.gz -RUN wget --quiet https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.2.0/kubebuilder_linux_amd64 && \ - mv kubebuilder_linux_amd64 /usr/local/kubebuilder/bin/kubebuilder && \ +RUN wget --quiet https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.2.0/kubebuilder_linux_$(go env GOARCH) && \ + mv kubebuilder_linux_$(go env GOARCH) /usr/local/kubebuilder/bin/kubebuilder && \ chmod +x /usr/local/kubebuilder/bin/kubebuilder # get controller-tools @@ -39,19 +39,30 @@ RUN go install golang.org/x/tools/cmd/goimports@11e9d9cc0042e6bd10337d4d2c3e5d92 # get protoc compiler and golang plugin WORKDIR /root RUN apt-get update && apt-get install -y unzip -RUN wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \ - unzip protoc-25.2-linux-x86_64.zip && \ +RUN if [ "$(go env GOARCH)" = "arm64" ] ; then \ + wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-aarch_64.zip && \ + unzip protoc-25.2-linux-aarch_64.zip; \ + else \ + wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \ + unzip protoc-25.2-linux-x86_64.zip; \ + fi && \ + rm *.zip && \ mv bin/protoc /usr/bin/protoc && \ mv include/google /usr/include && \ - chmod a+x /usr/include/google && \ - chmod a+x /usr/include/google/protobuf && \ + chmod a+x /usr/include/google && \ + chmod a+x /usr/include/google/protobuf && \ chmod a+r -R /usr/include/google && \ chmod +x /usr/bin/protoc RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.32.0 # get goreleaser -RUN wget --quiet https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_x86_64.tar.gz && \ - tar xvf goreleaser_Linux_x86_64.tar.gz && \ +RUN if [ "$(go env GOARCH)" = "arm64" ] ; then \ + wget --quiet "https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_arm64.tar.gz" && \ + tar xvf goreleaser_Linux_arm64.tar.gz; \ + else \ + wget --quiet "https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_x86_64.tar.gz" && \ + tar xvf goreleaser_Linux_x86_64.tar.gz; \ + fi && \ mv goreleaser /usr/bin/goreleaser && \ chmod +x /usr/bin/goreleaser @@ -59,6 +70,6 @@ RUN wget --quiet https://github.com/goreleaser/goreleaser/releases/download/v1.1 RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 # install kubectl -RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl +RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/$(go env GOARCH)/kubectl RUN chmod +x ./kubectl RUN mv ./kubectl /usr/local/bin From 5adb7d0def8250d128fb5b5920c61414fb4ae21d Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 5 Feb 2024 22:24:57 -0500 Subject: [PATCH 2/3] Make arch more flexible Signed-off-by: Tiger Kaovilai --- hack/build-image/Dockerfile | 46 +++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/hack/build-image/Dockerfile b/hack/build-image/Dockerfile index 9f3c6ca82..5818271c7 100644 --- a/hack/build-image/Dockerfile +++ b/hack/build-image/Dockerfile @@ -39,13 +39,27 @@ RUN go install golang.org/x/tools/cmd/goimports@11e9d9cc0042e6bd10337d4d2c3e5d92 # get protoc compiler and golang plugin WORKDIR /root RUN apt-get update && apt-get install -y unzip -RUN if [ "$(go env GOARCH)" = "arm64" ] ; then \ - wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-aarch_64.zip && \ - unzip protoc-25.2-linux-aarch_64.zip; \ +# protobuf uses bazel cpunames except following +# if cpu == "systemz": +# cpu = "s390_64" +# elif cpu == "aarch64": +# cpu = "aarch_64" +# elif cpu == "ppc64": +# cpu = "ppcle_64" +# snippet from: https://github.com/protocolbuffers/protobuf/blob/d445953603e66eb8992a39b4e10fcafec8501f24/protobuf_release.bzl#L18-L24 +# cpu names: https://github.com/bazelbuild/platforms/blob/main/cpu/BUILD +RUN ARCH=$(go env GOARCH) && \ + if [ "$ARCH" = "s390x" ] ; then \ + ARCH="s390_64"; \ + elif [ "$ARCH" = "arm64" ] ; then \ + ARCH="aarch_64"; \ + elif [ "$ARCH" = "ppc64" ] ; then \ + ARCH="ppcle_64"; \ else \ - wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \ - unzip protoc-25.2-linux-x86_64.zip; \ - fi && \ + ARCH=$(uname -m); \ + fi && echo "ARCH=$ARCH" && \ + wget --quiet https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-$ARCH.zip && \ + unzip protoc-25.2-linux-$ARCH.zip; \ rm *.zip && \ mv bin/protoc /usr/bin/protoc && \ mv include/google /usr/include && \ @@ -56,13 +70,21 @@ RUN if [ "$(go env GOARCH)" = "arm64" ] ; then \ RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.32.0 # get goreleaser -RUN if [ "$(go env GOARCH)" = "arm64" ] ; then \ - wget --quiet "https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_arm64.tar.gz" && \ - tar xvf goreleaser_Linux_arm64.tar.gz; \ - else \ - wget --quiet "https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_x86_64.tar.gz" && \ - tar xvf goreleaser_Linux_x86_64.tar.gz; \ +# goreleaser name template per arch is basically goarch except for amd64 and 386 https://github.com/goreleaser/goreleaser/blob/ec8819a95c5527fae65e5cb41673f5bbc3245fda/.goreleaser.yaml#L167C1-L173C42 +# {{- .ProjectName }}_ +# {{- title .Os }}_ +# {{- if eq .Arch "amd64" }}x86_64 +# {{- else if eq .Arch "386" }}i386 +# {{- else }}{{ .Arch }}{{ end }} +# {{- if .Arm }}v{{ .Arm }}{{ end -}} +RUN ARCH=$(go env GOARCH) && \ + if [ "$ARCH" = "amd64" ] ; then \ + ARCH="x86_64"; \ + elif [ "$ARCH" = "386" ] ; then \ + ARCH="i386"; \ fi && \ + wget --quiet "https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_$ARCH.tar.gz" && \ + tar xvf goreleaser_Linux_$ARCH.tar.gz; \ mv goreleaser /usr/bin/goreleaser && \ chmod +x /usr/bin/goreleaser From 2375f78d0fe02488277e7423eb55b0eca5c0c7c1 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Mon, 5 Feb 2024 23:31:56 -0500 Subject: [PATCH 3/3] ppc64le fix for protocolbuffers Signed-off-by: Tiger Kaovilai --- hack/build-image/Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hack/build-image/Dockerfile b/hack/build-image/Dockerfile index 5818271c7..7165f9370 100644 --- a/hack/build-image/Dockerfile +++ b/hack/build-image/Dockerfile @@ -53,6 +53,8 @@ RUN ARCH=$(go env GOARCH) && \ ARCH="s390_64"; \ elif [ "$ARCH" = "arm64" ] ; then \ ARCH="aarch_64"; \ + elif [ "$ARCH" = "ppc64le" ] ; then \ + ARCH="ppcle_64"; \ elif [ "$ARCH" = "ppc64" ] ; then \ ARCH="ppcle_64"; \ else \ @@ -82,6 +84,8 @@ RUN ARCH=$(go env GOARCH) && \ ARCH="x86_64"; \ elif [ "$ARCH" = "386" ] ; then \ ARCH="i386"; \ + elif [ "$ARCH" = "ppc64le" ] ; then \ + ARCH="ppc64"; \ fi && \ wget --quiet "https://github.com/goreleaser/goreleaser/releases/download/v1.15.2/goreleaser_Linux_$ARCH.tar.gz" && \ tar xvf goreleaser_Linux_$ARCH.tar.gz; \