Multi-arch docker builds on GitHub Actions
Posted on:
For my various apps that I deploy via docker, I have the following GitHub Actions workflow to build the container for both x86_64 and arm64 architectures and then deploy them to ghcr.io (this is copied from one of my discord bots):
on:
push:
branches:
- "main"
tags:
- "v*"
name: Docker
jobs:
build:
name: Build Container
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- name: Login to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6.15.0
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/lannonbr/jeff-bot:${{ github.ref_name }}
Some notes
- All of the actions are using fixed hash pins while we wait for immutable action releases.
- it builds on every git commit to main or a tag that starts with
v
(ex: v1.0.0) - the only thing I need to change per repo to repo is the docker name / tag at the end of this file