Skip to content

Commit 624a227

Browse files
committed
add push input and rename registry output to image
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 667f7f2 commit 624a227

File tree

4 files changed

+76
-57
lines changed

4 files changed

+76
-57
lines changed

.github/workflows/.test.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525
packages: write
2626
id-token: write
2727
with:
28-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
28+
output: image
29+
push: ${{ github.event_name != 'pull_request' }}
2930
cache: true
3031
meta-images: |
3132
public.ecr.aws/q3b5f1u4/test-docker-action
@@ -59,7 +60,8 @@ jobs:
5960
packages: write
6061
id-token: write
6162
with:
62-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
63+
output: image
64+
push: ${{ github.event_name != 'pull_request' }}
6365
cache: true
6466
cache-scope: build-aws
6567
meta-images: |
@@ -95,7 +97,8 @@ jobs:
9597
packages: write
9698
id-token: write
9799
with:
98-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
100+
output: image
101+
push: ${{ github.event_name != 'pull_request' }}
99102
meta-images: ghcr.io/docker/github-builder-test
100103
meta-tags: |
101104
type=raw,value=build-${{ github.run_id }}
@@ -128,7 +131,8 @@ jobs:
128131
packages: write
129132
id-token: write
130133
with:
131-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
134+
output: image
135+
push: ${{ github.event_name != 'pull_request' }}
132136
meta-images: registry-1-stage.docker.io/docker/github-builder-test
133137
meta-tags: |
134138
type=raw,value=build-${{ github.run_id }}
@@ -161,7 +165,8 @@ jobs:
161165
packages: write
162166
id-token: write
163167
with:
164-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
168+
output: image
169+
push: ${{ github.event_name != 'pull_request' }}
165170
meta-images: registry-1-stage.docker.io/docker/github-builder-test
166171
meta-tags: |
167172
type=raw,value=${{ github.run_id }},prefix=oidc-
@@ -195,7 +200,8 @@ jobs:
195200
packages: write
196201
id-token: write
197202
with:
198-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
203+
output: image
204+
push: ${{ github.event_name != 'pull_request' }}
199205
meta-images: |
200206
ghcr.io/docker/github-builder-test
201207
public.ecr.aws/q3b5f1u4/test-docker-action
@@ -236,7 +242,8 @@ jobs:
236242
packages: write
237243
id-token: write
238244
with:
239-
output: ${{ github.event_name != 'pull_request' && 'local' || 'cacheonly' }}
245+
output: local
246+
push: ${{ github.event_name != 'pull_request' }}
240247
artifact-name: build-output
241248
build-file: test/hello.Dockerfile
242249
build-sbom: true
@@ -257,7 +264,8 @@ jobs:
257264
packages: write
258265
id-token: write
259266
with:
260-
output: ${{ github.event_name != 'pull_request' && 'local' || 'cacheonly' }}
267+
output: local
268+
push: ${{ github.event_name != 'pull_request' }}
261269
artifact-name: build-output-single
262270
build-file: test/hello.Dockerfile
263271
build-sbom: true
@@ -279,7 +287,8 @@ jobs:
279287
with:
280288
context: test
281289
target: hello
282-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
290+
output: image
291+
push: ${{ github.event_name != 'pull_request' }}
283292
cache: true
284293
cache-scope: bake-aws
285294
meta-images: |
@@ -315,7 +324,8 @@ jobs:
315324
with:
316325
context: test
317326
target: hello-cross
318-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
327+
output: image
328+
push: ${{ github.event_name != 'pull_request' }}
319329
cache: true
320330
cache-scope: bake-aws
321331
meta-images: |
@@ -351,7 +361,8 @@ jobs:
351361
with:
352362
context: test
353363
target: hello-cross
354-
output: ${{ github.event_name != 'pull_request' && 'registry' || 'cacheonly' }}
364+
output: image
365+
push: ${{ github.event_name != 'pull_request' }}
355366
cache: true
356367
cache-scope: bake-aws
357368
meta-images: |
@@ -394,7 +405,8 @@ jobs:
394405
with:
395406
context: test
396407
target: hello-cross
397-
output: ${{ github.event_name != 'pull_request' && 'local' || 'cacheonly' }}
408+
output: image
409+
push: ${{ github.event_name != 'pull_request' }}
398410
cache: true
399411
artifact-name: bake-output
400412
bake-sbom: true
@@ -416,7 +428,8 @@ jobs:
416428
with:
417429
context: test
418430
target: hello
419-
output: ${{ github.event_name != 'pull_request' && 'local' || 'cacheonly' }}
431+
output: image
432+
push: ${{ github.event_name != 'pull_request' }}
420433
cache: true
421434
artifact-name: bake-output-single
422435
bake-sbom: true

