From ac72953e9dc5b9f494e8d6ffa9ec06e9dc387e6a Mon Sep 17 00:00:00 2001 From: Jan Schintag Date: Thu, 28 Nov 2024 13:32:48 +0100 Subject: [PATCH 1/5] ci: Enable building for s390x Change the Dockerfile to support fast multi-arch builds using cross-compilation. Do not hardcode the target arch as amd64. Signed-off-by: Jan Schintag --- .github/workflows/image-push.yaml | 6 ++++-- Dockerfile | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/image-push.yaml b/.github/workflows/image-push.yaml index ab57bac1..be938363 100644 --- a/.github/workflows/image-push.yaml +++ b/.github/workflows/image-push.yaml @@ -8,8 +8,8 @@ on: env: image-push-owner: 'kubevirt' jobs: - push-amd64: - name: Image push/amd64 + push: + name: Image push runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory @@ -41,6 +41,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . + platforms: linux/amd64,linux/s390x push: true tags: ghcr.io/${{ env.REPOSITORY_LC }}:latest file: Dockerfile @@ -52,6 +53,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . + platforms: linux/amd64,linux/s390x push: true tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ github.ref_name }} file: Dockerfile diff --git a/Dockerfile b/Dockerfile index 57975d2c..26938724 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM docker.io/library/golang:1.19 as builder +FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.19 as builder WORKDIR /workspace # Copy the Go Modules manifests @@ -13,8 +13,10 @@ RUN go mod download COPY main.go main.go COPY pkg/ pkg/ +ARG TARGETARCH + # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" go build -a -o manager main.go FROM registry.access.redhat.com/ubi8/ubi-minimal WORKDIR / From 36780e0db3277606c17e1a87f337acd8814fdafc Mon Sep 17 00:00:00 2001 From: Jan Schintag Date: Thu, 28 Nov 2024 14:13:26 +0100 Subject: [PATCH 2/5] ci: Update workflow dependencies to latest version Signed-off-by: Jan Schintag --- .github/workflows/image-push.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/image-push.yaml b/.github/workflows/image-push.yaml index be938363..e8e6df7a 100644 --- a/.github/workflows/image-push.yaml +++ b/.github/workflows/image-push.yaml @@ -13,14 +13,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Login to Container Registry if: github.repository_owner == 'kubevirt' - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} @@ -38,7 +38,7 @@ jobs: - name: Push latest container image if: github.repository_owner == 'kubevirt' - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/s390x @@ -50,7 +50,7 @@ jobs: - name: Push tagged container image if: startsWith(github.ref, 'refs/tags/') - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/s390x @@ -65,7 +65,7 @@ jobs: run: IMAGE=ghcr.io/${{ env.REPOSITORY_LC }}:${{ github.ref_name }} hack/update-manifest.sh - name: Release the kraken - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') with: generate_release_notes: true From 71af676a576c689ca95a5d12d83f24b4554dae50 Mon Sep 17 00:00:00 2001 From: Jan Schintag Date: Thu, 28 Nov 2024 14:17:38 +0100 Subject: [PATCH 3/5] Dockerfile: Fix lowercase as The ci outputs a warning since both FROM and AS keywords should be all uppercase. Signed-off-by: Jan Schintag --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 26938724..93b04bf8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.19 as builder +FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.19 AS builder WORKDIR /workspace # Copy the Go Modules manifests From d03ce8e9d1ebe5ef3e44d2722680e34c0076c923 Mon Sep 17 00:00:00 2001 From: Jan Schintag Date: Thu, 28 Nov 2024 13:04:43 +0100 Subject: [PATCH 4/5] install-go.sh: Support installing golang on multiple arches Add support for installing golang on arm64 and s390x. Signed-off-by: Jan Schintag --- hack/install-go.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hack/install-go.sh b/hack/install-go.sh index e7148b31..f7947684 100755 --- a/hack/install-go.sh +++ b/hack/install-go.sh @@ -2,7 +2,26 @@ destination=$1 version=$(grep "^go " go.mod |awk '{print $2}') -tarball=go$version.linux-amd64.tar.gz + +arch="$(uname -m)" + +case $arch in + x86_64 | amd64) + arch="amd64" + ;; + aarch64 | arm64) + arch="arm64" + ;; + s390x) + arch="s390x" + ;; + *) + echo "ERROR: invalid arch=${arch}, only support x86_64, aarch64 and s390x" + exit 1 + ;; +esac + +tarball=go$version.linux-$arch.tar.gz url=https://dl.google.com/go/ mkdir -p $destination From 5a625ebdbbac2a4da3567f5bca0f181c790425f7 Mon Sep 17 00:00:00 2001 From: Jan Schintag Date: Mon, 2 Dec 2024 17:04:23 +0100 Subject: [PATCH 5/5] ci: Enable building for aarch64 Signed-off-by: Jan Schintag --- .github/workflows/image-push.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/image-push.yaml b/.github/workflows/image-push.yaml index e8e6df7a..1e7d19a0 100644 --- a/.github/workflows/image-push.yaml +++ b/.github/workflows/image-push.yaml @@ -41,7 +41,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64,linux/s390x + platforms: linux/amd64,linux/s390x,linux/arm64 push: true tags: ghcr.io/${{ env.REPOSITORY_LC }}:latest file: Dockerfile @@ -53,7 +53,7 @@ jobs: uses: docker/build-push-action@v6 with: context: . - platforms: linux/amd64,linux/s390x + platforms: linux/amd64,linux/s390x,linux/arm64 push: true tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ github.ref_name }} file: Dockerfile