Skip to content

Commit

Permalink
MULTIARCH-3440: refine multiarch support for test-unit and test-e2e u…
Browse files Browse the repository at this point in the history
…sing 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 <pbastide@redhat.com>

* MULTIARCH-3440: Update per review

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>

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 <jan.schintag@de.ibm.com>

* 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 <jan.schintag@de.ibm.com>

* MULTIARCH-3440: update the code to use go-containerregistry for all arches and add arm64

Signed-off-by: Paul Bastide <pbastide@redhat.com>

* MULTIARCH-3440: Adding cross-build for arm64

Signed-off-by: Paul Bastide <pbastide@redhat.com>

---------

Signed-off-by: Paul Bastide <pbastide@redhat.com>
Signed-off-by: Jan Schintag <jan.schintag@de.ibm.com>
Co-authored-by: Jan Schintag <43986265+jschintag@users.noreply.github.com>
  • Loading branch information
prb112 and jschintag committed Jun 8, 2023
1 parent b43a65b commit 063e0bb
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .goreleaser.yaml
Expand Up @@ -11,6 +11,9 @@ builds:
- linux
goarch:
- amd64
- ppc64le
- s390x
- arm64
env:
- CGO_ENABLED=1
flags:
Expand Down
15 changes: 12 additions & 3 deletions Dockerfile
Expand Up @@ -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 []
Expand Down
24 changes: 18 additions & 6 deletions Makefile
Expand Up @@ -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
Expand Down Expand Up @@ -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
vet:
$(GO) vet $(GO_BUILD_FLAGS) ./pkg/...
$(GO) vet $(GO_BUILD_FLAGS) ./cmd/...
.PHONY: vet
6 changes: 5 additions & 1 deletion test/e2e/e2e-simple.sh
Expand Up @@ -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
Expand Down
50 changes: 38 additions & 12 deletions test/e2e/lib/util.sh
Expand Up @@ -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
Expand Down

0 comments on commit 063e0bb

Please sign in to comment.