Skip to content

Commit c809e63

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 51a156c commit c809e63

File tree

2 files changed

+70
-18
lines changed

2 files changed

+70
-18
lines changed

.github/workflows/bake.yml

Lines changed: 35 additions & 9 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,22 +982,33 @@ jobs:
967982
return;
968983
}
969984
985+
let digest;
970986
for (const imageName of inpImageNames) {
971-
let createArgs = ['buildx', 'imagetools', 'create'];
987+
const tags = [];
972988
for (const tag of inpTagNames) {
973-
createArgs.push('-t', `${imageName}:${tag}`);
974-
}
975-
for (const digest of digests) {
976-
createArgs.push(digest);
989+
tags.push(`${imageName}:${tag}`);
977990
}
978991
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(' ')}`);
992+
const result = await new ImageTools().create({
993+
sources: digests,
994+
tags: tags
983995
});
996+
core.info(`Created manifest with digest: ${result.digest}`);
997+
digest = result.digest;
998+
} else {
999+
let createArgs = ['buildx', 'imagetools', 'create'];
1000+
for (const tag of tags) {
1001+
createArgs.push('-t', tag);
1002+
}
1003+
for (const digest of digests) {
1004+
createArgs.push(digest);
1005+
}
1006+
core.info(`Generated command for ${imageName}: docker ${createArgs.join(' ')}`);
9841007
}
9851008
}
1009+
if (digest) {
1010+
core.setOutput('digest', digest);
1011+
}
9861012
-
9871013
name: Merge artifacts
9881014
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}

.github/workflows/build.yml

Lines changed: 35 additions & 9 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,22 +835,33 @@ jobs:
820835
return;
821836
}
822837
838+
let digest;
823839
for (const imageName of inpImageNames) {
824-
let createArgs = ['buildx', 'imagetools', 'create'];
840+
const tags = [];
825841
for (const tag of inpTagNames) {
826-
createArgs.push('-t', `${imageName}:${tag}`);
827-
}
828-
for (const digest of digests) {
829-
createArgs.push(digest);
842+
tags.push(`${imageName}:${tag}`);
830843
}
831844
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(' ')}`);
845+
const result = await new ImageTools().create({
846+
sources: digests,
847+
tags: tags
836848
});
849+
core.info(`Created manifest with digest: ${result.digest}`);
850+
digest = result.digest;
851+
} else {
852+
let createArgs = ['buildx', 'imagetools', 'create'];
853+
for (const tag of tags) {
854+
createArgs.push('-t', tag);
855+
}
856+
for (const digest of digests) {
857+
createArgs.push(digest);
858+
}
859+
core.info(`Generated command for ${imageName}: docker ${createArgs.join(' ')}`);
837860
}
838861
}
862+
if (digest) {
863+
core.setOutput('digest', digest);
864+
}
839865
-
840866
name: Merge artifacts
841867
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}

0 commit comments

Comments
 (0)