Skip to content

Commit

Permalink
Fix cross-arch image (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedbossneo authored Aug 8, 2023
1 parent 937caac commit e98f018
Showing 1 changed file with 66 additions and 13 deletions.
79 changes: 66 additions & 13 deletions .github/workflows/build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ jobs:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{github.repository}}
# generate Docker tags based on the following events/attributes
tags: |
type=edge,branch=main,prefix=releases-
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU (arm64)
Expand All @@ -75,12 +65,75 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
platforms: ${{ matrix.docker_build_arch }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=ghcr.io/${{github.repository}},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max

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

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
if: github.event_name != 'pull_request'
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
if: github.event_name != 'pull_request'
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v4
with:
# generate Docker tags based on the following events/attributes
tags: |
type=edge,branch=main,prefix=releases-
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
images: ghcr.io/${{github.repository}}
- name: Login to Docker Hub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'ghcr.io/${{github.repository}}@sha256:%s ' *)
- name: Inspect image
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ghcr.io/${{github.repository}}:${{ steps.meta.outputs.version }}

0 comments on commit e98f018

Please sign in to comment.