mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-04-23 08:26:38 +02:00
nodes metadata JSON ouput
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f0ad70c1de
commit
aa0df6f73a
6 changed files with 113 additions and 44 deletions
|
@ -12,11 +12,15 @@ import * as tc from '@actions/tool-cache';
|
|||
export type Builder = {
|
||||
name?: string;
|
||||
driver?: string;
|
||||
node_name?: string;
|
||||
node_endpoint?: string;
|
||||
node_status?: string;
|
||||
node_flags?: string;
|
||||
node_platforms?: string;
|
||||
nodes: Node[];
|
||||
};
|
||||
|
||||
export type Node = {
|
||||
name?: string;
|
||||
endpoint?: string;
|
||||
status?: string;
|
||||
'buildkitd-flags'?: string;
|
||||
platforms?: string;
|
||||
};
|
||||
|
||||
export async function getConfigInline(s: string): Promise<string> {
|
||||
|
@ -98,44 +102,67 @@ export async function inspect(name: string, standalone?: boolean): Promise<Build
|
|||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr.trim());
|
||||
}
|
||||
const builder: Builder = {};
|
||||
itlines: for (const line of res.stdout.trim().split(`\n`)) {
|
||||
const builder: Builder = {
|
||||
nodes: []
|
||||
};
|
||||
let node: Node = {};
|
||||
for (const line of res.stdout.trim().split(`\n`)) {
|
||||
const [key, ...rest] = line.split(':');
|
||||
const value = rest.map(v => v.trim()).join(':');
|
||||
if (key.length == 0 || value.length == 0) {
|
||||
continue;
|
||||
}
|
||||
switch (key) {
|
||||
case 'Name': {
|
||||
switch (key.toLowerCase()) {
|
||||
case 'name': {
|
||||
if (builder.name == undefined) {
|
||||
builder.name = value;
|
||||
} else {
|
||||
builder.node_name = value;
|
||||
if (Object.keys(node).length > 0) {
|
||||
builder.nodes.push(node);
|
||||
node = {};
|
||||
}
|
||||
node.name = value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'Driver': {
|
||||
case 'driver': {
|
||||
builder.driver = value;
|
||||
break;
|
||||
}
|
||||
case 'Endpoint': {
|
||||
builder.node_endpoint = value;
|
||||
case 'endpoint': {
|
||||
node.endpoint = value;
|
||||
break;
|
||||
}
|
||||
case 'Status': {
|
||||
builder.node_status = value;
|
||||
case 'status': {
|
||||
node.status = value;
|
||||
break;
|
||||
}
|
||||
case 'Flags': {
|
||||
builder.node_flags = value;
|
||||
case 'flags': {
|
||||
node['buildkitd-flags'] = value;
|
||||
break;
|
||||
}
|
||||
case 'Platforms': {
|
||||
builder.node_platforms = value.replace(/\s/g, '');
|
||||
break itlines;
|
||||
case 'platforms': {
|
||||
let platforms: Array<string> = [];
|
||||
// if a preferred platform is being set then use only these
|
||||
// https://docs.docker.com/engine/reference/commandline/buildx_inspect/#get-information-about-a-builder-instance
|
||||
if (value.includes('*')) {
|
||||
for (const platform of value.split(', ')) {
|
||||
if (platform.includes('*')) {
|
||||
platforms.push(platform.replace('*', ''));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// otherwise set all platforms available
|
||||
platforms = value.split(', ');
|
||||
}
|
||||
node.platforms = platforms.join(',');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(node).length > 0) {
|
||||
builder.nodes.push(node);
|
||||
}
|
||||
return builder;
|
||||
});
|
||||
}
|
||||
|
|
21
src/main.ts
21
src/main.ts
|
@ -115,21 +115,26 @@ async function run(): Promise<void> {
|
|||
|
||||
core.startGroup(`Inspect builder`);
|
||||
const builder = await buildx.inspect(builderName, standalone);
|
||||
const firstNode = builder.nodes[0];
|
||||
core.info(JSON.stringify(builder, undefined, 2));
|
||||
context.setOutput('driver', builder.driver);
|
||||
context.setOutput('endpoint', builder.node_endpoint);
|
||||
context.setOutput('status', builder.node_status);
|
||||
context.setOutput('flags', builder.node_flags);
|
||||
context.setOutput('platforms', builder.node_platforms);
|
||||
context.setOutput('platforms', firstNode.platforms);
|
||||
context.setOutput('nodes', JSON.stringify(builder.nodes, undefined, 2));
|
||||
context.setOutput('endpoint', firstNode.endpoint); // TODO: deprecated, to be removed in a later version
|
||||
context.setOutput('status', firstNode.status); // TODO: deprecated, to be removed in a later version
|
||||
context.setOutput('flags', firstNode['buildkitd-flags']); // TODO: deprecated, to be removed in a later version
|
||||
core.endGroup();
|
||||
|
||||
if (!standalone && inputs.driver == 'docker-container') {
|
||||
stateHelper.setContainerName(`buildx_buildkit_${builder.node_name}`);
|
||||
if (!standalone && builder.driver == 'docker-container') {
|
||||
stateHelper.setContainerName(`buildx_buildkit_${firstNode.name}`);
|
||||
core.startGroup(`BuildKit version`);
|
||||
core.info(await buildx.getBuildKitVersion(`buildx_buildkit_${builder.node_name}`));
|
||||
for (const node of builder.nodes) {
|
||||
const bkvers = await buildx.getBuildKitVersion(`buildx_buildkit_${node.name}`);
|
||||
core.info(`${node.name}: ${bkvers}`);
|
||||
}
|
||||
core.endGroup();
|
||||
}
|
||||
if (core.isDebug() || builder.node_flags?.includes('--debug')) {
|
||||
if (core.isDebug() || firstNode['buildkitd-flags']?.includes('--debug')) {
|
||||
stateHelper.setDebug('true');
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue