Create a robust docker image build for ARMD64 and ARM64 (#81) #26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Multi-Platform Builds | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to run the workflow on' | |
| required: false | |
| release: | |
| types: [ created ] | |
| jobs: | |
| # ------------------------- | |
| # AMD64 Build | |
| # ------------------------- | |
| build-amd64: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - 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.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repo and sanitize ref | |
| run: | | |
| echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -) | |
| echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV | |
| - name: Build and push AMD64 image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile.x86_64 | |
| build-args: SOURCE_REPO=https://github.com/${{ github.repository }} | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 | |
| ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-amd64', env.REPO_LOWER) || '' }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # ------------------------- | |
| # ARM64 Build (manual / self-hosted) | |
| # ------------------------- | |
| build-arm64: | |
| #if: ${{ github.event_name == 'workflow_dispatch' }} # manual trigger only | |
| # runs-on: [self-hosted, arm64] # use if you have an ARM64 runner | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker daemon (containerd features) | |
| uses: docker/setup-docker-action@v4 | |
| with: | |
| daemon-config: | | |
| { | |
| "debug": true, | |
| "features": { "containerd-snapshotter": true } | |
| } | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - 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.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repo and sanitize ref | |
| run: | | |
| echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -) | |
| echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV | |
| - name: Build and push ARM64 image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile.arm64 | |
| build-args: BUILDKIT_PROGRESS=plain,SOURCE_REPO=https://github.com/${{ github.repository }} | |
| platforms: linux/arm64 | |
| push: true | |
| tags: | | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64 | |
| ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-arm64', env.REPO_LOWER) || '' }} | |
| cache-from: type=gha,scope=arm64 | |
| cache-to: type=gha,scope=arm64,mode=max | |
| # ------------------------- | |
| # Create multi-arch manifest | |
| # ------------------------- | |
| manifest: | |
| # if: ${{ github.event_name == 'workflow_dispatch' }} # only when both images are built | |
| needs: [ build-amd64, build-arm64 ] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Set up Docker Buildx (for imagetools) | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Normalize repo and sanitize ref | |
| run: | | |
| echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -) | |
| echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV | |
| - name: Create multi-arch manifest for ref tag | |
| run: | | |
| docker buildx imagetools create \ | |
| --tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }} \ | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 \ | |
| ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64 | |
| - name: Also tag :latest on main | |
| if: ${{ github.ref_name == 'main' }} | |
| run: | | |
| docker buildx imagetools create \ | |
| --tag ghcr.io/${{ env.REPO_LOWER }}:latest \ | |
| ghcr.io/${{ env.REPO_LOWER }}:latest-amd64 \ | |
| ghcr.io/${{ env.REPO_LOWER }}:latest-arm64 |