Skip to content

Commit 19b9a13

Browse files
committed
distribute: use toolkit to parse bake definition
Signed-off-by: CrazyMax <[email protected]>
1 parent 7fe8741 commit 19b9a13

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

.github/workflows/distribute.yml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ on:
108108
login-password:
109109
description: "Password or personal access token used to log against the Docker registry"
110110
required: false
111+
github-token:
112+
description: "API token used to authenticate to a Git repository for remote definitions"
113+
required: false
111114

112115
jobs:
113116
prepare:
@@ -125,7 +128,6 @@ jobs:
125128
with:
126129
script: |
127130
let def;
128-
const source = `${{ inputs.bake-source }}`;
129131
const files = `${{ inputs.bake-files }}` ? `${{ inputs.bake-files }}`.split(/[\r?\n,]+/).filter(Boolean) : [];
130132
const target = `${{ inputs.target }}`;
131133
@@ -134,25 +136,32 @@ jobs:
134136
throw new Error('Only one meta-image is allowed');
135137
}
136138
137-
await core.group(`Validating definition`, async () => {
138-
let args = ['buildx', 'bake'];
139-
for (const file of files) {
140-
args.push('--file', file);
141-
}
142-
if (source && source !== '.') {
143-
args.push(source);
144-
}
145-
args.push(target, '--print');
139+
await core.group(`Install docker/actions-toolkit`, async () => {
140+
await exec.exec('npm', ['install', '@docker/actions-toolkit']);
141+
});
146142
147-
const res = await exec.getExecOutput('docker', args, {
148-
ignoreReturnCode: true,
149-
silent: true,
150-
cwd: `${{ inputs.bake-workdir }}`
151-
});
152-
if (res.stderr.length > 0 && res.exitCode != 0) {
153-
throw new Error(res.stderr);
143+
await core.group(`Validating definition`, async () => {
144+
const { Bake } = require('@docker/actions-toolkit/lib/buildx/bake');
145+
const bake = new Bake();
146+
def = await bake.getDefinition(
147+
{
148+
allow: `${{ inputs.bake-allow }}` ? `${{ inputs.bake-allow }}`.split(/[\r?\n,]+/).filter(Boolean) : [],
149+
files: `${{ inputs.bake-files }}` ? `${{ inputs.bake-files }}`.split(/[\r?\n,]+/).filter(Boolean) : [],
150+
noCache: `${{ inputs.bake-no-cache }}`,
151+
overrides: `${{ inputs.bake-set }}` ? `${{ inputs.bake-set }}`.split(/[\r?\n,]+/).filter(Boolean) : [],
152+
provenance: `${{ inputs.bake-provenance }}`,
153+
sbom: `${{ inputs.bake-sbom }}`,
154+
source: `${{ inputs.bake-source }}`,
155+
targets: [`${{ inputs.target }}`],
156+
githubToken: `${{ secrets.github-token || github.token }}`
157+
},
158+
{
159+
cwd: `${{ inputs.bake-workdir }}`
160+
}
161+
);
162+
if (!def) {
163+
throw new Error('Bake definition not set');
154164
}
155-
def = JSON.parse(res.stdout.trim());
156165
core.info(JSON.stringify(def, null, 2));
157166
});
158167
@@ -339,6 +348,7 @@ jobs:
339348
*.tags=
340349
*.platform=${{ matrix.platform }}
341350
*.output=type=image,"name=${{ inputs.meta-image }}",push-by-digest=true,name-canonical=true,push=${{ inputs.push }}
351+
github-token: ${{ secrets.github-token || github.token }}
342352
-
343353
name: Set digest output
344354
id: digest

0 commit comments

Comments
 (0)