forked from docker/github-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
722 lines (690 loc) · 28.8 KB
/
bake.yml
File metadata and controls
722 lines (690 loc) · 28.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
name: bake
on:
workflow_call:
inputs:
context:
type: string
description: "Context to build from (defaults to repository root)"
required: false
default: .
target:
type: string
description: "Target to build"
required: true
default: default
output:
type: string
description: "Build output destination (image or local)"
required: true
artifact-name:
type: string
description: "Name of the uploaded artifact (for local output)"
required: false
default: 'docker-github-builder-assets'
envs:
type: string
description: "Environment variables to set"
required: false
push:
type: boolean
description: "Push image to the registry (for image output) and/or sign attestation manifests or local artifacts"
required: false
default: false
cache:
type: boolean
description: "Enable cache to GitHub Actions cache backend"
required: false
default: false
cache-scope:
type: string
description: "Which scope cache object belongs to if cache enabled (defaults to target name)"
required: false
cache-mode:
type: string
description: "Cache layers to export if cache enabled (min or max)"
required: false
default: 'min'
set-meta-annotations:
type: boolean
description: "Set metadata-action annotations"
required: false
default: false
set-meta-labels:
type: boolean
description: "Set metadata-action labels"
required: false
default: false
setup-qemu:
type: boolean
description: "Install QEMU static binaries"
required: false
default: false
# same as docker/metadata-action inputs (minus sep-tags, sep-labels, sep-annotations, bake-target)
meta-images:
type: string
description: "List of images to use as base name for tags"
required: false
meta-tags:
type: string
description: "List of tags as key-value pair attributes"
required: false
meta-flavor:
type: string
description: "Flavors to apply"
required: false
meta-labels:
type: string
description: "List of custom labels"
required: false
meta-annotations:
type: string
description: "List of custom annotations"
required: false
meta-bake-target:
type: string
description: "Bake target name for metadata (defaults to docker-metadata-action)"
required: false
# same as docker/setup-qemu-action inputs (minus platforms, cache-image)
qemu-image:
type: string
description: "QEMU static binaries Docker image (e.g. tonistiigi/binfmt:latest)"
required: false
# same as docker/bake-action inputs
bake-allow:
type: string
description: "Allow build to access specified resources (e.g., network.host)"
required: false
bake-files:
type: string
description: "List of bake definition files (defaults to docker-bake.hcl)"
required: false
bake-pull:
type: boolean
description: "Always attempt to pull all referenced images"
required: false
default: false
bake-sbom:
type: string
description: "SBOM is a shorthand for --set=*.attest=type=sbom"
required: false
bake-set:
type: string
description: "List of targets values to override (eg. targetpattern.key=value)"
required: false
secrets:
registry-auths:
description: "Registry authentication details as YAML objects"
required: false
github-token:
description: "GitHub Token used to authenticate against a repository for Git context"
required: false
outputs:
cosign-version:
description: Cosign version used for verification
value: ${{ jobs.finalize.outputs.cosign-version }}
cosign-verify-commands:
description: Cosign verify commands
value: ${{ jobs.finalize.outputs.cosign-verify-commands }}
artifact-name:
description: Name of the uploaded artifact (for local output)
value: ${{ jobs.finalize.outputs.artifact-name }}
output-type:
description: Build output type
value: ${{ jobs.finalize.outputs.output-type }}
env:
DOCKER_ACTIONS_TOOLKIT_MODULE: "@docker/actions-toolkit@0.67.0"
COSIGN_VERSION: "v3.0.2"
LOCAL_EXPORT_DIR: "/tmp/buildx-output"
MATRIX_SIZE_LIMIT: "20"
jobs:
prepare:
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
includes: ${{ steps.set.outputs.includes }}
steps:
-
name: Environment variables
uses: actions/github-script@v8
env:
INPUT_ENVS: ${{ inputs.envs }}
with:
script: |
for (const env of core.getMultilineInput('envs')) {
core.info(env);
const [key, value] = env.split('=', 2);
core.exportVariable(key, value);
}
-
name: Install @docker/actions-toolkit
uses: actions/github-script@v8
env:
INPUT_DAT-MODULE: ${{ env.DOCKER_ACTIONS_TOOLKIT_MODULE }}
with:
script: |
await exec.exec('npm', ['install', '--prefer-offline', '--no-audit', core.getInput('dat-module')]);
-
name: Set includes
id: set
uses: actions/github-script@v8
env:
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
INPUT_CONTEXT: ${{ inputs.context }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_BAKE-ALLOW: ${{ inputs.bake-allow }}
INPUT_BAKE-FILES: ${{ inputs.bake-files }}
INPUT_BAKE-PULL: ${{ inputs.bake-pull }}
INPUT_BAKE-SBOM: ${{ inputs.bake-sbom }}
INPUT_BAKE-SET: ${{ inputs.bake-set }}
INPUT_GITHUB-TOKEN: ${{ secrets.github-token || github.token }}
with:
script: |
const os = require('os');
const { Bake } = require('@docker/actions-toolkit/lib/buildx/bake');
const { Util } = require('@docker/actions-toolkit/lib/util');
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
const inpContext = core.getInput('context');
const inpTarget = core.getInput('target');
const inpBakeAllow = core.getInput('bake-allow');
const inpBakeFiles = Util.getInputList('bake-files');
const inpBakePull = core.getBooleanInput('bake-pull');
const inpBakeSbom = core.getInput('bake-sbom');
const inpBakeSet = Util.getInputList('bake-set', {ignoreComma: true, quote: false});
const inpGitHubToken = core.getInput('github-token');
const bakeSource = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}.git#${process.env.GITHUB_REF}:${inpContext}`;
await core.group(`Set bake source`, async () => {
core.info(bakeSource);
});
let def;
let target;
await core.group(`Validating definition`, async () => {
const bake = new Bake();
def = await bake.getDefinition({
allow: inpBakeAllow,
files: inpBakeFiles,
overrides: inpBakeSet,
sbom: inpBakeSbom,
source: bakeSource,
targets: [inpTarget],
githubToken: inpGitHubToken
});
if (!def) {
throw new Error('Bake definition not set');
}
const targets = Object.keys(def.target);
if (targets.length > 1) {
throw new Error(`Only one target can be built at once, found: ${targets.join(', ')}`);
}
target = targets[0];
});
await core.group(`Set includes`, async () => {
let includes = [];
const platforms = def.target[target].platforms || [];
if (platforms.length > inpMatrixSizeLimit) {
throw new Error(`Platforms to build exceed matrix size limit of ${inpMatrixSizeLimit}`);
} else if (platforms.length === 0) {
includes.push({
index: 0,
runner: 'ubuntu-24.04'
});
} else {
platforms.forEach((platform, index) => {
includes.push({
index: index,
platform: platform,
runner: platform.startsWith('linux/arm') ? 'ubuntu-24.04-arm' : 'ubuntu-24.04'
});
});
}
core.info(JSON.stringify(includes, null, 2));
core.setOutput('includes', JSON.stringify(includes));
});
build:
runs-on: ${{ matrix.runner }}
needs:
- prepare
permissions:
contents: read
id-token: write # for signing attestation manifests and/or registry authentication with GitHub OIDC Token
packages: write # for pushing manifests to GHCR if needed
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.prepare.outputs.includes) }}
outputs:
# needs predefined outputs as we can't use dynamic ones atm: https://github.com/actions/runner/pull/2477
# 20 is the maximum number of platforms supported by our matrix strategy
result_0: ${{ steps.result.outputs.result_0 }}
result_1: ${{ steps.result.outputs.result_1 }}
result_2: ${{ steps.result.outputs.result_2 }}
result_3: ${{ steps.result.outputs.result_3 }}
result_4: ${{ steps.result.outputs.result_4 }}
result_5: ${{ steps.result.outputs.result_5 }}
result_6: ${{ steps.result.outputs.result_6 }}
result_7: ${{ steps.result.outputs.result_7 }}
result_8: ${{ steps.result.outputs.result_8 }}
result_9: ${{ steps.result.outputs.result_9 }}
result_10: ${{ steps.result.outputs.result_10 }}
result_11: ${{ steps.result.outputs.result_11 }}
result_12: ${{ steps.result.outputs.result_12 }}
result_13: ${{ steps.result.outputs.result_13 }}
result_14: ${{ steps.result.outputs.result_14 }}
result_15: ${{ steps.result.outputs.result_15 }}
result_16: ${{ steps.result.outputs.result_16 }}
result_17: ${{ steps.result.outputs.result_17 }}
result_18: ${{ steps.result.outputs.result_18 }}
result_19: ${{ steps.result.outputs.result_19 }}
steps:
-
name: Environment variables
uses: actions/github-script@v8
env:
INPUT_ENVS: ${{ inputs.envs }}
with:
script: |
for (const env of core.getMultilineInput('envs')) {
core.info(env);
const [key, value] = env.split('=', 2);
core.exportVariable(key, value);
}
-
name: Install @docker/actions-toolkit
uses: actions/github-script@v8
env:
INPUT_DAT-MODULE: ${{ env.DOCKER_ACTIONS_TOOLKIT_MODULE }}
with:
script: |
await exec.exec('npm', ['install', '--prefer-offline', '--no-audit', core.getInput('dat-module')]);
-
name: Docker meta
id: meta
if: ${{ inputs.output == 'image' }}
uses: docker/metadata-action@v5
with:
images: ${{ inputs.meta-images }}
tags: ${{ inputs.meta-tags }}
flavor: ${{ inputs.meta-flavor }}
labels: ${{ inputs.meta-labels }}
annotations: ${{ inputs.meta-annotations }}
bake-target: ${{ inputs.meta-bake-target }}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: ${{ inputs.setup-qemu }}
with:
image: ${{ inputs.qemu-image }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
buildkitd-flags: --debug
-
name: Prepare
id: prepare
uses: actions/github-script@v8
env:
INPUT_PLATFORM: ${{ matrix.platform }}
INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
INPUT_CONTEXT: ${{ inputs.context }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_OUTPUT: ${{ inputs.output }}
INPUT_PUSH: ${{ inputs.push }}
INPUT_CACHE: ${{ inputs.cache }}
INPUT_CACHE-SCOPE: ${{ inputs.cache-scope }}
INPUT_CACHE-MODE: ${{ inputs.cache-mode }}
INPUT_META-IMAGES: ${{ inputs.meta-images }}
INPUT_SET-META-ANNOTATIONS: ${{ inputs.set-meta-annotations }}
INPUT_SET-META-LABELS: ${{ inputs.set-meta-labels }}
INPUT_BAKE-FILE-TAGS: ${{ steps.meta.outputs.bake-file-tags }}
INPUT_BAKE-FILE-ANNOTATIONS: ${{ steps.meta.outputs.bake-file-annotations }}
INPUT_BAKE-FILE-LABELS: ${{ steps.meta.outputs.bake-file-labels }}
INPUT_BAKE-ALLOW: ${{ inputs.bake-allow }}
INPUT_BAKE-FILES: ${{ inputs.bake-files }}
INPUT_BAKE-PULL: ${{ inputs.bake-pull }}
INPUT_BAKE-SBOM: ${{ inputs.bake-sbom }}
INPUT_BAKE-SET: ${{ inputs.bake-set }}
INPUT_GITHUB-TOKEN: ${{ secrets.github-token || github.token }}
with:
script: |
const os = require('os');
const { Bake } = require('@docker/actions-toolkit/lib/buildx/bake');
const { Util } = require('@docker/actions-toolkit/lib/util');
const inpPlatform = core.getInput('platform');
const platformPairSuffix = inpPlatform ? `-${inpPlatform.replace(/\//g, '-')}` : '';
core.setOutput('platform-pair-suffix', platformPairSuffix);
const inpLocalExportDir = core.getInput('local-export-dir');
const inpContext = core.getInput('context');
const inpTarget = core.getInput('target');
const inpOutput = core.getInput('output');
const inpPush = core.getBooleanInput('push');
const inpCache = core.getBooleanInput('cache');
const inpCacheScope = core.getInput('cache-scope');
const inpCacheMode = core.getInput('cache-mode');
const inpMetaImages = core.getMultilineInput('meta-images');
const inpSetMetaAnnotations = core.getBooleanInput('set-meta-annotations');
const inpSetMetaLabels = core.getBooleanInput('set-meta-labels');
const inpBakeFileTags = core.getInput('bake-file-tags');
const inpBakeFileAnnotations = core.getInput('bake-file-annotations');
const inpBakeFileLabels = core.getInput('bake-file-labels');
const inpBakeAllow = core.getInput('bake-allow');
const inpBakeFiles = Util.getInputList('bake-files');
const inpBakePull = core.getBooleanInput('bake-pull');
const inpBakeSbom = core.getInput('bake-sbom');
const inpBakeSet = Util.getInputList('bake-set', {ignoreComma: true, quote: false});
const inpGitHubToken = core.getInput('github-token');
const bakeSource = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}.git#${process.env.GITHUB_REF}:${inpContext}`;
await core.group(`Set bake source`, async () => {
core.info(bakeSource);
core.setOutput('source', bakeSource);
});
let target;
await core.group(`Validating definition`, async () => {
const bake = new Bake();
const def = await bake.getDefinition({
allow: inpBakeAllow,
files: inpBakeFiles,
overrides: inpBakeSet,
sbom: inpBakeSbom,
source: bakeSource,
targets: [inpTarget],
githubToken: inpGitHubToken
});
if (!def) {
throw new Error('Bake definition not set');
}
const targets = Object.keys(def.target);
if (targets.length > 1) {
throw new Error(`Only one target can be built at once, found: ${targets.join(', ')}`);
}
target = targets[0];
core.setOutput('target', target);
});
let bakeFiles = inpBakeFiles;
await core.group(`Set bake files`, async () => {
if (bakeFiles.length === 0) {
bakeFiles = ['docker-bake.hcl'];
}
if (inpBakeFileTags) {
bakeFiles.push(`cwd://${inpBakeFileTags}`);
}
if (inpSetMetaAnnotations && inpBakeFileAnnotations) {
bakeFiles.push(`cwd://${inpBakeFileAnnotations}`);
}
if (inpSetMetaLabels && inpBakeFileLabels) {
bakeFiles.push(`cwd://${inpBakeFileLabels}`);
}
core.info(JSON.stringify(bakeFiles, null, 2));
core.setOutput('files', bakeFiles.join(os.EOL));
});
let outputOverride = '';
switch (inpOutput) {
case 'image':
if (inpMetaImages.length == 0) {
core.setFailed('meta-images is required when output is image');
}
outputOverride = `*.output=type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`;
break;
case 'local':
outputOverride = `*.output=type=local,platform-split=true,dest=${inpLocalExportDir}`;
break;
default:
core.setFailed(`Invalid output: ${inpOutput}`);
}
let bakeOverrides = [...inpBakeSet, outputOverride];
await core.group(`Set bake overrides`, async () => {
bakeOverrides.push('*.attest=type=provenance,mode=max,version=v1', '*.tags=');
if (inpPlatform) {
bakeOverrides.push(`*.platform=${inpPlatform}`);
}
if (inpCache) {
bakeOverrides.push(`*.cache-from=type=gha,scope=${inpCacheScope || target}${platformPairSuffix}`);
bakeOverrides.push(`*.cache-to=type=gha,scope=${inpCacheScope || target}${platformPairSuffix},mode=${inpCacheMode}`);
}
core.info(JSON.stringify(bakeOverrides, null, 2));
core.setOutput('overrides', bakeOverrides.join(os.EOL));
});
-
name: Login to registry
if: ${{ inputs.push && inputs.output == 'image' }}
# TODO: switch to docker/login-action when OIDC is supported
uses: crazy-max/docker-login-action@dockerhub-oidc
with:
registry-auth: ${{ secrets.registry-auths }}
-
name: Build
id: bake
uses: docker/bake-action@v6
with:
source: ${{ steps.prepare.outputs.source }}
files: ${{ steps.prepare.outputs.files }}
targets: ${{ steps.prepare.outputs.target }}
allow: ${{ inputs.bake-allow }}
pull: ${{ inputs.bake-pull }}
sbom: ${{ inputs.bake-sbom }}
set: ${{ steps.prepare.outputs.overrides }}
github-token: ${{ secrets.github-token || github.token }}
env:
BUILDKIT_MULTI_PLATFORM: 1
-
name: Get image digest
id: get-image-digest
if: ${{ inputs.output == 'image' }}
uses: actions/github-script@v8
env:
INPUT_TARGET: ${{ steps.prepare.outputs.target }}
INPUT_METADATA: ${{ steps.bake.outputs.metadata }}
with:
script: |
const inpTarget = core.getInput('target');
const inpMetadata = JSON.parse(core.getInput('metadata'));
const imageDigest = inpMetadata[inpTarget]['containerimage.digest'];
core.info(imageDigest);
core.setOutput('digest', imageDigest);
-
name: Install Cosign
if: ${{ inputs.push }}
uses: actions/github-script@v8
env:
INPUT_COSIGN-VERSION: ${{ env.COSIGN_VERSION }}
with:
script: |
const { Cosign } = require('@docker/actions-toolkit/lib/cosign/cosign');
const { Install } = require('@docker/actions-toolkit/lib/cosign/install');
const cosignInstall = new Install();
const cosignBinPath = await cosignInstall.download(core.getInput('cosign-version'), false, true);
await cosignInstall.install(cosignBinPath);
const cosign = new Cosign();
await cosign.printVersion();
-
name: Signing attestation manifests
id: signing-attestation-manifests
if: ${{ inputs.push && inputs.output == 'image' }}
uses: actions/github-script@v8
env:
INPUT_IMAGE-NAMES: ${{ inputs.meta-images }}
INPUT_IMAGE-DIGEST: ${{ steps.get-image-digest.outputs.digest }}
with:
script: |
const { Sigstore } = require('@docker/actions-toolkit/lib/sigstore/sigstore');
const inpImageNames = core.getMultilineInput('image-names');
const inpImageDigest = core.getInput('image-digest');
const sigstore = new Sigstore();
const signResults = await sigstore.signAttestationManifests({
imageNames: inpImageNames,
imageDigest: inpImageDigest
});
const verifyResults = await sigstore.verifySignedManifests(
{ certificateIdentityRegexp: `^https://github.com/docker/github-builder-experimental/.github/workflows/bake.yml.*$` },
signResults
);
await core.group(`Verify commands`, async () => {
const verifyCommands = [];
for (const [attestationRef, verifyResult] of Object.entries(verifyResults)) {
const cmd = `cosign ${verifyResult.cosignArgs.join(' ')} ${attestationRef}`;
core.info(cmd);
verifyCommands.push(cmd);
}
core.setOutput('verify-commands', verifyCommands.join('\n'));
});
-
name: Signing local artifacts
id: signing-local-artifacts
if: ${{ inputs.push && inputs.output == 'local' }}
uses: actions/github-script@v8
env:
INPUT_LOCAL-OUTPUT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
with:
script: |
const path = require('path');
const { Sigstore } = require('@docker/actions-toolkit/lib/sigstore/sigstore');
const inplocalExportDir = core.getInput('local-output-dir');
const sigstore = new Sigstore();
const signResults = await sigstore.signProvenanceBlobs({
localExportDir: inplocalExportDir
});
const verifyResults = await sigstore.verifySignedArtifacts(
{ certificateIdentityRegexp: `^https://github.com/docker/github-builder-experimental/.github/workflows/bake.yml.*$` },
signResults
);
await core.group(`Verify commands`, async () => {
const verifyCommands = [];
for (const [artifactPath, verifyResult] of Object.entries(verifyResults)) {
const cmd = `cosign ${verifyResult.cosignArgs.join(' ')} --bundle ${path.relative(inplocalExportDir, verifyResult.bundlePath)} ${path.relative(inplocalExportDir, artifactPath)}`;
core.info(cmd);
verifyCommands.push(cmd);
}
core.setOutput('verify-commands', verifyCommands.join('\n'));
});
-
name: List local output
if: ${{ inputs.output == 'local' }}
run: |
tree -nh ${{ env.LOCAL_EXPORT_DIR }}
-
name: Upload artifact
if: ${{ inputs.output == 'local' }}
uses: actions/upload-artifact@v5
with:
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix }}
path: ${{ env.LOCAL_EXPORT_DIR }}
if-no-files-found: error
-
name: Set result output
id: result
uses: actions/github-script@v8
env:
INPUT_INDEX: ${{ matrix.index }}
INPUT_VERIFY-COMMANDS: ${{ steps.signing-attestation-manifests.outputs.verify-commands || steps.signing-local-artifacts.outputs.verify-commands }}
INPUT_IMAGE-DIGEST: ${{ steps.get-image-digest.outputs.digest }}
INPUT_ARTIFACT-NAME: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix }}
with:
script: |
const inpIndex = core.getInput('index');
const inpVerifyCommands = core.getInput('verify-commands');
const inpImageDigest = core.getInput('image-digest');
const inpArtifactName = core.getInput('artifact-name');
const result = {
verifyCommands: inpVerifyCommands,
imageDigest: inpImageDigest,
artifactName: inpArtifactName
}
core.info(JSON.stringify(result, null, 2));
core.setOutput(`result_${inpIndex}`, JSON.stringify(result));
finalize:
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write # for registry authentication with OIDC if needed
packages: write # for pushing to GHCR when merging manifests if needed
outputs:
cosign-version: ${{ env.COSIGN_VERSION }}
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
artifact-name: ${{ inputs.artifact-name }}
output-type: ${{ inputs.output }}
needs:
- build
steps:
-
name: Docker meta
id: meta
if: ${{ inputs.output == 'image' }}
uses: docker/metadata-action@v5
with:
images: ${{ inputs.meta-images }}
tags: ${{ inputs.meta-tags }}
flavor: ${{ inputs.meta-flavor }}
labels: ${{ inputs.meta-labels }}
annotations: ${{ inputs.meta-annotations }}
bake-target: ${{ inputs.meta-bake-target }}
-
name: Login to registry
if: ${{ inputs.push && inputs.output == 'image' }}
# TODO: switch to docker/login-action when OIDC is supported
uses: crazy-max/docker-login-action@dockerhub-oidc
with:
registry-auth: ${{ secrets.registry-auths }}
-
name: Set up Docker Buildx
if: ${{ inputs.push && inputs.output == 'image' }}
uses: docker/setup-buildx-action@v3
with:
version: latest
buildkitd-flags: --debug
-
name: Create manifest
if: ${{ inputs.push && inputs.output == 'image' }}
uses: actions/github-script@v8
env:
INPUT_IMAGE-NAMES: ${{ inputs.meta-images }}
INPUT_TAG-NAMES: ${{ steps.meta.outputs.tag-names }}
INPUT_BUILD-OUTPUTS: ${{ toJSON(needs.build.outputs) }}
with:
script: |
const inpImageNames = core.getMultilineInput('image-names');
const inpTagNames = core.getMultilineInput('tag-names');
const inpBuildOutputs = JSON.parse(core.getInput('build-outputs'));
const digests = [];
for (const key of Object.keys(inpBuildOutputs)) {
const output = JSON.parse(inpBuildOutputs[key]);
if (output.imageDigest) {
digests.push(output.imageDigest);
}
}
if (digests.length === 0) {
throw new Error('No image digests found from build outputs');
}
for (const imageName of inpImageNames) {
let createArgs = ['buildx', 'imagetools', 'create'];
for (const tag of inpTagNames) {
createArgs.push('-t', `${imageName}:${tag}`);
}
for (const digest of digests) {
createArgs.push(digest);
}
await exec.getExecOutput('docker', createArgs, {
ignoreReturnCode: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
});
}
-
name: Set outputs
id: set
uses: actions/github-script@v8
env:
INPUT_BUILD-OUTPUTS: ${{ toJSON(needs.build.outputs) }}
with:
script: |
const inpBuildOutputs = JSON.parse(core.getInput('build-outputs'));
const verifyCommands = [];
for (const key of Object.keys(inpBuildOutputs)) {
const output = JSON.parse(inpBuildOutputs[key]);
if (output.verifyCommands) {
verifyCommands.push(output.verifyCommands);
}
}
core.setOutput('cosign-verify-commands', verifyCommands.join('\n'));