Skip to content

Commit 24a3541

Browse files
authored
feat: add docker-build-push-multi-registry (#57)
1 parent 8f94682 commit 24a3541

File tree

2 files changed

+193
-6
lines changed

2 files changed

+193
-6
lines changed

Diff for: .github/workflows/docker-build-push-multi-platform.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ jobs:
105105

106106
- name: Export digest
107107
run: |
108-
mkdir -p /tmp/digests
108+
mkdir -p ${{ runner.temp }}/digests
109109
digest="${{ steps.build.outputs.digest }}"
110-
touch "/tmp/digests/${digest#sha256:}"
110+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
111111
112112
- name: Upload digest
113113
uses: actions/upload-artifact@v4
114114
with:
115115
name: digests-${{ inputs.build-digest-key }}-${{ env.PLATFORM_PAIR }}
116-
path: /tmp/digests/*
116+
path: ${{ runner.temp }}/digests/*
117117
if-no-files-found: error
118118
retention-days: 1
119119

@@ -125,7 +125,7 @@ jobs:
125125
- name: Download digests
126126
uses: actions/download-artifact@v4
127127
with:
128-
path: /tmp/digests
128+
path: ${{ runner.temp }}/digests
129129
pattern: digests-${{ inputs.build-digest-key }}-*
130130
merge-multiple: true
131131

@@ -136,7 +136,8 @@ jobs:
136136
id: meta
137137
uses: docker/metadata-action@v5
138138
with:
139-
images: ${{ inputs.registry-image }}
139+
images: |
140+
${{ inputs.registry-image }}
140141
tags: |
141142
${{ inputs.metadata-tags }}
142143
@@ -148,7 +149,7 @@ jobs:
148149
password: ${{ secrets.registry-password }}
149150

150151
- name: Create manifest list and push
151-
working-directory: /tmp/digests
152+
working-directory: ${{ runner.temp }}/digests
152153
run: |
153154
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
154155
$(printf '${{ inputs.registry-image }}@sha256:%s ' *)
+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
dockerhub-repo:
5+
description: >-
6+
Docker Hub repository to push the image to.
7+
required: true
8+
type: string
9+
dockerhub-username:
10+
description: >-
11+
Username for authenticating to Docker Hub.
12+
required: true
13+
type: string
14+
quay-repo:
15+
description: >-
16+
Quay repository to push the image to.
17+
required: true
18+
type: string
19+
quay-username:
20+
description: >-
21+
Username for authenticating to Quay.
22+
required: true
23+
type: string
24+
build-context:
25+
description: >-
26+
Build's context is the set of files located in the specified PATH or URL.
27+
type: string
28+
required: false
29+
build-file:
30+
description: >-
31+
Path to the Dockerfile.
32+
type: string
33+
required: false
34+
build-cache-key:
35+
description: >-
36+
An explicit key for a cache entry.
37+
required: false
38+
type: string
39+
default: coatl
40+
build-digest-key:
41+
description: >-
42+
Name of the build digest.
43+
required: false
44+
type: string
45+
default: coatl
46+
metadata-tags:
47+
description: >-
48+
List of tags as key-value pair attributes.
49+
required: false
50+
type: string
51+
latest-tag-flavor:
52+
description: >-
53+
Set the latest tag flavor.
54+
required: false
55+
type: string
56+
default: auto
57+
secrets:
58+
dockerhub-password:
59+
description: >-
60+
Password or personal access token for authenticating against Docker Hub.
61+
required: true
62+
quay-password:
63+
description: >-
64+
Password or personal access token for authenticating against Quay.
65+
required: true
66+
67+
jobs:
68+
build:
69+
runs-on: ${{ matrix.builder.runner-image }}
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
builder:
74+
- runner-image: ubuntu-24.04
75+
platform: linux/amd64
76+
- runner-image: ubuntu-24.04-arm
77+
platform: linux/arm64
78+
steps:
79+
- name: Prepare
80+
run: |
81+
platform=${{ matrix.builder.platform }}
82+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
83+
84+
- name: Docker meta
85+
id: meta
86+
uses: docker/metadata-action@v5
87+
with:
88+
images: |
89+
${{ inputs.dockerhub-repo }}
90+
${{ inputs.quay-repo }}
91+
92+
- name: Login to Docker Hub
93+
uses: docker/login-action@v3
94+
with:
95+
username: ${{ inputs.dockerhub-username }}
96+
password: ${{ secrets.dockerhub-password }}
97+
98+
- name: Login to Quay
99+
uses: docker/login-action@v3
100+
with:
101+
registry: quay.io
102+
username: ${{ inputs.quay-username }}
103+
password: ${{ secrets.quay-password }}
104+
105+
- name: Set up Docker Buildx
106+
uses: docker/setup-buildx-action@v3
107+
108+
- name: Build and push by digest
109+
id: build
110+
uses: docker/build-push-action@v6
111+
with:
112+
cache-from: type=gha,scope=${{ inputs.build-cache-key }}-${{ env.PLATFORM_PAIR }}
113+
cache-to: type=gha,scope=${{ inputs.build-cache-key }}-${{ env.PLATFORM_PAIR }},mode=max
114+
context: ${{ inputs.build-context }}
115+
file: ${{ inputs.build-file }}
116+
labels: ${{ steps.meta.outputs.labels }}
117+
outputs: type=image,"name=${{ inputs.dockerhub-repo }},${{ inputs.quay-repo }}",push-by-digest=true,name-canonical=true,push=true
118+
platforms: ${{ matrix.builder.platform }}
119+
provenance: false
120+
121+
- name: Export digest
122+
run: |
123+
mkdir -p ${{ runner.temp }}/digests
124+
digest="${{ steps.build.outputs.digest }}"
125+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
126+
127+
- name: Upload digest
128+
uses: actions/upload-artifact@v4
129+
with:
130+
name: digests-${{ inputs.build-digest-key }}-${{ env.PLATFORM_PAIR }}
131+
path: ${{ runner.temp }}/digests/*
132+
if-no-files-found: error
133+
retention-days: 1
134+
135+
merge:
136+
runs-on: ubuntu-latest
137+
needs:
138+
- build
139+
steps:
140+
- name: Download digests
141+
uses: actions/download-artifact@v4
142+
with:
143+
path: ${{ runner.temp }}/digests
144+
pattern: digests-${{ inputs.build-digest-key }}-*
145+
merge-multiple: true
146+
147+
- name: Login to Docker Hub
148+
uses: docker/login-action@v3
149+
with:
150+
username: ${{ inputs.dockerhub-username }}
151+
password: ${{ secrets.dockerhub-password }}
152+
153+
- name: Login to Quay
154+
uses: docker/login-action@v3
155+
with:
156+
registry: quay.io
157+
username: ${{ inputs.quay-username }}
158+
password: ${{ secrets.quay-password }}
159+
160+
- name: Set up Docker Buildx
161+
uses: docker/setup-buildx-action@v3
162+
163+
- name: Docker meta
164+
id: meta
165+
uses: docker/metadata-action@v5
166+
with:
167+
images: |
168+
${{ inputs.dockerhub-repo }}
169+
${{ inputs.quay-repo }}
170+
tags: |
171+
${{ inputs.metadata-tags }}
172+
flavor: |
173+
latest=${{ inputs.latest-tag-flavor }}
174+
175+
- name: Create manifest list and push
176+
working-directory: ${{ runner.temp }}/digests
177+
run: |
178+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
179+
$(printf '${{ inputs.dockerhub-repo }}@sha256:%s ' *)
180+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
181+
$(printf '${{ inputs.quay-repo }}@sha256:%s ' *)
182+
183+
- name: Inspect image
184+
run: |
185+
docker buildx imagetools inspect ${{ inputs.dockerhub-repo }}:${{ steps.meta.outputs.version }}
186+
docker buildx imagetools inspect ${{ inputs.quay-repo }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)