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,114 @@ 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.x86_64
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 (manual / self-hosted)
60+ # -------------------------
61+ build-arm64 :
62+ # if: ${{ github.event_name == 'workflow_dispatch' }} # manual trigger only
63+ # runs-on: [self-hosted, arm64] # use if you have an ARM64 runner
64+ runs-on : ubuntu-latest
65+ steps :
66+ - name : Checkout code
67+ uses : actions/checkout@v4
68+
69+ - name : Set up Docker daemon (containerd features)
70+ uses : docker/setup-docker-action@v4
71+ with :
72+ daemon-config : |
73+ {
74+ "debug": true,
75+ "features": { "containerd-snapshotter": true }
76+ }
77+
78+ - name : Set up QEMU
79+ uses : docker/setup-qemu-action@v3
80+
81+ - name : Set up Docker Buildx
82+ uses : docker/setup-buildx-action@v3
83+
84+ - name : Login to GitHub Container Registry
85+ uses : docker/login-action@v3
86+ with :
87+ registry : ghcr.io
88+ username : ${{ github.repository_owner }}
89+ password : ${{ secrets.GITHUB_TOKEN }}
90+
91+ - name : Normalize repo and sanitize ref
92+ run : |
93+ echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
94+ SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
95+ echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
96+
97+ - name : Build and push ARM64 image
98+ uses : docker/build-push-action@v6
99+ with :
100+ context : .
101+ file : Dockerfile.arm64
102+ build-args : BUILDKIT_PROGRESS=plain,SOURCE_REPO=https://github.com/${{ github.repository }}
103+ platforms : linux/arm64
104+ push : true
105+ tags : |
106+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64
107+ ${{ github.ref_name == 'main' && format('ghcr.io/{0}:latest-arm64', env.REPO_LOWER) || '' }}
108+ cache-from : type=gha,scope=arm64
109+ cache-to : type=gha,scope=arm64,mode=max
110+
111+ # -------------------------
112+ # Create multi-arch manifest
113+ # -------------------------
114+ manifest :
115+ # if: ${{ github.event_name == 'workflow_dispatch' }} # only when both images are built
116+ needs : [ build-amd64, build-arm64 ]
117+ runs-on : ubuntu-latest
118+ steps :
119+ - name : Set up Docker Buildx (for imagetools)
120+ uses : docker/setup-buildx-action@v3
121+
122+ - name : Login to GitHub Container Registry
123+ uses : docker/login-action@v3
124+ with :
125+ registry : ghcr.io
126+ username : ${{ github.repository_owner }}
127+ password : ${{ secrets.GITHUB_TOKEN }}
128+
129+ - name : Normalize repo and sanitize ref
130+ run : |
131+ echo "REPO_LOWER=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
132+ SAFE_REF=$(echo "${GITHUB_REF_NAME}" | tr / -)
133+ echo "SAFE_REF=$SAFE_REF" >> $GITHUB_ENV
134+
135+ - name : Create multi-arch manifest for ref tag
136+ run : |
137+ docker buildx imagetools create \
138+ --tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }} \
139+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-amd64 \
140+ ghcr.io/${{ env.REPO_LOWER }}:${{ env.SAFE_REF }}-arm64
141+
142+ - name : Also tag :latest on main
143+ if : ${{ github.ref_name == 'main' }}
144+ run : |
145+ docker buildx imagetools create \
146+ --tag ghcr.io/${{ env.REPO_LOWER }}:latest \
147+ ghcr.io/${{ env.REPO_LOWER }}:latest-amd64 \
148+ ghcr.io/${{ env.REPO_LOWER }}:latest-arm64
0 commit comments