Skip to content

Commit b0164e8

Browse files
committed
artifact-merge opt to merge output for multi-platforms build into a single artifact
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent cf2bccf commit b0164e8

File tree

6 files changed

+89
-5
lines changed

6 files changed

+89
-5
lines changed

.github/workflows/.test-bake.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,33 @@ jobs:
543543
- registry: registry-1-stage.docker.io
544544
username: ${{ vars.DOCKERHUB_STAGE_USERNAME }}
545545
password: ${{ secrets.DOCKERHUB_STAGE_TOKEN }}
546+
547+
bake-local-nomerge:
548+
uses: ./.github/workflows/bake.yml
549+
permissions:
550+
contents: read
551+
id-token: write
552+
with:
553+
artifact-name: bake-nomerge-output
554+
artifact-upload: true
555+
artifact-merge: false
556+
context: test
557+
output: local
558+
sbom: true
559+
sign: ${{ github.event_name != 'pull_request' }}
560+
target: hello-cross
561+
562+
bake-local-single-nomerge:
563+
uses: ./.github/workflows/bake.yml
564+
permissions:
565+
contents: read
566+
id-token: write
567+
with:
568+
artifact-name: bake-single-nomerge-output
569+
artifact-upload: true
570+
artifact-merge: false
571+
context: test
572+
output: local
573+
sbom: true
574+
sign: ${{ github.event_name != 'pull_request' }}
575+
target: hello

.github/workflows/.test-build.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,32 @@ jobs:
574574
- registry: registry-1-stage.docker.io
575575
username: ${{ vars.DOCKERHUB_STAGE_USERNAME }}
576576
password: ${{ secrets.DOCKERHUB_STAGE_TOKEN }}
577+
578+
build-local-nomerge:
579+
uses: ./.github/workflows/build.yml
580+
permissions:
581+
contents: read
582+
id-token: write
583+
with:
584+
artifact-name: build-nomerge-output
585+
artifact-upload: true
586+
artifact-merge: false
587+
file: test/hello.Dockerfile
588+
output: local
589+
platforms: linux/amd64,linux/arm64
590+
sbom: true
591+
sign: ${{ github.event_name != 'pull_request' }}
592+
593+
build-local-single-nomerge:
594+
uses: ./.github/workflows/build.yml
595+
permissions:
596+
contents: read
597+
id-token: write
598+
with:
599+
artifact-name: build-single-nomerge-output
600+
artifact-upload: true
601+
artifact-merge: false
602+
file: test/hello.Dockerfile
603+
output: local
604+
sbom: true
605+
sign: ${{ github.event_name != 'pull_request' }}

.github/workflows/bake.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ on:
2828
description: "Upload build output GitHub artifact (for local output)"
2929
required: false
3030
default: false
31+
artifact-merge:
32+
type: boolean
33+
description: "Merge output for multi-platforms build into a single artifact (for local output)"
34+
required: false
35+
default: true
3136
cache:
3237
type: boolean
3338
description: "Enable cache to GitHub Actions cache backend"
@@ -138,6 +143,9 @@ on:
138143
artifact-name:
139144
description: "Name of the uploaded artifact (for local output)"
140145
value: ${{ jobs.finalize.outputs.artifact-name }}
146+
artifact-merge:
147+
description: "Whether multiple artifacts were merged (for local output)"
148+
value: ${{ jobs.finalize.outputs.artifact-merge }}
141149
output-type:
142150
description: "Build output type"
143151
value: ${{ jobs.finalize.outputs.output-type }}
@@ -852,7 +860,7 @@ jobs:
852860
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
853861
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
854862
with:
855-
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix || '0' }}
863+
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix || (inputs.artifact-merge && '' || '0') }}
856864
path: ${{ env.LOCAL_EXPORT_DIR }}
857865
if-no-files-found: error
858866
-
@@ -892,6 +900,7 @@ jobs:
892900
cosign-version: ${{ env.COSIGN_VERSION }}
893901
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
894902
artifact-name: ${{ inputs.artifact-upload && inputs.artifact-name || '' }}
903+
artifact-merge: ${{ inputs.artifact-merge }}
895904
output-type: ${{ inputs.output }}
896905
signed: ${{ needs.prepare.outputs.sign }}
897906
needs:
@@ -973,7 +982,7 @@ jobs:
973982
}
974983
-
975984
name: Merge artifacts
976-
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
985+
if: ${{ inputs.output == 'local' && inputs.artifact-upload && inputs.artifact-merge }}
977986
uses: actions/upload-artifact/merge@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
978987
with:
979988
name: ${{ inputs.artifact-name }}

