Skip to content

Commit 4efdeeb

Browse files
committed
build: support multiple image names
Signed-off-by: CrazyMax <[email protected]>
1 parent 24ba812 commit 4efdeeb

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ on:
2929
required: false
3030
default: true
3131
# same as docker/metadata-action inputs (minus sep-tags, sep-labels, sep-annotations, bake-target)
32-
meta-image:
32+
meta-images:
3333
type: string
34-
description: "Image to use as base name for tags"
34+
description: "List of images to use as base name for tags"
3535
required: false
3636
meta-tags:
3737
type: string
@@ -84,7 +84,7 @@ on:
8484
required: false
8585

8686
env:
87-
DOCKER_ACTIONS_TOOLKIT_MODULE: "@docker/actions-toolkit@0.65.0"
87+
DOCKER_ACTIONS_TOOLKIT_MODULE: "@docker/actions-toolkit@0.66.0"
8888
COSIGN_VERSION: "v3.0.2"
8989
LOCAL_EXPORT_DIR: "/tmp/buildx-output"
9090

@@ -104,27 +104,25 @@ jobs:
104104
INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
105105
INPUT_CACHE: ${{ inputs.cache }}
106106
INPUT_CACHE-MODE: ${{ inputs.cache-mode }}
107-
INPUT_META-IMAGE: ${{ inputs.meta-image }}
107+
INPUT_META-IMAGES: ${{ inputs.meta-images }}
108108
INPUT_BUILD-OUTPUT: ${{ inputs.build-output }}
109109
with:
110110
script: |
111111
const inpLocalExportDir = core.getInput('local-export-dir');
112112
const inpCache = core.getBooleanInput('cache');
113113
const inpCacheMode = core.getInput('cache-mode');
114-
const inpMetaImage = core.getMultilineInput('meta-image');
114+
const inpMetaImages = core.getMultilineInput('meta-images');
115115
const inpBuildOutput = core.getInput('build-output');
116116
117117
switch (inpBuildOutput) {
118118
case 'cacheonly':
119119
core.setOutput('output', 'type=cacheonly');
120120
break;
121121
case 'registry':
122-
if (inpMetaImage.length == 0) {
123-
core.setFailed('meta-image is required when build-output is registry');
124-
} else if (inpMetaImage.length > 1) {
125-
core.setFailed('Only one meta-image is supported');
122+
if (inpMetaImages.length == 0) {
123+
core.setFailed('meta-images is required when build-output is registry');
126124
}
127-
core.setOutput('output', `type=registry,"name=${inpMetaImage[0]}",oci-artifact=true,push-by-digest=true,name-canonical=true`);
125+
core.setOutput('output', `type=registry,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true`);
128126
break;
129127
case 'local':
130128
core.setOutput('output', `type=local,dest=${inpLocalExportDir}`);
@@ -161,7 +159,7 @@ jobs:
161159
if: ${{ inputs.build-output == 'registry' }}
162160
uses: docker/metadata-action@v5
163161
with:
164-
images: ${{ inputs.meta-image }}
162+
images: ${{ inputs.meta-images }}
165163
tags: ${{ inputs.meta-tags }}
166164
flavor: ${{ inputs.meta-flavor }}
167165
labels: ${{ inputs.meta-labels }}
@@ -213,18 +211,18 @@ jobs:
213211
if: ${{ inputs.build-output == 'registry' }}
214212
uses: actions/github-script@v8
215213
env:
216-
INPUT_IMAGE-NAME: ${{ inputs.meta-image }}
214+
INPUT_IMAGE-NAMES: ${{ inputs.meta-images }}
217215
INPUT_IMAGE-DIGEST: ${{ steps.build.outputs.digest }}
218216
with:
219217
script: |
220218
const { Sigstore } = require('@docker/actions-toolkit/lib/sigstore/sigstore');
221219
222-
const inpImageName = core.getInput('image-name');
220+
const inpImageNames = core.getMultilineInput('image-names');
223221
const inpImageDigest = core.getInput('image-digest');
224222
225223
const sigstore = new Sigstore();
226224
const signResults = await sigstore.signAttestationManifests({
227-
imageName: inpImageName,
225+
imageNames: inpImageNames,
228226
imageDigest: inpImageDigest
229227
});
230228
@@ -258,22 +256,25 @@ jobs:
258256
if: ${{ inputs.build-output == 'registry' }}
259257
uses: actions/github-script@v7
260258
env:
261-
INPUT_TAGS: ${{ steps.meta.outputs.tags }}
259+
INPUT_IMAGE-NAMES: ${{ inputs.meta-images }}
260+
INPUT_TAG-NAMES: ${{ steps.meta.outputs.tag-names }}
262261
INPUT_IMAGE-DIGEST: ${{ steps.build.outputs.digest }}
263262
with:
264263
script: |
265-
let createArgs = ['buildx', 'imagetools', 'create'];
266-
for (const tag of core.getMultilineInput('tags')) {
267-
createArgs.push('-t', tag);
268-
}
269-
createArgs.push(core.getInput('image-digest'));
270-
await exec.getExecOutput('docker', createArgs, {
271-
ignoreReturnCode: true
272-
}).then(res => {
273-
if (res.stderr.length > 0 && res.exitCode != 0) {
274-
throw new Error(res.stderr);
264+
for (const imageName of core.getMultilineInput('image-names')) {
265+
let createArgs = ['buildx', 'imagetools', 'create'];
266+
for (const tag of core.getMultilineInput('tag-names')) {
267+
createArgs.push('-t', `${imageName}:${tag}`);
275268
}
276-
});
269+
createArgs.push(core.getInput('image-digest'));
270+
await exec.getExecOutput('docker', createArgs, {
271+
ignoreReturnCode: true
272+
}).then(res => {
273+
if (res.stderr.length > 0 && res.exitCode != 0) {
274+
throw new Error(res.stderr);
275+
}
276+
});
277+
}
277278
-
278279
name: List local output
279280
if: ${{ inputs.build-output == 'local' }}

0 commit comments

Comments
 (0)