Skip to content

Commit

Permalink
Add multi arch python image
Browse files Browse the repository at this point in the history
* Add multi arch

* Try push by digest

* Try to fix image push

* Change arch

* Fix push ?

* Last fix
  • Loading branch information
Hartorn authored Sep 23, 2024
1 parent 35f8150 commit 22551d6
Showing 1 changed file with 74 additions and 3 deletions.
77 changes: 74 additions & 3 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
strategy:
matrix:
element: ["python"]
platform: ['amd64', 'arm64']
fail-fast: false
runs-on: ubuntu-latest
steps:
Expand All @@ -25,14 +26,25 @@ jobs:
id: builder
uses: docker/setup-buildx-action@v3

- name: 'Append ARM buildx builder'
if: ${{ matrix.platform == 'arm64' }}
uses: baschny/append-buildx-action@v1
with:
node_name: builder-${{github.run_id}}-${{github.job}}-${{github.run_number}}-${{github.run_attempt}}
builder: ${{ steps.builder.outputs.name }}
endpoint: ssh://${{ secrets.ARM_SSH_CONNECTION_STRING }}
ssh_private_key: ${{ secrets.ARM_SSH_PRIVATE_KEY }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_IMAGE_PREFIX }}${{ matrix.element }}
flavor: |
latest=true
latest=false
tags: |
type=raw,enable=true,value=${{matrix.platform}}
- name: Login to Docker registry
uses: docker/login-action@v3
Expand All @@ -46,7 +58,66 @@ jobs:
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.element }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
builder: ${{ steps.builder.outputs.name }}
platforms: |
linux/${{ matrix.platform }}
push: true

# For details, see link below
# https://docs.docker.com/build/ci/github-actions/multi-platform/
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.push.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.platform }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digests-*
merge-multiple: true
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: |
${{ env.REGISTRY_IMAGE_PREFIX }}python
flavor: |
latest=${{ github.ref_name == 'main'}}
- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_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_PREFIX }}python@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE_PREFIX }}python:${{ steps.meta.outputs.version }}

0 comments on commit 22551d6

Please sign in to comment.