Skip to content

Commit c169ae7

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

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

.github/workflows/.test.yml

Lines changed: 62 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.exec(cmd);
92+
}
93+
6294
build-ghcr:
6395
uses: ./.github/workflows/build.yml
6496
permissions:
@@ -154,3 +186,33 @@ 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: Install Cosign
197+
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
198+
with:
199+
cosign-release: ${{ needs.build-local.outputs.cosign-version }}
200+
-
201+
name: Download artifact
202+
uses: actions/download-artifact@v5
203+
with:
204+
name: ${{ needs.build-local.outputs.artifact-name }}
205+
-
206+
name: Verify signatures
207+
uses: actions/github-script@v8
208+
env:
209+
INPUT_COSIGN-VERSION: ${{ needs.build-local.outputs.cosign-version }}
210+
INPUT_COSIGN-VERIFY-COMMANDS: ${{ needs.build-local.outputs.cosign-verify-commands }}
211+
with:
212+
script: |
213+
const cosignVersion = core.getInput('cosign-version');
214+
core.info(`Cosign version used by Docker GitHub Builder: ${cosignVersion}`);
215+
const cosignVerifyCommands = core.getMultilineInput('cosign-verify-commands');
216+
for (const cmd of cosignVerifyCommands) {
217+
await exec.exec(cmd);
218+
}

.github/workflows/build.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,30 @@ 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 }}
118+
artifact-name:
119+
description: Name of the uploaded artifact (for local output)
120+
value: ${{ jobs.build.outputs.artifact-name }}
111121

112122
env:
113123
DOCKER_ACTIONS_TOOLKIT_MODULE: "@docker/actions-toolkit@0.67.0"
114124
COSIGN_VERSION: "v3.0.2"
115125
LOCAL_EXPORT_DIR: "/tmp/buildx-output"
126+
LOCAL_ARTIFACT_NAME: "docker-github-builder-assets"
116127

117128
jobs:
118129
build:
119130
runs-on: ubuntu-latest
131+
outputs:
132+
cosign-version: ${{ env.COSIGN_VERSION }}
133+
cosign-verify-commands: ${{ steps.signing-attestation-manifests.outputs.verify-commands || steps.signing-local-artifacts.outputs.verify-commands }}
134+
artifact-name: ${{ env.LOCAL_ARTIFACT_NAME }}
120135
permissions:
121136
contents: read
122137
id-token: write # needed for signing the images with GitHub OIDC Token
@@ -266,6 +281,7 @@ jobs:
266281
await cosign.printVersion();
267282
-
268283
name: Signing attestation manifests
284+
id: signing-attestation-manifests
269285
if: ${{ inputs.output == 'registry' }}
270286
uses: actions/github-script@v8
271287
env:
@@ -288,8 +304,19 @@ jobs:
288304
{ certificateIdentityRegexp: `^https://github.com/docker/github-builder-experimental/.github/workflows/build.yml.*$` },
289305
signResults
290306
);
307+
308+
await core.group(`Verify commands`, async () => {
309+
const verifyCommands = [];
310+
for (const [attestationRef, verifyResult] of Object.entries(verifyResults)) {
311+
const cmd = `cosign ${verifyResult.cosignArgs.join(' ')} ${attestationRef}`;
312+
core.info(cmd);
313+
verifyCommands.push(cmd);
314+
}
315+
core.setOutput('verify-commands', verifyCommands.join('\n'));
316+
});
291317
-
292318
name: Signing local artifacts
319+
id: signing-local-artifacts
293320
if: ${{ inputs.output == 'local' }}
294321
uses: actions/github-script@v8
295322
env:
@@ -309,6 +336,16 @@ jobs:
309336
{ certificateIdentityRegexp: `^https://github.com/docker/github-builder-experimental/.github/workflows/build.yml.*$` },
310337
signResults
311338
);
339+
340+
await core.group(`Verify commands`, async () => {
341+
const verifyCommands = [];
342+
for (const [artifactPath, verifyResult] of Object.entries(verifyResults)) {
343+
const cmd = `cosign ${verifyResult.cosignArgs.join(' ')} --bundle ${path.relative(inplocalExportDir, verifyResult.bundlePath)} ${path.relative(inplocalExportDir, artifactPath)}`;
344+
core.info(cmd);
345+
verifyCommands.push(cmd);
346+
}
347+
core.setOutput('verify-commands', verifyCommands.join('\n'));
348+
});
312349
-
313350
name: Create manifest
314351
if: ${{ inputs.output == 'registry' }}
@@ -343,6 +380,6 @@ jobs:
343380
if: ${{ inputs.output == 'local' }}
344381
uses: actions/upload-artifact@v5
345382
with:
346-
name: docker-github-builder-assets
383+
name: ${{ env.LOCAL_ARTIFACT_NAME }}
347384
path: ${{ env.LOCAL_EXPORT_DIR }}
348385
if-no-files-found: error

0 commit comments

Comments
 (0)