Skip to content

Commit 8f42112

Browse files
committed
github: Build the multiplatform docker image in two steps
6b6b124 tried to build a multiplatform image, by building two images separately and pushing them one at a time, with the same name (but with a different platform). This doesn't work as expected; the last push for the image name replaces earlier pushes. So depending on which push finishes last, we'd end up with either an amd64 or arm64 image, but not one that supports both. Instead, push two separate images just with push-by-digest, and then create the actual tag with "docker buildx imagetools create". Alternatively, we could build all platform variants of the main image with Dockerfile.toolchain, simplifying the setup significantly. The contents of such a build is marginally different though, so keep the amd64 image as it was, for now, compiled in that environment.
1 parent ed5fd4c commit 8f42112

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

.github/workflows/docker.yml

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,9 @@ jobs:
3838
cat parameters.txt >> $GITHUB_OUTPUT
3939
cat $GITHUB_OUTPUT
4040
41-
docker-build:
41+
docker-build-dev:
4242
needs: [prepare]
4343
runs-on: ubuntu-latest
44-
strategy:
45-
fail-fast: false
46-
matrix:
47-
include:
48-
- { file: Dockerfile, maintag: latest, prefix: }
49-
- { file: Dockerfile.dev, maintag: dev, prefix: dev- }
5044
steps:
5145
- uses: actions/checkout@v4
5246
with:
@@ -62,22 +56,29 @@ jobs:
6256
with:
6357
context: .
6458
push: ${{inputs.push}}
65-
file: ./${{matrix.file}}
59+
file: ./Dockerfile.dev
6660
tags: |
67-
mstorsjo/llvm-mingw:${{matrix.maintag}}
68-
mstorsjo/llvm-mingw:${{matrix.prefix}}${{needs.prepare.outputs.TAG}}
61+
mstorsjo/llvm-mingw:dev
62+
mstorsjo/llvm-mingw:dev-${{needs.prepare.outputs.TAG}}
6963
- name: Inspect Docker images
7064
run: |
7165
docker images
7266
73-
docker-build-toolchain:
67+
docker-build:
7468
needs: [prepare]
7569
runs-on: ubuntu-latest
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
include:
74+
- { file: Dockerfile, key: amd64 }
75+
- { file: Dockerfile.toolchain, platforms: linux/arm64, key: arm64 }
7676
steps:
7777
- uses: actions/checkout@v4
7878
with:
7979
ref: ${{ (inputs.commit != '' && inputs.commit) || inputs.branch }}
8080
- name: Download toolchain
81+
if: ${{matrix.file == 'Dockerfile.toolchain'}}
8182
uses: dawidd6/action-download-artifact@v3
8283
with:
8384
workflow: build.yml
@@ -89,6 +90,7 @@ jobs:
8990
name_is_regexp: true
9091
path: toolchain
9192
- name: Set up QEMU
93+
if: ${{matrix.file == 'Dockerfile.toolchain'}}
9294
uses: docker/setup-qemu-action@v3
9395
- name: Set up Docker Buildx
9496
uses: docker/setup-buildx-action@v3
@@ -100,15 +102,42 @@ jobs:
100102
password: ${{secrets.DOCKER_PASSWORD}}
101103
- name: Build Docker images
102104
uses: docker/build-push-action@v5
105+
id: build
103106
with:
104107
context: .
105-
platforms: linux/arm64
108+
platforms: ${{matrix.platforms}}
106109
push: ${{inputs.push}}
107-
file: ./Dockerfile.toolchain
108-
load: ${{!inputs.push}}
109-
tags: |
110-
mstorsjo/llvm-mingw:latest
111-
mstorsjo/llvm-mingw:${{needs.prepare.outputs.TAG}}
112-
- name: Inspect Docker images
110+
file: ./${{matrix.file}}
111+
outputs: |
112+
type=image,name=mstorsjo/llvm-mingw,push-by-digest=true,name-canonical=true
113+
- name: Write outputs for later steps
114+
uses: cloudposse/github-action-matrix-outputs-write@main
115+
id: out
116+
with:
117+
matrix-step-name: ${{github.job}}
118+
matrix-key: ${{matrix.key}}
119+
outputs: |-
120+
digest: ${{steps.build.outputs.digest}}
121+
122+
docker-create:
123+
needs: [docker-build, prepare]
124+
runs-on: ubuntu-latest
125+
if: ${{inputs.push}}
126+
steps:
127+
- uses: cloudposse/github-action-matrix-outputs-read@main
128+
id: read
129+
with:
130+
matrix-step-name: docker-build
131+
- name: Set up Docker Buildx
132+
uses: docker/setup-buildx-action@v3
133+
- name: Log in to Docker Hub
134+
uses: docker/login-action@v3
135+
with:
136+
username: ${{secrets.DOCKER_USERNAME}}
137+
password: ${{secrets.DOCKER_PASSWORD}}
138+
- name: Create final image
113139
run: |
114-
docker images
140+
set -x
141+
for tag in latest ${{needs.prepare.outputs.TAG}}; do
142+
docker buildx imagetools create -t mstorsjo/llvm-mingw:$tag mstorsjo/llvm-mingw@${{fromJson(steps.read.outputs.result).digest.amd64}} mstorsjo/llvm-mingw@${{fromJson(steps.read.outputs.result).digest.arm64}}
143+
done

0 commit comments

Comments
 (0)