1- name : Docker Image CI
1+ name : Docker Multi-Platform Builds
22
33on :
44 push :
99 description : ' Branch to run the workflow on'
1010 required : false
1111 release :
12- types :
13- - created
14-
12+ types : [ created ]
1513
1614jobs :
17- build-and-push :
15+
16+ # -------------------------
17+ # AMD64 Build
18+ # -------------------------
19+ build-amd64 :
1820 runs-on : ubuntu-latest
1921 permissions :
2022 contents : read
2123 packages : write
22-
2324 steps :
2425 - name : Checkout code
2526 uses : actions/checkout@v4
26- with :
27- fetch-depth : 0 # Saves time by not fetching other branches
2827
2928 - name : Set up Docker Buildx
3029 uses : docker/setup-buildx-action@v3
@@ -36,18 +35,111 @@ jobs:
3635 username : ${{ github.repository_owner }}
3736 password : ${{ secrets.GITHUB_TOKEN }}
3837
39- - name : Set lowercase repository name
38+ - name : Normalize repo and sanitize ref
4039 run : |
4140 echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
41+ SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
42+ echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
4243
43- - name : Build and push Docker image
44- id : docker_build
44+ - name : Build and push AMD64 image
4545 uses : docker/build-push-action@v6
4646 with :
4747 context : .
48+ file : Dockerfile
49+ build-args : SOURCE_REPO=https://github.com/${{ github.repository }}
50+ platforms : linux/amd64
4851 push : true
4952 tags : |
50- ghcr.io/${{ env.REPO_LOWER }}:${{ github.ref_name }}
51- ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest', env.REPO_LOWER) || '' }}
53+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64
54+ ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-amd64 ', env.REPO_LOWER) || '' }}
5255 cache-from : type=gha
5356 cache-to : type=gha,mode=max
57+
58+ # -------------------------
59+ # ARM64 Build
60+ # -------------------------
61+ build-arm64 :
62+ runs-on : ubuntu-latest
63+ steps :
64+ - name : Checkout code
65+ uses : actions/checkout@v4
66+
67+ - name : Set up Docker daemon (containerd features)
68+ uses : docker/setup-docker-action@v4
69+ with :
70+ daemon-config : |
71+ {
72+ "debug": true,
73+ "features": { "containerd-snapshotter": true }
74+ }
75+
76+ - name : Set up QEMU
77+ uses : docker/setup-qemu-action@v3
78+
79+ - name : Set up Docker Buildx
80+ uses : docker/setup-buildx-action@v3
81+
82+ - name : Login to GitHub Container Registry
83+ uses : docker/login-action@v3
84+ with :
85+ registry : ghcr.io
86+ username : ${{ github.repository_owner }}
87+ password : ${{ secrets.GITHUB_TOKEN }}
88+
89+ - name : Normalize repo and sanitize ref
90+ run : |
91+ echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
92+ SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
93+ echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
94+
95+ - name : Build and push ARM64 image
96+ uses : docker/build-push-action@v6
97+ with :
98+ context : .
99+ file : Dockerfile
100+ build-args : BUILDKIT_PROGRESS=plain,SOURCE_REPO=https://github.com/${{ github.repository }}
101+ platforms : linux/arm64
102+ push : true
103+ tags : |
104+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64
105+ ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-arm64', env.REPO_LOWER) || '' }}
106+ cache-from : type=gha,scope=arm64
107+ cache-to : type=gha,scope=arm64,mode=max
108+
109+ # -------------------------
110+ # Create multi-arch manifest
111+ # -------------------------
112+ manifest :
113+ needs : [ build-amd64, build-arm64 ]
114+ runs-on : ubuntu-latest
115+ steps :
116+ - name : Set up Docker Buildx (for imagetools)
117+ uses : docker/setup-buildx-action@v3
118+
119+ - name : Login to GitHub Container Registry
120+ uses : docker/login-action@v3
121+ with :
122+ registry : ghcr.io
123+ username : ${{ github.repository_owner }}
124+ password : ${{ secrets.GITHUB_TOKEN }}
125+
126+ - name : Normalize repo and sanitize ref
127+ run : |
128+ echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
129+ SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
130+ echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
131+
132+ - name : Create multi-arch manifest for ref tag
133+ run : |
134+ docker buildx imagetools create \
135+ --tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }} \
136+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 \
137+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64
138+
139+ - name : Also tag :latest on main
140+ if : ${{ github.ref_name == 'main' }}
141+ run : |
142+ docker buildx imagetools create \
143+ --tag ghcr.io/${{ env.REPO_LOWER }}:latest \
144+ ghcr.io/${{ env.REPO_LOWER }}:latest-amd64 \
145+ ghcr.io/${{ env.REPO_LOWER }}:latest-arm64
0 commit comments