Cross-platform docker images built with GitHub actions
I run a number of docker containers on a couple of Raspberry Pi 4's. These are running arm64 version of raspbian. To build the docker images for these servers I found it was easiest to use GitHub Actions and get that do do the hard work.
This is an base level example workflow that I use.
Assuming the root of your GitHub repository has a working Dockerfile
.
Create a file in .github/workflows
, say 'build.yaml' with the following
contents.
.github/workflows/build.yaml
name: Build Image Cross Platform
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# this is a simple way of using date and time to do versioning.
- name: Modify scripts and get version
id: version
run: |
output=$(date -u '+%Y%m%d%H%M%S')
echo ::set-output name=date_version::$output
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
# here you can do additional steps
-
name: Build and push
uses: docker/[email protected]
with:
context: ./
file: ./Dockerfile
platforms: linux/arm64, linux/amd64
push: true
tags: |
ghcr.io/${{github.repository}}:latest
ghcr.io/${{github.repository}}:${{steps.version.outputs.date_version}}
Under platforms
you can list any compatible docker buildx
platforms you need.
The platforms will be printed in the action log when it is run. Currently these are:
- linux/amd64
- linux/arm64
- linux/riscv64
- linux/ppc64le
- linux/s390x
- linux/386
- linux/mips64le
- linux/mips64
- linux/arm/v7
- linux/arm/v6