Skip to content

Commit 2742bba

Browse files
authored
Merge pull request #21664 from dvdksn/gha-distributed-build-metadata
build: add tags and multi-registry push to distributed gha example
2 parents c8cc3fa + 391ad34 commit 2742bba

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

content/manuals/build/ci/github-actions/multi-platform.md

+37-9
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ each platform across multiple runners and create manifest list using the
109109

110110
The following workflow will build the image for each platform on a dedicated
111111
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`
113116

114117
This example also uses the [`metadata` action](https://github.com/docker/metadata-action)
115118
to set tags and labels.
@@ -121,7 +124,8 @@ on:
121124
push:
122125
123126
env:
124-
REGISTRY_IMAGE: user/app
127+
DOCKERHUB_REPO: docker-user/my-app
128+
GHCR_REPO: ghcr.io/gh-user/my-app
125129
126130
jobs:
127131
build:
@@ -131,8 +135,6 @@ jobs:
131135
matrix:
132136
platform:
133137
- linux/amd64
134-
- linux/arm/v6
135-
- linux/arm/v7
136138
- linux/arm64
137139
steps:
138140
- name: Prepare
@@ -144,14 +146,23 @@ jobs:
144146
id: meta
145147
uses: docker/metadata-action@v5
146148
with:
147-
images: ${{ env.REGISTRY_IMAGE }}
149+
images: |
150+
${{ env.DOCKERHUB_REPO }}
151+
${{ env.GHCR_REPO }}
148152
149153
- name: Login to Docker Hub
150154
uses: docker/login-action@v3
151155
with:
152156
username: ${{ vars.DOCKERHUB_USERNAME }}
153157
password: ${{ secrets.DOCKERHUB_TOKEN }}
154158
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+
155166
- name: Set up QEMU
156167
uses: docker/setup-qemu-action@v3
157168
@@ -164,7 +175,7 @@ jobs:
164175
with:
165176
platforms: ${{ matrix.platform }}
166177
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
168179
169180
- name: Export digest
170181
run: |
@@ -198,24 +209,41 @@ jobs:
198209
username: ${{ vars.DOCKERHUB_USERNAME }}
199210
password: ${{ secrets.DOCKERHUB_TOKEN }}
200211
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+
201219
- name: Set up Docker Buildx
202220
uses: docker/setup-buildx-action@v3
203221
204222
- name: Docker meta
205223
id: meta
206224
uses: docker/metadata-action@v5
207225
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}}
209234
210235
- name: Create manifest list and push
211236
working-directory: /tmp/digests
212237
run: |
213238
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 ' *)
215242
216243
- name: Inspect image
217244
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 }}
219247
```
220248

221249
### With Bake

0 commit comments

Comments
 (0)