Skip to content

Commit c22f37d

Browse files
authored
fix multiplatform builds (#6)
refs BerkeleyLibrary/gha-testing#3
1 parent e165fe4 commit c22f37d

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
runner:
23-
- ubuntu-24.04
24-
- ubuntu-24.04-arm
22+
include:
23+
- platform: linux/amd64
24+
runner: ubuntu-24.04
25+
- platform: linux/arm64
26+
runner: ubuntu-24.04-arm
2527
steps:
2628
- name: Checkout code
2729
uses: actions/checkout@v4
@@ -37,15 +39,15 @@ jobs:
3739
password: ${{ secrets.GITHUB_TOKEN }}
3840

3941
- id: build-meta
40-
name: Docker meta
42+
name: Prepare Docker metadata
4143
uses: docker/metadata-action@v5
4244
with:
4345
images: ghcr.io/${{ github.repository }}
4446
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
4547

4648
# Build cache is shared among all builds of the same architecture
4749
- id: cache-meta
48-
name: Docker meta
50+
name: Fetch build cache metadata
4951
uses: docker/metadata-action@v5
5052
with:
5153
images: ghcr.io/${{ github.repository }}
@@ -60,6 +62,7 @@ jobs:
6062
name: Build/push the arch-specific image
6163
uses: docker/build-push-action@v6
6264
with:
65+
platforms: ${{ matrix.platform }}
6366
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
6467
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
6568
labels: ${{ steps.build-meta.outputs.labels }}
@@ -74,13 +77,15 @@ jobs:
7477
echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
7578
7679
merge:
77-
runs-on: ubuntu-24.04
80+
runs-on: ubuntu-latest
7881
needs: build
7982
env:
8083
DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.image-arm64 }}
8184
DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.image-x64 }}
8285
outputs:
8386
image: ${{ steps.meta.outputs.tags }}
87+
build-image-arm64: ${{ needs.build.outputs.image-arm64 }}
88+
build-image-x64: ${{ needs.build.outputs.image-x64 }}
8489
steps:
8590
- name: Checkout code
8691
uses: actions/checkout@v4
@@ -100,7 +105,8 @@ jobs:
100105
uses: docker/metadata-action@v5
101106
with:
102107
images: ghcr.io/${{ github.repository }}
103-
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
108+
tags: |
109+
type=sha,suffix=-build-${{ github.run_id }}_${{ github.run_attempt }}
104110
105111
- name: Push the multi-platform app image
106112
run: |
@@ -109,7 +115,7 @@ jobs:
109115
"$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64"
110116
111117
test:
112-
runs-on: ubuntu-24.04
118+
runs-on: ubuntu-latest
113119
needs: merge
114120
env:
115121
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
@@ -137,16 +143,21 @@ jobs:
137143
docker compose exec app test/test.sh
138144
139145
push:
140-
runs-on: ubuntu-24.04
146+
runs-on: ubuntu-latest
141147
needs:
142148
- merge
143149
- test
144150
env:
145151
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
152+
DOCKER_APP_IMAGE_ARM64: ${{ needs.merge.outputs.build-image-arm64 }}
153+
DOCKER_APP_IMAGE_X64: ${{ needs.merge.outputs.build-image-x64 }}
146154
steps:
147155
- name: Checkout code
148156
uses: actions/checkout@v4
149157

158+
- name: Set up Docker Buildx
159+
uses: docker/setup-buildx-action@v3
160+
150161
- name: Login to GitHub Container Registry
151162
uses: docker/login-action@v3
152163
with:
@@ -165,6 +176,5 @@ jobs:
165176
166177
- name: Retag and push the image
167178
run: |
168-
docker pull "$DOCKER_APP_IMAGE"
169-
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE"
170-
docker push --all-tags "$(echo "$DOCKER_APP_IMAGE" | cut -f1 -d:)"
179+
docker buildx imagetools create \
180+
$(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $DOCKER_APP_IMAGE_ARM64 $DOCKER_APP_IMAGE_X64

.github/workflows/release.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
env:
3838
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
3939
run: |
40-
docker pull "$BASE_IMAGE"
40+
docker manifest inspect "$BASE_IMAGE"
4141
4242
- name: Produce release tags
4343
id: tag-meta
@@ -51,9 +51,10 @@ jobs:
5151
type=semver,pattern={{major}}.{{minor}}
5252
type=semver,pattern={{version}}
5353
54-
- name: Retag the pulled image
54+
- name: Retag and push image
5555
env:
5656
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
5757
run: |
58-
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$BASE_IMAGE"
59-
docker push --all-tags "$(echo "$BASE_IMAGE" | cut -f1 -d:)"
58+
docker buildx imagetools create \
59+
$(jq -cr '.tags | map("--tag " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
60+
"$(echo "$BASE_IMAGE" | cut -f1 -d:)"

0 commit comments

Comments
 (0)