Skip to content

Commit 95c9483

Browse files
committed
build: set cosign version and verify commands as outputs
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent ec89399 commit 95c9483

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.github/workflows/.test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,38 @@ jobs:
5959
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
6060
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6161
62+
build-aws-verify:
63+
runs-on: ubuntu-latest
64+
needs:
65+
- build-aws
66+
steps:
67+
-
68+
name: Install Cosign
69+
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
70+
with:
71+
cosign-release: ${{ needs.build-aws.outputs.cosign-version }}
72+
-
73+
name: Login to registry
74+
uses: docker/login-action@v3
75+
with:
76+
registry: public.ecr.aws
77+
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
78+
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
79+
-
80+
name: Verify signatures
81+
uses: actions/github-script@v8
82+
env:
83+
INPUT_COSIGN-VERSION: ${{ needs.build-aws.outputs.cosign-version }}
84+
INPUT_COSIGN-VERIFY-COMMANDS: ${{ needs.build-aws.outputs.cosign-verify-commands }}
85+
with:
86+
script: |
87+
const cosignVersion = core.getInput('cosign-version');
88+
core.info(`Cosign version used by Docker GitHub Builder: ${cosignVersion}`);
89+
const cosignVerifyCommands = core.getMultilineInput('cosign-verify-commands');
90+
for (const cmd of cosignVerifyCommands) {
91+
await exec(cmd);
92+
}
93+
6294
build-ghcr:
6395
uses: ./.github/workflows/build.yml
6496
permissions:
@@ -154,3 +186,12 @@ jobs:
154186
build-file: test/hello.Dockerfile
155187
build-sbom: true
156188
build-platforms: linux/amd64,linux/arm64
189+
190+
build-local-verify:
191+
runs-on: ubuntu-latest
192+
needs:
193+
- build-local
194+
steps:
195+
-
196+
name: Show output
197+
run: echo "Image SHA is ${{ needs.call-reusable.outputs.build_sha }}"

.github/workflows/build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ on:
108108
github-token:
109109
description: "GitHub Token used to authenticate against a repository for Git context"
110110
required: false
111+
outputs:
112+
cosign-version:
113+
description: Cosign version used for verification
114+
value: ${{ jobs.build.outputs.cosign-version }}
115+
cosign-verify-commands:
116+
description: Cosign verify commands
117+
value: ${{ jobs.build.outputs.cosign-verify-commands }}
111118

112119
env:
113120
DOCKER_ACTIONS_TOOLKIT_MODULE: "@docker/actions-toolkit@0.67.0"
@@ -117,6 +124,9 @@ env:
117124
jobs:
118125
build:
119126
runs-on: ubuntu-latest
127+
outputs:
128+
cosign-version: ${{ env.COSIGN_VERSION }}
129+
cosign-verify-commands: ${{ steps.signing-attestation-manifests.outputs.verify-commands || steps.signing-local-artifacts.outputs.verify-commands }}
120130
permissions:
121131
contents: read
122132
id-token: write # needed for signing the images with GitHub OIDC Token
@@ -266,6 +276,7 @@ jobs:
266276
await cosign.printVersion();
267277
-
268278
name: Signing attestation manifests
279+
id: signing-attestation-manifests
269280
if: ${{ inputs.output == 'registry' }}
270281
uses: actions/github-script@v8
271282
env:
@@ -288,8 +299,19 @@ jobs:
288299
{ certificateIdentityRegexp: `^https://github.com/docker/github-builder-experimental/.github/workflows/build.yml.*$` },
289300
signResults
290301
);
302+
303+
await core.group(`Verify commands`, async () => {
304+
const verifyCommands = [];
305+
for (const [attestationRef, verifyResult] of Object.entries(verifyResults)) {
306+
const cmd = `cosign ${verifyResult.cosignArgs.join(' ')} ${attestationRef}`;
307+
core.info(cmd);
308+
verifyCommands.push(cmd);
309+
}
310+
core.setOutput('verify-commands', verifyCommands.join('\n'));
311+
});
291312
-
292313
name: Signing local artifacts
314+
id: signing-local-artifacts
293315
if: ${{ inputs.output == 'local' }}
294316
uses: actions/github-script@v8
295317
env:
@@ -309,6 +331,16 @@ jobs:
309331
{ certificateIdentityRegexp: `^https://github.com/docker/github-builder-experimental/.github/workflows/build.yml.*$` },
310332
signResults
311333
);
334+
335+
await core.group(`Verify commands`, async () => {
336+
const verifyCommands = [];
337+
for (const [artifactPath, verifyResult] of Object.entries(verifyResults)) {
338+
const cmd = `cosign ${verifyResult.cosignArgs.join(' ')} --bundle ${path.relative(inplocalExportDir, verifyResult.bundlePath)} ${path.relative(inplocalExportDir, artifactPath)}`;
339+
core.info(cmd);
340+
verifyCommands.push(cmd);
341+
}
342+
core.setOutput('verify-commands', verifyCommands.join('\n'));
343+
});
312344
-
313345
name: Create manifest
314346
if: ${{ inputs.output == 'registry' }}

0 commit comments

Comments
 (0)