.github/workflows/build.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ on:
2828
description: "Upload build output GitHub artifact (for local output)"
2929
required: false
3030
default: false
31+
artifact-merge:
32+
type: boolean
33+
description: "Merge output for multi-platforms build into a single artifact (for local output)"
34+
required: false
35+
default: true
3136
annotations:
3237
type: string
3338
description: "List of annotations to set to the image (for image output)"
@@ -141,6 +146,9 @@ on:
141146
artifact-name:
142147
description: "Name of the uploaded artifact (for local output)"
143148
value: ${{ jobs.finalize.outputs.artifact-name }}
149+
artifact-merge:
150+
description: "Whether multiple artifacts were merged (for local output)"
151+
value: ${{ jobs.finalize.outputs.artifact-merge }}
144152
output-type:
145153
description: "Build output type"
146154
value: ${{ jobs.finalize.outputs.output-type }}
@@ -717,7 +725,7 @@ jobs:
717725
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
718726
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
719727
with:
720-
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix || '0' }}
728+
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix || (inputs.artifact-merge && '' || '0') }}
721729
path: ${{ env.LOCAL_EXPORT_DIR }}
722730
if-no-files-found: error
723731
-
@@ -757,6 +765,7 @@ jobs:
757765
cosign-version: ${{ env.COSIGN_VERSION }}
758766
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
759767
artifact-name: ${{ inputs.artifact-upload && inputs.artifact-name || '' }}
768+
artifact-merge: ${{ inputs.artifact-merge }}
760769
output-type: ${{ inputs.output }}
761770
signed: ${{ needs.prepare.outputs.sign }}
762771
needs:
@@ -837,7 +846,7 @@ jobs:
837846
}
838847
-
839848
name: Merge artifacts
840-
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
849+
if: ${{ inputs.output == 'local' && inputs.artifact-upload && inputs.artifact-merge }}
841850
uses: actions/upload-artifact/merge@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
842851
with:
843852
name: ${{ inputs.artifact-name }}

.github/workflows/verify.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
const cosignVersion = builderOutputs['cosign-version'];
3434
const cosignVerifyCommands = builderOutputs['cosign-verify-commands'];
3535
const artifactName = builderOutputs['artifact-name'];
36+
const artifactMerge = builderOutputs['artifact-merge'] === 'true';
3637
const outputType = builderOutputs['output-type'];
3738
const signed = builderOutputs['signed'] === 'true';
3839
if (!signed) {
@@ -44,7 +45,9 @@ jobs:
4445
4546
core.setOutput('cosign-version', cosignVersion);
4647
core.setOutput('cosign-verify-commands', cosignVerifyCommands);
47-
core.setOutput('artifact-name', artifactName);
48+
core.setOutput('artifact-name', artifactMerge ? '' : artifactName);
49+
core.setOutput('artifact-pattern', artifactMerge ? `${artifactName}-*` : '');
50+
core.setOutput('artifact-merge-multiple', artifactMerge ? 'true' : 'false');
4851
core.setOutput('output-type', outputType);
4952
core.setOutput('signed', signed);
5053
-
@@ -92,6 +95,8 @@ jobs:
9295
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
9396
with:
9497
name: ${{ steps.vars.outputs.artifact-name }}
98+
pattern: ${{ steps.vars.outputs.artifact-pattern }}
99+
merge-multiple: ${{ steps.vars.outputs.artifact-merge-multiple }}
95100
-
96101
name: Verify signatures
97102
if: ${{ steps.vars.outputs.signed == 'true' }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ on:
223223
| `setup-qemu` | Bool | `false` | Runs the `setup-qemu-action` step to install QEMU static binaries |
224224
| `artifact-name` | String | `docker-github-builder-assets` | Name of the uploaded GitHub artifact (for `local` output) |
225225
| `artifact-upload` | Bool | `false` | Upload build output GitHub artifact (for `local` output) |
226+
| `artifact-merge` | Bool | `true` | Merge output for multi-platforms build into a single artifact (for `local` output) |
226227
| `annotations` | List | | List of annotations to set to the image (for `image` output) |
227228
| `build-args` | List | `auto` | List of [build-time variables](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-arg). If you want to set a build-arg through an environment variable, use the `envs` input |
228229
| `cache` | Bool | `false` | Enable [GitHub Actions cache](https://docs.docker.com/build/cache/backends/gha/) exporter |
@@ -331,6 +332,7 @@ on:
331332
| `setup-qemu` | Bool | `false` | Runs the `setup-qemu-action` step to install QEMU static binaries |
332333
| `artifact-name` | String | `docker-github-builder-assets` | Name of the uploaded GitHub artifact (for `local` output) |
333334
| `artifact-upload` | Bool | `false` | Upload build output GitHub artifact (for `local` output) |
335+
| `artifact-merge` | Bool | `true` | Merge output for multi-platforms build into a single artifact (for `local` output) |
334336
| `cache` | Bool | `false` | Enable [GitHub Actions cache](https://docs.docker.com/build/cache/backends/gha/) exporter |
335337
| `cache-scope` | String | target name or `buildkit` | Which [scope cache object belongs to](https://docs.docker.com/build/cache/backends/gha/#scope) if `cache` is enabled. This is the cache blob prefix name used when pushing cache to GitHub Actions cache backend |
336338
| `cache-mode` | String | `min` | [Cache layers to export](https://docs.docker.com/build/cache/backends/#cache-mode) if cache enabled (`min` or `max`). In `min` cache mode, only layers that are exported into the resulting image are cached, while in `max` cache mode, all layers are cached, even those of intermediate steps |

0 commit comments

Comments
 (0)