Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
feat(ci): build multi-arch images in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgacsal committed Oct 3, 2023
1 parent 11d2c55 commit cd0961b
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions .github/workflows/build-and-push-component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ on:
jobs:
build-and-push:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -52,16 +58,65 @@ jobs:

- name: Build
uses: docker/build-push-action@v5
id: build
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: ${{ matrix.platform }}
tags: ghcr.io/openclarity/${{ inputs.image_name }}:${{ inputs.image_tag }}
file: ${{ inputs.dockerfile }}
push: ${{ inputs.push }}
outputs: "${{ env.OUTPUTS }}"
outputs: type=image,name=${{ inputs.image_name }},push-by-digest=true,name-canonical=true,push=${{ inputs.push }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
VERSION=${{ inputs.image_tag }}
BUILD_TIMESTAMP=${{ inputs.timestamp }}
COMMIT_HASH=${{ github.sha }}
- name: Export digest
if: inputs.push
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
if: inputs.push
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge-and-push:
if: inputs.push
runs-on: ubuntu-latest
needs:
- build-and-push
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
# shellcheck disable=SC2046
docker buildx imagetools create --tag "${{ inputs.image_tag }}" \
$(printf '${{ inputs.image_name }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ inputs.image_name }}:${{ inputs.image_tag }}

0 comments on commit cd0961b

Please sign in to comment.