From 6fa46f719bbf4e1cd6175f1ab2fc6c69015c9a67 Mon Sep 17 00:00:00 2001 From: jdao-rh Date: Thu, 7 Nov 2024 03:46:19 -0500 Subject: [PATCH] ROX-25992: Add multiarch builds to CI - Manual manifest build (#48) Co-authored-by: Marcin Owsiany --- .github/workflows/build.yaml | 147 ++++++++++++++++++++++++++++++----- Dockerfile | 3 +- Makefile | 13 ++++ 3 files changed, 144 insertions(+), 19 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0e3e414..5ae4fd3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,20 +14,6 @@ jobs: - name: Run ShellCheck on GHA config uses: saleor/shellcheck-gha@v0 - - name: Prepare OCI metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: "quay.io/stackrox-io/image-prefetcher" - # generate Docker tags based on the following events/attributes - # See https://github.com/docker/metadata-action - tags: | - type=ref,event=branch,prefix=branch- - type=semver,pattern=v{{major}}.{{minor}}.{{patch}} - type=semver,pattern=v{{major}}.{{minor}} - type=semver,pattern=v{{major}} - type=sha - - name: Setup Go uses: actions/setup-go@v5 with: @@ -71,7 +57,7 @@ jobs: directory: manifests - name: Build binary - run: CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' . + run: make -j2 binary-all - name: Login to Quay if: github.event_name != 'pull_request' @@ -81,14 +67,139 @@ jobs: username: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }} password: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }} - - name: Build and push OCI image + - name: Prepare manifest OCI metadata for amd64 + id: meta-amd64 + uses: docker/metadata-action@v5 + with: + images: "quay.io/stackrox-io/image-prefetcher" + # generate Docker tags based on the following events/attributes + # See https://github.com/docker/metadata-action + tags: | + type=ref,event=branch,prefix=branch-,suffix=-amd64 + type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-amd64 + type=semver,pattern=v{{major}}.{{minor}},suffix=-amd64 + type=semver,pattern=v{{major}},suffix=-amd64 + type=sha,suffix=-amd64 + + - name: Build and push OCI amd64 image + if: github.event_name != 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-amd64.outputs.tags }} + labels: ${{ steps.meta-amd64.outputs.labels }} + platforms: linux/amd64 + build-args: | + ARCH=amd64 + + - name: Prepare manifest OCI metadata for arm64 + id: meta-arm64 + uses: docker/metadata-action@v5 + with: + images: "quay.io/stackrox-io/image-prefetcher" + # generate Docker tags based on the following events/attributes + # See https://github.com/docker/metadata-action + tags: | + type=ref,event=branch,prefix=branch-,suffix=-arm64 + type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-arm64 + type=semver,pattern=v{{major}}.{{minor}},suffix=-arm64 + type=semver,pattern=v{{major}},suffix=-arm64 + type=sha,suffix=-arm64 + + - name: Build and push OCI arm64 image + if: github.event_name != 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-arm64.outputs.tags }} + labels: ${{ steps.meta-arm64.outputs.labels }} + platforms: linux/arm64 + build-args: | + ARCH=arm64 + + - name: Prepare manifest OCI metadata for ppc64le + id: meta-ppc64le + uses: docker/metadata-action@v5 + with: + images: "quay.io/stackrox-io/image-prefetcher" + # generate Docker tags based on the following events/attributes + # See https://github.com/docker/metadata-action + tags: | + type=ref,event=branch,prefix=branch-,suffix=-ppc64le + type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-ppc64le + type=semver,pattern=v{{major}}.{{minor}},suffix=-ppc64le + type=semver,pattern=v{{major}},suffix=-ppc64le + type=sha,suffix=-ppc64le + + - name: Build and push OCI ppc64le image + if: github.event_name != 'pull_request' + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-ppc64le.outputs.tags }} + labels: ${{ steps.meta-ppc64le.outputs.labels }} + platforms: linux/ppc64le + build-args: | + ARCH=ppc64le + + - name: Prepare manifest OCI metadata for s390x + id: meta-s390x + uses: docker/metadata-action@v5 + with: + images: "quay.io/stackrox-io/image-prefetcher" + # generate Docker tags based on the following events/attributes + # See https://github.com/docker/metadata-action + tags: | + type=ref,event=branch,prefix=branch-,suffix=-s390x + type=semver,pattern=v{{major}}.{{minor}}.{{patch}},suffix=-s390x + type=semver,pattern=v{{major}}.{{minor}},suffix=-s390x + type=semver,pattern=v{{major}},suffix=-s390x + type=sha,suffix=-s390x + + - name: Build and push OCI s390x image if: github.event_name != 'pull_request' uses: docker/build-push-action@v5 with: context: . push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta-s390x.outputs.tags }} + labels: ${{ steps.meta-s390x.outputs.labels }} + platforms: linux/s390x + build-args: | + ARCH=s390x + + - name: Prepare manifest OCI metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: "quay.io/stackrox-io/image-prefetcher" + # generate Docker tags based on the following events/attributes + # See https://github.com/docker/metadata-action + tags: | + type=ref,event=branch,prefix=branch- + type=semver,pattern=v{{major}}.{{minor}}.{{patch}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=sha + + - name: Create and push multi-arch manifest + if: github.event_name != 'pull_request' + env: + IMAGE_TAGS: ${{ steps.meta.outputs.tags }} + run: | + for tag in ${IMAGE_TAGS}; + do + docker manifest create "${tag}" \ + --amend "${tag}-amd64" \ + --amend "${tag}-arm64" \ + --amend "${tag}-ppc64le" \ + --amend "${tag}-s390x" + docker manifest push "${tag}" + done + e2e: if: github.event_name != 'pull_request' diff --git a/Dockerfile b/Dockerfile index d0090dd..f488d21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM scratch -COPY image-prefetcher / +ARG ARCH=amd64 +COPY ./image-prefetcher-${ARCH} /image-prefetcher ENTRYPOINT ["/image-prefetcher"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c479cba --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +binary-amd64: + env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o image-prefetcher-amd64 -ldflags '-extldflags "-static"' . + +binary-arm64: + env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o image-prefetcher-arm64 -ldflags '-extldflags "-static"' . + +binary-ppc64le: + env CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -a -o image-prefetcher-ppc64le -ldflags '-extldflags "-static"' . + +binary-s390x: + env CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -a -o image-prefetcher-s390x -ldflags '-extldflags "-static"' . + +binary-all: binary-amd64 binary-arm64 binary-ppc64le binary-s390x