@@ -109,7 +109,10 @@ each platform across multiple runners and create manifest list using the
109
109
110
110
The following workflow will build the image for each platform on a dedicated
111
111
runner using a matrix strategy and push by digest. Then, the `merge` job will
112
- create a manifest list and push it to Docker Hub.
112
+ create manifest lists and push them to two registries :
113
+
114
+ - Docker Hub : ` docker.io/docker-user/my-app`
115
+ - GitHub Container Registry : ` ghcr.io/gh-user/my-app`
113
116
114
117
This example also uses the [`metadata` action](https://github.com/docker/metadata-action)
115
118
to set tags and labels.
121
124
push:
122
125
123
126
env:
124
- REGISTRY_IMAGE: user/app
127
+ DOCKERHUB_REPO: docker-user/my-app
128
+ GHCR_REPO: ghcr.io/gh-user/my-app
125
129
126
130
jobs:
127
131
build:
@@ -131,8 +135,6 @@ jobs:
131
135
matrix:
132
136
platform:
133
137
- linux/amd64
134
- - linux/arm/v6
135
- - linux/arm/v7
136
138
- linux/arm64
137
139
steps:
138
140
- name: Prepare
@@ -144,14 +146,23 @@ jobs:
144
146
id: meta
145
147
uses: docker/metadata-action@v5
146
148
with:
147
- images: ${{ env.REGISTRY_IMAGE }}
149
+ images: |
150
+ ${{ env.DOCKERHUB_REPO }}
151
+ ${{ env.GHCR_REPO }}
148
152
149
153
- name: Login to Docker Hub
150
154
uses: docker/login-action@v3
151
155
with:
152
156
username: ${{ vars.DOCKERHUB_USERNAME }}
153
157
password: ${{ secrets.DOCKERHUB_TOKEN }}
154
158
159
+ - name: Login to GHCR
160
+ uses: docker/login-action@v3
161
+ with:
162
+ registry: ghcr.io
163
+ username: ${{ github.repository_owner }}
164
+ password: ${{ secrets.GITHUB_TOKEN }}
165
+
155
166
- name: Set up QEMU
156
167
uses: docker/setup-qemu-action@v3
157
168
@@ -164,7 +175,7 @@ jobs:
164
175
with:
165
176
platforms: ${{ matrix.platform }}
166
177
labels: ${{ steps.meta.outputs.labels }}
167
- outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
178
+ outputs: type=image," name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}" ,push-by-digest=true,name-canonical=true,push=true
168
179
169
180
- name: Export digest
170
181
run: |
@@ -198,24 +209,41 @@ jobs:
198
209
username: ${{ vars.DOCKERHUB_USERNAME }}
199
210
password: ${{ secrets.DOCKERHUB_TOKEN }}
200
211
212
+ - name: Login to GHCR
213
+ uses: docker/login-action@v3
214
+ with:
215
+ registry: ghcr.io
216
+ username: ${{ github.repository_owner }}
217
+ password: ${{ secrets.GITHUB_TOKEN }}
218
+
201
219
- name: Set up Docker Buildx
202
220
uses: docker/setup-buildx-action@v3
203
221
204
222
- name: Docker meta
205
223
id: meta
206
224
uses: docker/metadata-action@v5
207
225
with:
208
- images: ${{ env.REGISTRY_IMAGE }}
226
+ images: |
227
+ ${{ env.DOCKERHUB_REPO }}
228
+ ${{ env.GHCR_REPO }}
229
+ tags: |
230
+ type=ref,event=branch
231
+ type=ref,event=pr
232
+ type=semver,pattern={{version}}
233
+ type=semver,pattern={{major}}.{{minor}}
209
234
210
235
- name: Create manifest list and push
211
236
working-directory: /tmp/digests
212
237
run: |
213
238
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
214
- $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
239
+ $(printf '${{ env.DOCKERHUB_REPO }}@sha256:%s ' *)
240
+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
241
+ $(printf '${{ env.GHCR_REPO }}@sha256:%s ' *)
215
242
216
243
- name: Inspect image
217
244
run: |
218
- docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
245
+ docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.version }}
246
+ docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }}
219
247
` ` `
220
248
221
249
# ## With Bake
0 commit comments