Skip to content

Commit 06282b7

Browse files
authored
Merge pull request #195 from evolvingweb/194-docker-image-doesnt-support-m1-chip
refs #68174: fix ci, support building multi-platform docker images
2 parents 7b45ca7 + 65d81c0 commit 06282b7

File tree

1 file changed

+74
-12
lines changed

1 file changed

+74
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and push to DockerHub
1+
name: "Build and push to DockerHub"
22

33
on:
44
push:
@@ -7,13 +7,27 @@ on:
77

88
env:
99
REGISTRY: docker.io
10-
IMAGE_NAME: ${{ github.repository }}
10+
REGISTRY_IMAGE: ${{ github.repository }}
1111

1212
jobs:
13-
build-deploy:
13+
build:
1414
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
platform:
19+
- linux/amd64
20+
- linux/arm/v6
21+
- linux/arm/v7
22+
- linux/arm64
23+
1524
if: startsWith(github.event.ref, 'refs/tags/v')
1625
steps:
26+
- name: "Prepare"
27+
run: |
28+
platform=${{ matrix.platform }}
29+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
30+
1731
- name: "Check out"
1832
uses: actions/checkout@v4
1933

@@ -31,18 +45,66 @@ jobs:
3145
uses: docker/metadata-action@v5
3246
with:
3347
images: |
34-
${{ env.IMAGE_NAME }}
48+
${{ env.REGISTRY_IMAGE }}
3549
tags: |
3650
type=semver,pattern={{version}}
3751
38-
- name: "Test Docker image"
39-
run: |
40-
docker run --rm -d ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
41-
42-
- name: "Build and push"
52+
- name: Build and push by digest
53+
id: build
4354
uses: docker/build-push-action@v6
4455
with:
45-
context: .
46-
push: true
47-
tags: ${{ steps.meta.outputs.tags }}
56+
platforms: ${{ matrix.platform }}
4857
labels: ${{ steps.meta.outputs.labels }}
58+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
59+
60+
61+
- name: "Export digest"
62+
run: |
63+
mkdir -p /tmp/digests
64+
digest="${{ steps.build.outputs.digest }}"
65+
touch "/tmp/digests/${digest#sha256:}"
66+
67+
- name: "Upload digest"
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: digests-${{ env.PLATFORM_PAIR }}
71+
path: /tmp/digests/*
72+
if-no-files-found: error
73+
retention-days: 1
74+
75+
merge-push:
76+
runs-on: ubuntu-latest
77+
needs:
78+
- build
79+
steps:
80+
- name: "Download digests"
81+
uses: actions/download-artifact@v4
82+
with:
83+
path: /tmp/digests
84+
pattern: digests-*
85+
merge-multiple: true
86+
87+
- name: "Set up Docker Buildx"
88+
uses: docker/setup-buildx-action@v3
89+
90+
- name: "Docker meta"
91+
id: meta
92+
uses: docker/metadata-action@v5
93+
with:
94+
images: ${{ env.REGISTRY_IMAGE }}
95+
96+
- name: "Login to Docker Hub"
97+
uses: docker/login-action@v3
98+
with:
99+
username: ${{ secrets.DOCKERHUB_USERNAME }}
100+
password: ${{ secrets.DOCKERHUB_TOKEN }}
101+
102+
- name: "Create manifest list and push"
103+
working-directory: /tmp/digests
104+
run: |
105+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
106+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
107+
108+
- name: "Inspect image"
109+
run: |
110+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)