Skip to content

Commit 82581c8

Browse files
committed
build: push by digest and create manifest in last step
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 80c78b2 commit 82581c8

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ jobs:
7979
packages: write # needed for pushing the images to GitHub Packages
8080
id-token: write # needed for signing the images with GitHub OIDC Token
8181
steps:
82+
-
83+
name: Validate
84+
uses: actions/github-script@v7
85+
env:
86+
INPUT_META-IMAGE: ${{ inputs.meta-image }}
87+
with:
88+
script: |
89+
function getInputList(name) {
90+
return core.getInput(name) ? core.getInput(name).split(/[\r?\n,]+/).filter(x => x !== '') : [];
91+
}
92+
if (getInputList('meta-image').length > 1) {
93+
throw new Error('Only one meta-image is allowed');
94+
}
8295
-
8396
name: Set up Docker Buildx
8497
uses: docker/setup-buildx-action@v3
@@ -108,8 +121,7 @@ jobs:
108121
with:
109122
build-args: ${{ inputs.build-args }}
110123
platforms: ${{ inputs.build-platforms }}
111-
tags: ${{ steps.meta.outputs.tags }}
112-
outputs: type=image,oci-artifact=true,push=${{ inputs.push }}
124+
outputs: type=image,"name=${{ inputs.meta-image }}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${{ inputs.push }}
113125
sbom: ${{ inputs.build-sbom }}
114126
labels: ${{ inputs.set-meta-labels && steps.meta.outputs.labels || '' }}
115127
annotations: ${{ inputs.set-meta-annotations && steps.meta.outputs.annotations || '' }}
@@ -198,3 +210,29 @@ jobs:
198210
});
199211
}
200212
}
213+
-
214+
name: Create manifest
215+
if: ${{ inputs.push }}
216+
uses: actions/github-script@v7
217+
env:
218+
INPUT_TAGS: ${{ steps.meta.outputs.tags }}
219+
INPUT_IMAGE-DIGEST: ${{ steps.build.outputs.digest }}
220+
with:
221+
script: |
222+
function getInputList(name) {
223+
return core.getInput(name) ? core.getInput(name).split(/[\r?\n,]+/).filter(x => x !== '') : [];
224+
}
225+
226+
let createArgs = ['buildx', 'imagetools', 'create'];
227+
for (const tag of getInputList('tags')) {
228+
createArgs.push('-t', tag);
229+
}
230+
createArgs.push(core.getInput('image-digest'));
231+
232+
await exec.getExecOutput('docker', createArgs, {
233+
ignoreReturnCode: true
234+
}).then(res => {
235+
if (res.stderr.length > 0 && res.exitCode != 0) {
236+
throw new Error(res.stderr);
237+
}
238+
});

0 commit comments

Comments
 (0)