.github/workflows/bake.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ on:
1919
default: default
2020
output:
2121
type: string
22-
description: "Build output destination (one of cacheonly, registry, local)"
23-
default: 'cacheonly'
24-
required: false
22+
description: "Build output destination (image or local)"
23+
required: true
2524
artifact-name:
2625
type: string
2726
description: "Name of the uploaded artifact (for local output)"
@@ -31,6 +30,11 @@ on:
3130
type: string
3231
description: "Environment variables to set"
3332
required: false
33+
push:
34+
type: boolean
35+
description: "Push image to the registry (for image output) and/or sign attestation manifests or local artifacts"
36+
required: false
37+
default: false
3438
cache:
3539
type: boolean
3640
description: "Enable cache to GitHub Actions cache backend"
@@ -314,7 +318,7 @@ jobs:
314318
-
315319
name: Docker meta
316320
id: meta
317-
if: ${{ inputs.output == 'registry' }}
321+
if: ${{ inputs.output == 'image' }}
318322
uses: docker/metadata-action@v5
319323
with:
320324
images: ${{ inputs.meta-images }}
@@ -345,6 +349,7 @@ jobs:
345349
INPUT_CONTEXT: ${{ inputs.context }}
346350
INPUT_TARGET: ${{ inputs.target }}
347351
INPUT_OUTPUT: ${{ inputs.output }}
352+
INPUT_PUSH: ${{ inputs.push }}
348353
INPUT_CACHE: ${{ inputs.cache }}
349354
INPUT_CACHE-SCOPE: ${{ inputs.cache-scope }}
350355
INPUT_CACHE-MODE: ${{ inputs.cache-mode }}
@@ -375,6 +380,7 @@ jobs:
375380
const inpContext = core.getInput('context');
376381
const inpTarget = core.getInput('target');
377382
const inpOutput = core.getInput('output');
383+
const inpPush = core.getBooleanInput('push');
378384
const inpCache = core.getBooleanInput('cache');
379385
const inpCacheScope = core.getInput('cache-scope');
380386
const inpCacheMode = core.getInput('cache-mode');
@@ -441,14 +447,11 @@ jobs:
441447
442448
let outputOverride = '';
443449
switch (inpOutput) {
444-
case 'cacheonly':
445-
outputOverride = '*.output=type=cacheonly';
446-
break;
447-
case 'registry':
450+
case 'image':
448451
if (inpMetaImages.length == 0) {
449452
core.setFailed('meta-images is required when output is registry');
450453
}
451-
outputOverride = `*.output=type=registry,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true`;
454+
outputOverride = `*.output=type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}`;
452455
break;
453456
case 'local':
454457
outputOverride = `*.output=type=local,platform-split=true,dest=${inpLocalExportDir}`;
@@ -472,7 +475,7 @@ jobs:
472475
});
473476
-
474477
name: Login to registry
475-
if: ${{ inputs.output == 'registry' }}
478+
if: ${{ inputs.push && inputs.output == 'image' }}
476479
# TODO: switch to docker/login-action when OIDC is supported
477480
uses: crazy-max/docker-login-action@dockerhub-oidc
478481
with:
@@ -495,7 +498,7 @@ jobs:
495498
-
496499
name: Get image digest
497500
id: get-image-digest
498-
if: ${{ inputs.output == 'registry' }}
501+
if: ${{ inputs.push && inputs.output == 'image' }}
499502
uses: actions/github-script@v8
500503
env:
501504
INPUT_TARGET: ${{ steps.prepare.outputs.target }}
@@ -509,7 +512,7 @@ jobs:
509512
core.setOutput('digest', imageDigest);
510513
-
511514
name: Install Cosign
512-
if: ${{ inputs.output != 'cacheonly' }}
515+
if: ${{ inputs.push }}
513516
uses: actions/github-script@v8
514517
env:
515518
INPUT_COSIGN-VERSION: ${{ env.COSIGN_VERSION }}
@@ -527,7 +530,7 @@ jobs:
527530
-
528531
name: Signing attestation manifests
529532
id: signing-attestation-manifests
530-
if: ${{ inputs.output == 'registry' }}
533+
if: ${{ inputs.push && inputs.output == 'image' }}
531534
uses: actions/github-script@v8
532535
env:
533536
INPUT_IMAGE-NAMES: ${{ inputs.meta-images }}
@@ -562,7 +565,7 @@ jobs:
562565
-
563566
name: Signing local artifacts
564567
id: signing-local-artifacts
565-
if: ${{ inputs.output == 'local' }}
568+
if: ${{ inputs.push && inputs.output == 'local' }}
566569
uses: actions/github-script@v8
567570
env:
568571
INPUT_LOCAL-OUTPUT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
@@ -646,7 +649,7 @@ jobs:
646649
-
647650
name: Docker meta
648651
id: meta
649-
if: ${{ inputs.output == 'registry' }}
652+
if: ${{ inputs.output == 'image' }}
650653
uses: docker/metadata-action@v5
651654
with:
652655
images: ${{ inputs.meta-images }}
@@ -657,21 +660,21 @@ jobs:
657660
bake-target: ${{ inputs.meta-bake-target }}
658661
-
659662
name: Login to registry
660-
if: ${{ inputs.output == 'registry' }}
663+
if: ${{ inputs.push && inputs.output == 'image' }}
661664
# TODO: switch to docker/login-action when OIDC is supported
662665
uses: crazy-max/docker-login-action@dockerhub-oidc
663666
with:
664667
registry-auth: ${{ secrets.registry-auths }}
665668
-
666669
name: Set up Docker Buildx
667-
if: ${{ inputs.output == 'registry' }}
670+
if: ${{ inputs.push && inputs.output == 'image' }}
668671
uses: docker/setup-buildx-action@v3
669672
with:
670673
version: latest
671674
buildkitd-flags: --debug
672675
-
673676
name: Create manifest
674-
if: ${{ inputs.output == 'registry' }}
677+
if: ${{ inputs.push && inputs.output == 'image' }}
675678
uses: actions/github-script@v8
676679
env:
677680
INPUT_IMAGE-NAMES: ${{ inputs.meta-images }}
@@ -713,7 +716,6 @@ jobs:
713716
-
714717
name: Set outputs
715718
id: set
716-
if: ${{ inputs.output != 'cacheonly' }}
717719
uses: actions/github-script@v8
718720
env:
719721
INPUT_BUILD-OUTPUTS: ${{ toJSON(needs.build.outputs) }}

0 commit comments

Comments
 (0)