1+ name : Build Docker
2+
3+ on :
4+ workflow_call :
5+
6+ env :
7+ DOCKERHUB_REPO : karinjs/karin
8+ GHCR_REPO : ghcr.io/karinjs/karin
9+
10+ jobs :
11+ build :
12+ runs-on : ${{ matrix.os }}
13+ strategy :
14+ matrix :
15+ include :
16+ - platform : linux/amd64
17+ os : ubuntu-latest
18+ - platform : linux/arm64
19+ os : ubuntu-24.04-arm
20+ steps :
21+ - name : 检出代码
22+ uses : actions/checkout@v6
23+
24+ - name : 设置 Buildx
25+ uses : docker/setup-buildx-action@v3
26+
27+ - name : 登录DockerHub
28+ uses : docker/login-action@v3
29+ with :
30+ username : ${{ secrets.DOCKERHUB_USERNAME }}
31+ password : ${{ secrets.DOCKERHUB_PASSWORD }}
32+
33+ - name : 登录GHCR
34+ uses : docker/login-action@v3
35+ with :
36+ registry : ghcr.io
37+ username : ${{ github.repository_owner }}
38+ password : ${{ secrets.GITHUB_TOKEN }}
39+
40+ - uses : docker/build-push-action@v6
41+ with :
42+ push : true
43+ platforms : ${{ matrix.platform }}
44+ tags : |
45+ ${{ env.DOCKERHUB_REPO }}:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
46+ ${{ env.GHCR_REPO }}:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
47+
48+ push :
49+ needs : [build]
50+ runs-on : ubuntu-latest
51+ steps :
52+ - name : 设置 Buildx
53+ uses : docker/setup-buildx-action@v3
54+
55+ - name : 登录DockerHub
56+ uses : docker/login-action@v3
57+ with :
58+ username : ${{ secrets.DOCKERHUB_USERNAME }}
59+ password : ${{ secrets.DOCKERHUB_PASSWORD }}
60+
61+ - name : 登录GHCR
62+ uses : docker/login-action@v3
63+ with :
64+ registry : ghcr.io
65+ username : ${{ github.repository_owner }}
66+ password : ${{ secrets.GITHUB_TOKEN }}
67+
68+ - name : 创建并推送多平台清单
69+ run : |
70+ docker buildx imagetools create \
71+ -t ${{ env.DOCKERHUB_REPO }}:latest \
72+ ${{ env.DOCKERHUB_REPO }}:amd64 \
73+ ${{ env.DOCKERHUB_REPO }}:arm64
74+
75+ docker buildx imagetools create \
76+ -t ${{ env.GHCR_REPO }}:latest \
77+ ${{ env.GHCR_REPO }}:amd64 \
78+ ${{ env.GHCR_REPO }}:arm64
79+
80+ - name : 检查镜像
81+ run : |
82+ docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:latest
83+ docker buildx imagetools inspect ${{ env.GHCR_REPO }}:latest
0 commit comments