Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building both amd64 and arm64 with GitHub workflows from different files

What is the correct way to setup GitHub workflow for the multi-platform (amd64+arm64) Docker image build? I have two different docker files, one for each platform (see MapLibre/Martin project), and I tried to do it with a matrix configuring both platform and file params, but for some reason it publishes linux/amd64 image with the linux/arm64 metadata, and another image has unknown/unknown.

jobs:
  docker:
    name: Build ${{ matrix.platform }} docker image
    strategy:
      fail-fast: true
      matrix:
        include:
          - platform: linux/amd64
            file: Dockerfile
          - platform: linux/arm64
            file: arm64.Dockerfile
    runs-on: ubuntu-latest
    steps:

      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Docker meta
        id: docker_meta
        uses: docker/metadata-action@v4
        with:
          images: ghcr.io/maplibre/martin

      - name: Set up QEMU
        uses: docker/[email protected]
        with:
          platforms: linux/arm64,linux/amd64

      - name: Set up Docker Buildx
        uses: docker/[email protected]
        with:
          install: true
          platforms: ${{ matrix.platform }}

      - name: Build the Docker image
        id: docker_build
        uses: docker/build-push-action@v4
        with:
          file: ${{ matrix.file }}
          push: false
          load: true
          tags: ${{ steps.docker_meta.outputs.tags }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          platforms: ${{ matrix.platform }}

      - name: Login to GitHub Docker registry
        uses: docker/login-action@v2
        if: ${{ github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork }}
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Push the Docker image
        if: ${{ github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' }}
        uses: docker/build-push-action@v4
        with:
          file: ${{ matrix.file }}
          push: true
          load: false
          tags: ${{ steps.docker_meta.outputs.tags }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          platforms: ${{ matrix.platform }}
like image 481
Yuri Astrakhan Avatar asked Feb 02 '26 06:02

Yuri Astrakhan


1 Answers

You don't need to use strategy: matrix: ... to do a multi-platform build. It will be much easier if you can integrate your two Dockerfiles into a single Dockerfile. Add --platform=$BUILDPLATFORM to the first FROM ... line of your Dockerfile.

FROM --platform=$BUILDPLATFORM rust:alpine as builder

You should try to settle on the same set of base images to use for both your arm and amd builds. If you can't, then it gets a bit more involved.

Within your build step use an array of platforms:

    - name: Build Docker images
      uses: docker/build-push-action@v4
      with:
        platforms:
           - linux/amd64
           - linux/arm64

You'll end up with something like this:

jobs:
  docker:
    name: Build docker images
    runs-on: ubuntu-latest
    steps:

      - name: Checkout sources
        uses: actions/checkout@v3

      - name: Docker meta
        id: docker_meta
        uses: docker/metadata-action@v4
        with:
          images: ghcr.io/maplibre/martin

      - name: Set up Docker Buildx
        uses: docker/[email protected]

      - name: Login to GitHub Docker registry
        uses: docker/login-action@v2
        if: ${{ github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork }}
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Push the Docker image
        if: ${{ github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' }}
        uses: docker/build-push-action@v4
        with:
          push: true
          tags: ${{ steps.docker_meta.outputs.tags }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          platforms: 
             - linux/arm64
             - linux/amd64
like image 151
Will Holtz Avatar answered Feb 04 '26 00:02

Will Holtz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!