1- name : Docker
1+ name : Build and Publish Multi-Platform Docker Image
22
33on :
44 push :
5- branches : ["main", "legacy", "feature/* "]
5+ branches : ["main", "develop "]
66 tags : ["*"]
7- pull_request :
8- branches : ["main"]
9-
10- env :
11- REGISTRY : ghcr.io
12- IMAGE_NAME : ${{ github.repository }}
137
148jobs :
15- build :
9+ build-amd64 :
1610 runs-on : ubuntu-latest
1711 permissions :
1812 contents : read
1913 packages : write
14+ steps :
15+ - name : Checkout repository
16+ uses : actions/checkout@v4
17+
18+ - name : Prepare repository name in lowercase
19+ id : repo
20+ run : echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
21+
22+ - name : Set up Docker Buildx
23+ uses : docker/setup-buildx-action@v3
24+
25+ - name : Log in to the Container registry
26+ uses : docker/login-action@v3
27+ with :
28+ registry : ghcr.io
29+ username : ${{ github.actor }}
30+ password : ${{ secrets.GITHUB_TOKEN }}
31+
32+ - name : Extract metadata
33+ id : meta
34+ uses : docker/metadata-action@v5
35+ with :
36+ images : |
37+ ghcr.io/${{ steps.repo.outputs.name }}
38+ tags : |
39+ type=ref,event=branch,suffix=-amd64
40+ type=ref,event=tag,suffix=-amd64
41+ type=raw,value=latest,suffix=-amd64,enable=${{ startsWith(github.ref, 'refs/tags/') }}
42+
43+ - name : Build and push AMD64 Docker image
44+ uses : docker/build-push-action@v5
45+ with :
46+ context : .
47+ platforms : linux/amd64
48+ push : true
49+ tags : ${{ steps.meta.outputs.tags }}
50+ labels : ${{ steps.meta.outputs.labels }}
51+ cache-from : type=gha
52+ cache-to : type=gha,mode=max
2053
54+ build-arm64 :
55+ runs-on : ubuntu-22.04-arm
56+ permissions :
57+ contents : read
58+ packages : write
2159 steps :
2260 - name : Checkout repository
2361 uses : actions/checkout@v4
2462
63+ - name : Prepare repository name in lowercase
64+ id : repo
65+ run : echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
66+
2567 - name : Set up QEMU
2668 uses : docker/setup-qemu-action@v3
2769
@@ -31,27 +73,68 @@ jobs:
3173 - name : Log in to the Container registry
3274 uses : docker/login-action@v3
3375 with :
34- registry : ${{ env.REGISTRY }}
76+ registry : ghcr.io
3577 username : ${{ github.actor }}
3678 password : ${{ secrets.GITHUB_TOKEN }}
3779
38- - name : Extract metadata (tags, labels) for Docker
80+ - name : Extract metadata
3981 id : meta
4082 uses : docker/metadata-action@v5
4183 with :
42- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
84+ images : |
85+ ghcr.io/${{ steps.repo.outputs.name }}
4386 tags : |
44- type=ref,event=branch
45- type=ref,event=pr
46- type=semver,pattern={{version}}
47- type=semver,pattern={{major}}.{{minor}}
48- type=sha
87+ type=ref,event=branch,suffix=-arm64
88+ type=ref,event=tag,suffix=-arm64
89+ type=raw,value=latest,suffix=-arm64,enable=${{ startsWith(github.ref, 'refs/tags/') }}
4990
50- - name : Build and push Docker image
91+ - name : Build and push ARM64 Docker image
5192 uses : docker/build-push-action@v5
5293 with :
5394 context : .
54- platforms : linux/amd64,linux/ arm64
95+ platforms : linux/arm64
5596 push : true
5697 tags : ${{ steps.meta.outputs.tags }}
5798 labels : ${{ steps.meta.outputs.labels }}
99+ cache-from : type=gha
100+ cache-to : type=gha,mode=max
101+
102+ manifest :
103+ needs : [build-amd64, build-arm64]
104+ runs-on : ubuntu-latest
105+ permissions :
106+ contents : read
107+ packages : write
108+
109+ steps :
110+ - name : Prepare repository name in lowercase
111+ id : repo
112+ run : echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
113+
114+ - name : Log in to the Container registry
115+ uses : docker/login-action@v3
116+ with :
117+ registry : ghcr.io
118+ username : ${{ github.actor }}
119+ password : ${{ secrets.GITHUB_TOKEN }}
120+
121+ - name : Extract metadata for final manifest
122+ id : meta
123+ uses : docker/metadata-action@v5
124+ with :
125+ images : |
126+ ghcr.io/${{ steps.repo.outputs.name }}
127+ tags : |
128+ type=ref,event=branch
129+ type=ref,event=tag
130+ type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
131+
132+ - name : Create and push manifest list
133+ run : |
134+ echo "${{ steps.meta.outputs.tags }}" | while read -r tag; do
135+ if [ -z "$tag" ]; then continue; fi
136+ echo "Creating manifest for ${tag}"
137+ docker buildx imagetools create --tag "${tag}" \
138+ "${tag}-amd64" \
139+ "${tag}-arm64"
140+ done
0 commit comments