Skip to content

Commit 94a1349

Browse files
committed
add image-digest output to return pushed digest on manifest creation
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 803057a commit 94a1349

File tree

2 files changed

+60
-14
lines changed

2 files changed

+60
-14
lines changed

.github/workflows/bake.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ on:
138138
artifact-name:
139139
description: "Name of the uploaded artifact (for local output)"
140140
value: ${{ jobs.finalize.outputs.artifact-name }}
141+
image-digest:
142+
description: "Digest of the built image (for image output if pushed)"
143+
value: ${{ jobs.finalize.outputs.image-digest }}
141144
output-type:
142145
description: "Build output type"
143146
value: ${{ jobs.finalize.outputs.output-type }}
@@ -904,12 +907,21 @@ jobs:
904907
cosign-version: ${{ env.COSIGN_VERSION }}
905908
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
906909
artifact-name: ${{ inputs.artifact-upload && inputs.artifact-name || '' }}
910+
image-digest: ${{ steps.manifest.outputs.digest }}
907911
output-type: ${{ inputs.output }}
908912
signed: ${{ needs.prepare.outputs.sign }}
909913
needs:
910914
- prepare
911915
- build
912916
steps:
917+
-
918+
name: Install @docker/actions-toolkit
919+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
920+
env:
921+
INPUT_DAT-MODULE: ${{ env.DOCKER_ACTIONS_TOOLKIT_MODULE }}
922+
with:
923+
script: |
924+
await exec.exec('npm', ['install', '--prefer-offline', '--ignore-scripts', core.getInput('dat-module')]);
913925
-
914926
name: Docker meta
915927
id: meta
@@ -941,6 +953,7 @@ jobs:
941953
cache-binary: false
942954
-
943955
name: Create manifest
956+
id: manifest
944957
if: ${{ inputs.output == 'image' }}
945958
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
946959
env:
@@ -950,6 +963,8 @@ jobs:
950963
INPUT_BUILD-OUTPUTS: ${{ toJSON(needs.build.outputs) }}
951964
with:
952965
script: |
966+
const { ImageTools } = require('@docker/actions-toolkit/lib/buildx/imagetools');
967+
953968
const inpPush = core.getBooleanInput('push');
954969
const inpImageNames = core.getMultilineInput('image-names');
955970
const inpTagNames = core.getMultilineInput('tag-names');
@@ -967,21 +982,29 @@ jobs:
967982
return;
968983
}
969984
985+
const tags = [];
970986
for (const imageName of inpImageNames) {
987+
for (const tag of inpTagNames) {
988+
tags.push(`${imageName}:${tag}`);
989+
}
990+
}
991+
992+
if (inpPush) {
993+
const result = await new ImageTools().create({
994+
sources: digests,
995+
tags: tags
996+
});
997+
core.info(`Created manifest with digest: ${result.digest}`);
998+
core.setOutput('digest', result.digest);
999+
} else {
9711000
let createArgs = ['buildx', 'imagetools', 'create'];
9721001
for (const tag of inpTagNames) {
9731002
createArgs.push('-t', `${imageName}:${tag}`);
9741003
}
9751004
for (const digest of digests) {
9761005
createArgs.push(digest);
9771006
}
978-
if (inpPush) {
979-
await exec.exec('docker', createArgs);
980-
} else {
981-
await core.group(`Generated imagetools create command for ${imageName}`, async () => {
982-
core.info(`docker ${createArgs.join(' ')}`);
983-
});
984-
}
1007+
core.info(`Generated command: docker ${createArgs.join(' ')}`);
9851008
}
9861009
-
9871010
name: Merge artifacts

.github/workflows/build.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ on:
141141
artifact-name:
142142
description: "Name of the uploaded artifact (for local output)"
143143
value: ${{ jobs.finalize.outputs.artifact-name }}
144+
image-digest:
145+
description: "Digest of the built image (for image output if pushed)"
146+
value: ${{ jobs.finalize.outputs.image-digest }}
144147
output-type:
145148
description: "Build output type"
146149
value: ${{ jobs.finalize.outputs.output-type }}
@@ -758,12 +761,21 @@ jobs:
758761
cosign-version: ${{ env.COSIGN_VERSION }}
759762
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
760763
artifact-name: ${{ inputs.artifact-upload && inputs.artifact-name || '' }}
764+
image-digest: ${{ steps.manifest.outputs.digest }}
761765
output-type: ${{ inputs.output }}
762766
signed: ${{ needs.prepare.outputs.sign }}
763767
needs:
764768
- prepare
765769
- build
766770
steps:
771+
-
772+
name: Install @docker/actions-toolkit
773+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
774+
env:
775+
INPUT_DAT-MODULE: ${{ env.DOCKER_ACTIONS_TOOLKIT_MODULE }}
776+
with:
777+
script: |
778+
await exec.exec('npm', ['install', '--prefer-offline', '--ignore-scripts', core.getInput('dat-module')]);
767779
-
768780
name: Docker meta
769781
id: meta
@@ -794,6 +806,7 @@ jobs:
794806
cache-binary: false
795807
-
796808
name: Create manifest
809+
id: manifest
797810
if: ${{ inputs.output == 'image' }}
798811
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
799812
env:
@@ -803,6 +816,8 @@ jobs:
803816
INPUT_BUILD-OUTPUTS: ${{ toJSON(needs.build.outputs) }}
804817
with:
805818
script: |
819+
const { ImageTools } = require('@docker/actions-toolkit/lib/buildx/imagetools');
820+
806821
const inpPush = core.getBooleanInput('push');
807822
const inpImageNames = core.getMultilineInput('image-names');
808823
const inpTagNames = core.getMultilineInput('tag-names');
@@ -820,21 +835,29 @@ jobs:
820835
return;
821836
}
822837
838+
const tags = [];
823839
for (const imageName of inpImageNames) {
840+
for (const tag of inpTagNames) {
841+
tags.push(`${imageName}:${tag}`);
842+
}
843+
}
844+
845+
if (inpPush) {
846+
const result = await new ImageTools().create({
847+
sources: digests,
848+
tags: tags
849+
});
850+
core.info(`Created manifest with digest: ${result.digest}`);
851+
core.setOutput('digest', result.digest);
852+
} else {
824853
let createArgs = ['buildx', 'imagetools', 'create'];
825854
for (const tag of inpTagNames) {
826855
createArgs.push('-t', `${imageName}:${tag}`);
827856
}
828857
for (const digest of digests) {
829858
createArgs.push(digest);
830859
}
831-
if (inpPush) {
832-
await exec.exec('docker', createArgs);
833-
} else {
834-
await core.group(`Generated imagetools create command for ${imageName}`, async () => {
835-
core.info(`docker ${createArgs.join(' ')}`);
836-
});
837-
}
860+
core.info(`Generated command: docker ${createArgs.join(' ')}`);
838861
}
839862
-
840863
name: Merge artifacts

0 commit comments

Comments
 (0)