Skip to content

Commit b95bbed

Browse files
committed
ci: build multi-platform images natively using Github ARM runners
Signed-off-by: Bob Du <[email protected]>
1 parent 35e6e20 commit b95bbed

File tree

1 file changed

+82
-22
lines changed

1 file changed

+82
-22
lines changed

.github/workflows/build_docker.yml

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,97 @@ jobs:
2727
readme-filepath: README.en.md
2828
enable-url-completion: true
2929

30-
build_docker:
31-
name: Build docker
32-
runs-on: ubuntu-latest
30+
build:
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- platform: linux/amd64
36+
os: ubuntu-latest
37+
- platform: linux/arm64
38+
os: ubuntu-24.04-arm
39+
runs-on: ${{ matrix.os }}
3340
steps:
34-
- name: Checkout
35-
uses: actions/checkout@v4
41+
- name: Prepare
42+
run: |
43+
platform=${{ matrix.platform }}
44+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
3645
37-
# Print out all environment variables
38-
- run: |
39-
env
46+
- name: Docker meta
47+
id: meta
48+
uses: docker/metadata-action@v5
49+
with:
50+
images: ${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web
51+
52+
- name: Login to Docker Hub
53+
uses: docker/login-action@v3
54+
with:
55+
username: ${{ secrets.DOCKERHUB_USERNAME }}
56+
password: ${{ secrets.DOCKERHUB_TOKEN }}
4057

41-
- name: Set up QEMU
42-
uses: docker/setup-qemu-action@v3
4358
- name: Set up Docker Buildx
4459
uses: docker/setup-buildx-action@v3
60+
61+
- name: Build and push by digest
62+
id: build
63+
uses: docker/build-push-action@v6
64+
with:
65+
platforms: ${{ matrix.platform }}
66+
labels: ${{ steps.meta.outputs.labels }}
67+
outputs: type=image,name=${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web,push-by-digest=true,name-canonical=true,push=true
68+
69+
- name: Export digest
70+
run: |
71+
mkdir -p ${{ runner.temp }}/digests
72+
digest="${{ steps.build.outputs.digest }}"
73+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
74+
75+
- name: Upload digest
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: digests-${{ env.PLATFORM_PAIR }}
79+
path: ${{ runner.temp }}/digests/*
80+
if-no-files-found: error
81+
retention-days: 1
82+
83+
merge:
84+
runs-on: ubuntu-latest
85+
needs:
86+
- build
87+
steps:
88+
- name: Download digests
89+
uses: actions/download-artifact@v4
90+
with:
91+
path: ${{ runner.temp }}/digests
92+
pattern: digests-*
93+
merge-multiple: true
94+
4595
- name: Login to Docker Hub
4696
uses: docker/login-action@v3
4797
with:
4898
username: ${{ secrets.DOCKERHUB_USERNAME }}
4999
password: ${{ secrets.DOCKERHUB_TOKEN }}
50-
- name: Build and push
51-
id: docker_build
52-
uses: docker/build-push-action@v5
100+
101+
- name: Set up Docker Buildx
102+
uses: docker/setup-buildx-action@v3
103+
104+
- name: Docker meta
105+
id: meta
106+
uses: docker/metadata-action@v5
53107
with:
54-
context: .
55-
push: true
56-
labels: ${{ steps.meta.outputs.labels }}
57-
platforms: linux/amd64,linux/arm64
108+
images: ${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web
58109
tags: |
59-
${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web:${{ github.ref_name }}
60-
${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web:latest
61-
build-args: |
62-
GIT_COMMIT_HASH=${{ github.sha }}
63-
RELEASE_VERSION=${{ github.ref_name }}
110+
type=ref,event=branch
111+
type=ref,event=pr
112+
type=semver,pattern={{version}}
113+
type=semver,pattern={{major}}.{{minor}}
114+
115+
- name: Create manifest list and push
116+
working-directory: ${{ runner.temp }}/digests
117+
run: |
118+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
119+
$(printf '${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web@sha256:%s ' *)
120+
121+
- name: Inspect image
122+
run: |
123+
docker buildx imagetools inspect ${{ vars.DOCKERHUB_NAMESPACE }}/chatgpt-web:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)