Skip to content

Commit

Permalink
Build multi-arch docker images.
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Dec 8, 2023
1 parent 1b2b0d4 commit 014b8a8
Showing 1 changed file with 64 additions and 7 deletions.
71 changes: 64 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ jobs:
matrix:
os: [ linux ]
arch: [ x86_64, aarch64 ]
target: [ kupo ]

runs-on: ${{ matrix.os == 'linux' && 'ubuntu-latest' }}

Expand All @@ -100,15 +99,21 @@ jobs:

- name: 🐳 Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2.1.0
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: cardanosolutions/kupo

- name: 📝 Base Variables
id: base-variables
run: |
echo "image=cardanosolutions/${{ matrix.target }}" >> $GITHUB_OUTPUT
echo "image=cardanosolutions/kupo" >> $GITHUB_OUTPUT
- name: 📝 Tag Variables
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
Expand All @@ -122,25 +127,77 @@ jobs:
name: kupo-${{ github.sha }}-${{ matrix.arch }}-${{ matrix.os }}

- name: 🔨 Build and push (latest)
id: build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: ${{ matrix.os }}/${{ matrix.arch == 'x86_64' && 'amd64' || 'arm64' }}
tags: ${{ steps.base-variables.outputs.image }}:latest
target: ${{ matrix.target }}
target: kupo
cache-from: type=registry,ref=${{ steps.base-variables.outputs.image }}:latest
cache-to: type=inline
outputs: type=image,name=cardanosolutions/kupo,push-by-digest=true,name-canonical=true,push=true

- name: 🏷️ Build and push (tag)
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: ${{ matrix.os }}/${{ matrix.arch == 'x86_64' && 'amd64' || 'arm64' }}
tags: ${{ steps.base-variables.outputs.image }}:${{ steps.tag-variables.outputs.tag }}
target: ${{ matrix.target }}
target: kupo
cache-from: type=registry,ref=${{ steps.base-variables.outputs.image }}:latest
cache-to: type=inline
outputs: type=image,name=cardanosolutions/kupo,push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

registry:
needs: [ docker ]
runs-on: ubuntu-latest

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: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: cardanosolutions/kupo

- name: 🐳 Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect cardanosolutions/kupo:${{ steps.meta.outputs.version }}

0 comments on commit 014b8a8

Please sign in to comment.