1+ name : Build and Push Docker Image
2+
3+ on :
4+ workflow_dispatch :
5+ push :
6+ branches :
7+ - main
8+ - master
9+
10+ permissions :
11+ contents : read
12+ packages : write
13+
14+ jobs :
15+ build-amd64 :
16+ runs-on : runs-on=${{ github.run_id }}/runner=4cpu-linux-x64
17+
18+ steps :
19+ - name : Checkout code
20+ uses : actions/checkout@v4
21+
22+ - name : Set up Docker Buildx
23+ uses : docker/setup-buildx-action@v3
24+
25+ - name : Login to GitHub Container Registry
26+ uses : docker/login-action@v3
27+ with :
28+ registry : ghcr.io
29+ username : ${{ github.repository_owner }}
30+ password : ${{ secrets.GITHUB_TOKEN }}
31+
32+ - name : Build and push (AMD64)
33+ uses : docker/build-push-action@v6
34+ with :
35+ platforms : linux/amd64
36+ context : .
37+ push : true
38+ tags : |
39+ ghcr.io/${{ github.repository }}:latest-amd
40+ ghcr.io/${{ github.repository }}:${{ github.sha }}-amd
41+
42+ build-arm64 :
43+ runs-on : runs-on=${{ github.run_id }}/runner=4cpu-linux-arm64
44+
45+ steps :
46+ - name : Checkout code
47+ uses : actions/checkout@v4
48+
49+ - name : Set up Docker Buildx
50+ uses : docker/setup-buildx-action@v3
51+
52+ - name : Login to GitHub Container Registry
53+ uses : docker/login-action@v3
54+ with :
55+ registry : ghcr.io
56+ username : ${{ github.repository_owner }}
57+ password : ${{ secrets.GITHUB_TOKEN }}
58+
59+ - name : Build and push (ARM64)
60+ uses : docker/build-push-action@v6
61+ with :
62+ platforms : linux/arm64
63+ context : .
64+ push : true
65+ tags : |
66+ ghcr.io/${{ github.repository }}:latest-arm
67+ ghcr.io/${{ github.repository }}:${{ github.sha }}-arm
68+
69+ build-merge :
70+ runs-on : ubuntu-latest
71+
72+ needs :
73+ - build-amd64
74+ - build-arm64
75+
76+ steps :
77+ - name : Set up Docker Buildx
78+ uses : docker/setup-buildx-action@v3
79+
80+ - name : Login to GHCR
81+ uses : docker/login-action@v3
82+ with :
83+ registry : ghcr.io
84+ username : ${{ github.repository_owner }}
85+ password : ${{ secrets.GITHUB_TOKEN }}
86+
87+ - name : Merge
88+ run : |
89+ docker buildx imagetools create -t ghcr.io/${{ github.repository }}:latest \
90+ ghcr.io/${{ github.repository }}:latest-amd \
91+ ghcr.io/${{ github.repository }}:latest-arm
0 commit comments