Skip to content

Commit a12ea4a

Browse files
authored
Support building docker images for arm64 natively. (#1007)
* Try running arm builds on native platform and them combining them at the end. * Rework flow for manifest making * fix login action * login to both * Use a matrix loop * try using json * changelog
1 parent d866355 commit a12ea4a

File tree

2 files changed

+62
-18
lines changed

2 files changed

+62
-18
lines changed

.github/workflows/docker.yml

+61-18
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,47 @@ concurrency:
2222

2323
env:
2424
DOCKER_NAMESPACE: halfshot
25-
PLATFORMS: linux/amd64
26-
PLATFORMS_PUSH: linux/amd64,linux/arm64
27-
# Only push if this is main, otherwise we just want to build
28-
BUILD_FOR_ALL_PLATFORMS: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
2925

3026
jobs:
31-
docker-latest:
27+
docker-clean-metadata:
3228
runs-on: ubuntu-latest
29+
outputs:
30+
json: ${{ steps.meta.outputs.json }}
31+
steps:
32+
- name: Extract metadata (tags, labels) for Docker
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
tags: |
37+
type=semver,pattern={{version}}
38+
type=ref,event=branch
39+
type=ref,event=pr
40+
type=raw,value=latest,enable={{is_default_branch}}
41+
flavor: |
42+
latest=auto
43+
images: |
44+
${{ env.DOCKER_NAMESPACE }}/matrix-hookshot
45+
ghcr.io/matrix-org/matrix-hookshot
3346
47+
docker-build:
3448
permissions:
3549
contents: read
3650
packages: write
3751
attestations: write
3852
id-token: write
53+
strategy:
54+
matrix:
55+
include:
56+
- os: ubuntu-latest
57+
arch: amd64
58+
- os: ubuntu-24.04-arm
59+
arch: arm64
60+
61+
runs-on: ${{ matrix.os }}
3962

4063
steps:
4164
- name: Checkout
4265
uses: actions/checkout@v4
43-
- name: Set up QEMU
44-
uses: docker/setup-qemu-action@v3
45-
- name: Set up Docker Buildx
46-
uses: docker/setup-buildx-action@v3
4766
- name: Log in to Docker Hub
4867
uses: docker/login-action@v3
4968
with:
@@ -55,7 +74,6 @@ jobs:
5574
registry: ghcr.io
5675
username: ${{ github.actor }}
5776
password: ${{ secrets.GITHUB_TOKEN }}
58-
5977
- name: Extract metadata (tags, labels) for Docker
6078
id: meta
6179
uses: docker/metadata-action@v5
@@ -65,20 +83,45 @@ jobs:
6583
type=ref,event=branch
6684
type=ref,event=pr
6785
type=raw,value=latest,enable={{is_default_branch}}
86+
flavor: |
87+
latest=auto
88+
suffix=-${{ matrix.arch }},onlatest=true
6889
images: |
6990
${{ env.DOCKER_NAMESPACE }}/matrix-hookshot
7091
ghcr.io/matrix-org/matrix-hookshot
71-
92+
7293
- name: Build and push Docker images
73-
id: push
7494
uses: docker/build-push-action@v6
7595
with:
76-
context: .
77-
# arm64 builds OOM without the git fetch setting. c.f.
78-
# https://github.com/rust-lang/cargo/issues/10583
79-
build-args: |
80-
CARGO_NET_GIT_FETCH_WITH_CLI=true
81-
platforms: ${{ (env.BUILD_FOR_ALL_PLATFORMS == 'true' && env.PLATFORMS_PUSH) || env.PLATFORMS }}
8296
push: true
8397
tags: ${{ steps.meta.outputs.tags }}
8498
labels: ${{ steps.meta.outputs.labels }}
99+
100+
docker-manifest:
101+
needs:
102+
- docker-build
103+
- docker-clean-metadata
104+
runs-on: ubuntu-latest
105+
106+
strategy:
107+
matrix:
108+
image: ${{ fromJson(needs.docker-clean-metadata.outputs.json).tags }}
109+
110+
steps:
111+
- name: Log in to Docker Hub
112+
uses: docker/login-action@v3
113+
with:
114+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
115+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
116+
117+
- name: Log in to the GitHub Container registry
118+
uses: docker/login-action@v3
119+
with:
120+
registry: ghcr.io
121+
username: ${{ github.actor }}
122+
password: ${{ secrets.GITHUB_TOKEN }}
123+
124+
- name: Create and push manifest
125+
run: |
126+
docker manifest create ${{ matrix.image }} ${{ matrix.image }}-amd64 ${{ matrix.image }}-arm64
127+
docker manifest push ${{ matrix.image }}

changelog.d/1008.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Switch to using GitHub Actions native arm runners for Docker builds, which will reduce build times.

0 commit comments

Comments
 (0)