From 063e0bbb222b37ac8183ef9dfbdb32f6541092a0 Mon Sep 17 00:00:00 2001 From: Paul Bastide Date: Thu, 8 Jun 2023 09:48:03 -0400 Subject: [PATCH] MULTIARCH-3440: refine multiarch support for test-unit and test-e2e using dockerfile and add ppc64le build to Makefile (#624) * MULTIARCH-3440: refine multiarch support for test-unit and test-e2e using dockerfile and add ppc64le build to Makefile - Update the .goreleaser.yaml to include ppc64le - Update the Dockerfile to include wget and pigz dependency - Update the Dockerfile to consider arch it's built on - Update the util.sh to be arch agnostic - Update the cross build for ppc64le Signed-off-by: Paul Bastide * MULTIARCH-3440: Update per review Signed-off-by: Paul Bastide Co-authored-by: Jan Schintag <43986265+jschintag@users.noreply.github.com> * MULTIARCH-3441: Enable builds for s390x (#1) - Update the .goreleaser.yaml to include s390x - Update the cross build for s390x - Link gcc to s390x-linux-gnu-gcc binary On s390x go compiler seems to expect the gcc binary at s390x-linux-gnu-gcc binary. However on rhel it is not installed there. Signed-off-by: Jan Schintag * MULTIARCH-3441: Enable builds for s390x (#1) (#2) - Update the .goreleaser.yaml to include s390x - Update the cross build for s390x - Link gcc to s390x-linux-gnu-gcc binary On s390x go compiler seems to expect the gcc binary at s390x-linux-gnu-gcc binary. However on rhel it is not installed there. Signed-off-by: Jan Schintag * MULTIARCH-3440: update the code to use go-containerregistry for all arches and add arm64 Signed-off-by: Paul Bastide * MULTIARCH-3440: Adding cross-build for arm64 Signed-off-by: Paul Bastide --------- Signed-off-by: Paul Bastide Signed-off-by: Jan Schintag Co-authored-by: Jan Schintag <43986265+jschintag@users.noreply.github.com> --- .goreleaser.yaml | 3 +++ Dockerfile | 15 ++++++++++--- Makefile | 24 +++++++++++++++----- test/e2e/e2e-simple.sh | 6 ++++- test/e2e/lib/util.sh | 50 ++++++++++++++++++++++++++++++++---------- 5 files changed, 76 insertions(+), 22 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 9bf9298bd..52a88e552 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -11,6 +11,9 @@ builds: - linux goarch: - amd64 + - ppc64le + - s390x + - arm64 env: - CGO_ENABLED=1 flags: diff --git a/Dockerfile b/Dockerfile index 171bfcca8..016b79620 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,19 +14,28 @@ ARG DNF_LIST="\ git \ gpgme-devel \ libassuan-devel \ + wget \ + pigz \ " ################################################################################# -# Build UBI8 Builder +# Build UBI8 Builder with multi-arch support RUN set -ex \ + && ARCH=$(arch | sed 's|x86_64|amd64|g' | sed 's|aarch64|arm64|g') \ && dnf install -y --nodocs --setopt=install_weak_deps=false ${DNF_LIST} \ && dnf clean all -y \ - && GO_VERSION=go1.19.5 \ - && curl -sL https://golang.org/dl/${GO_VERSION}.linux-amd64.tar.gz \ + && GO_VERSION=go1.19.5 \ + && curl -sL https://golang.org/dl/${GO_VERSION}.linux-${ARCH}.tar.gz \ | tar xzvf - --directory /usr/local/ \ && /usr/local/go/bin/go version \ && ln -f /usr/local/go/bin/go /usr/bin/go +################################################################################# +# Link gcc to /usr/bin/s390x-linux-gnu-gcc as go requires it on s390x +RUN [ "$(arch)" == "s390x" ] \ + && ln /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc \ + || echo "Not running on s390x, skip linking gcc binary" + WORKDIR /build ENTRYPOINT ["make"] CMD [] diff --git a/Makefile b/Makefile index bb2307ef7..1986fa379 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,19 @@ cross-build-linux-amd64: +@GOOS=linux GOARCH=amd64 $(MAKE) "$(GO_BUILD_FLAGS)" --no-print-directory build GO_BUILD_BINDIR=$(GO_BUILD_BINDIR)/linux-amd64 .PHONY: cross-build-linux-amd64 -cross-build: cross-build-linux-amd64 +cross-build-linux-ppc64le: + +@GOOS=linux GOARCH=ppc64le $(MAKE) "$(GO_BUILD_FLAGS)" --no-print-directory build GO_BUILD_BINDIR=$(GO_BUILD_BINDIR)/linux-ppc64le +.PHONY: cross-build-linux-ppc64le + +cross-build-linux-s390x: + +@GOOS=linux GOARCH=s390x $(MAKE) "$(GO_BUILD_FLAGS)" --no-print-directory build GO_BUILD_BINDIR=$(GO_BUILD_BINDIR)/linux-s390x +.PHONY: cross-build-linux-s390x + +cross-build-linux-arm64: + +@GOOS=linux GOARCH=arm64 $(MAKE) "$(GO_BUILD_FLAGS)" --no-print-directory build GO_BUILD_BINDIR=$(GO_BUILD_BINDIR)/linux-arm64 +.PHONY: cross-build-linux-arm64 + +cross-build: cross-build-linux-amd64 cross-build-linux-ppc64le cross-build-linux-s390x cross-build-linux-arm64 .PHONY: cross-build hack-build: clean @@ -71,12 +83,12 @@ publish-catalog: @cd test/operator && make .PHONY: publish-catalog -format: +format: $(GO) fmt ./pkg/... $(GO) fmt ./cmd/... .PHONY: format -vet: - $(GO) vet $(GO_BUILD_FLAGS) ./pkg/... - $(GO) vet $(GO_BUILD_FLAGS) ./cmd/... -.PHONY: vet \ No newline at end of file +vet: + $(GO) vet $(GO_BUILD_FLAGS) ./pkg/... + $(GO) vet $(GO_BUILD_FLAGS) ./cmd/... +.PHONY: vet diff --git a/test/e2e/e2e-simple.sh b/test/e2e/e2e-simple.sh index 114e4cc7a..285f8f6d3 100755 --- a/test/e2e/e2e-simple.sh +++ b/test/e2e/e2e-simple.sh @@ -32,8 +32,12 @@ METADATA_OCI_CATALOG="oci://${DIR}/artifacts/rhop-ctlg-oci" TARGET_CATALOG_NAME="target-name" TARGET_CATALOG_TAG="target-tag" - GOBIN=$HOME/go/bin +# Check if this is running with a different location +if [ ! -d $GOBIN ] +then + GOBIN=/usr/local/go/bin/ +fi PATH=$PATH:$GOBIN mkdir -p $DATA_TMP diff --git a/test/e2e/lib/util.sh b/test/e2e/lib/util.sh index a93bbca03..ab52b6a83 100644 --- a/test/e2e/lib/util.sh +++ b/test/e2e/lib/util.sh @@ -43,18 +43,44 @@ function cleanup_conn() { # install_deps will install crane and registry2 in go bin dir function install_deps() { - pushd ${DATA_TMP} - GOFLAGS=-mod=mod go install github.com/google/go-containerregistry/cmd/crane@latest - popd - crane export registry:2 registry2.tar - tar xvf registry2.tar bin/registry - mv bin/registry $GOBIN - crane export quay.io/operator-framework/opm@sha256:d31c6ea5c50be93d6eb94d2b508f0208e84a308c011c6454ebf291d48b37df19 opm.tar - tar xvf opm.tar bin/opm - mv bin/opm $GOBIN - rm -f registry2.tar opm.tar - wget -O $GOBIN/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 - chmod +x $GOBIN/jq + if [ "$(arch)" == "x86_64" ] + then + pushd ${DATA_TMP} + GOFLAGS=-mod=mod go install github.com/google/go-containerregistry/cmd/crane@latest + popd + crane export registry:2 registry2.tar + tar xvf registry2.tar bin/registry + mv bin/registry $GOBIN + crane export quay.io/operator-framework/opm@sha256:d31c6ea5c50be93d6eb94d2b508f0208e84a308c011c6454ebf291d48b37df19 opm.tar + tar xvf opm.tar bin/opm + mv bin/opm $GOBIN + rm -f registry2.tar opm.tar + wget -O $GOBIN/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 + chmod +x $GOBIN/jq + else + # non-x86_64 flow + pushd ${DATA_TMP} + + # For ppc64le, this is compiled with Power9 compatibility (does not run on Power8) + ARCH=$(arch | sed 's|aarch64|arm64|g') + curl -o $GOBIN/opm -L https://github.com/operator-framework/operator-registry/releases/download/v1.27.1/linux-${ARCH}-opm + chmod +x $GOBIN/opm + + GOFLAGS=-mod=mod go install github.com/google/go-containerregistry/cmd/crane@latest + mv ~/go/bin/crane $GOBIN/ + + if [ "${ARCH}" == "arm64" ] + then + crane export --platform linux/arm64/v8 registry:2 registry2.tar + else + crane export ${ARCH}/registry:2 registry2.tar + fi + tar xvf registry2.tar bin/registry + mv bin/registry $GOBIN + rm registry2.tar + + popd + fi } # setup_reg will configure and start registry2 processes