mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-04-20 17:46:45 +00:00
Enhance builder inspection
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
abdb186058
commit
72750233ac
10 changed files with 215 additions and 53 deletions
|
@ -8,6 +8,16 @@ import * as github from './github';
|
|||
import * as core from '@actions/core';
|
||||
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;
|
||||
};
|
||||
|
||||
export async function getVersion(): Promise<string> {
|
||||
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
|
@ -34,16 +44,50 @@ export async function isAvailable(): Promise<Boolean> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function platforms(): Promise<String | undefined> {
|
||||
return await exec.exec(`docker`, ['buildx', 'inspect'], true).then(res => {
|
||||
export async function inspect(name: string): Promise<Builder> {
|
||||
return await exec.exec(`docker`, ['buildx', 'inspect', name], true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
for (const line of res.stdout.trim().split(`\n`)) {
|
||||
if (line.startsWith('Platforms')) {
|
||||
return line.replace('Platforms: ', '').replace(/\s/g, '').trim();
|
||||
const builder: Builder = {};
|
||||
itlines: 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': {
|
||||
if (builder.name == undefined) {
|
||||
builder.name = value;
|
||||
} else {
|
||||
builder.node_name = value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'Driver': {
|
||||
builder.driver = value;
|
||||
break;
|
||||
}
|
||||
case 'Endpoint': {
|
||||
builder.node_endpoint = value;
|
||||
break;
|
||||
}
|
||||
case 'Status': {
|
||||
builder.node_status = value;
|
||||
break;
|
||||
}
|
||||
case 'Flags': {
|
||||
builder.node_flags = value;
|
||||
break;
|
||||
}
|
||||
case 'Platforms': {
|
||||
builder.node_platforms = value.replace(/\s/g, '');
|
||||
break itlines;
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
import {issueCommand} from '@actions/core/lib/command';
|
||||
|
||||
export const osPlat: string = os.platform();
|
||||
export const osArch: string = os.arch();
|
||||
|
@ -49,3 +50,8 @@ export const asyncForEach = async (array, callback) => {
|
|||
await callback(array[index], index, array);
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
||||
export function setOutput(name: string, value: any): void {
|
||||
issueCommand('set-output', {name}, value);
|
||||
}
|
||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -28,7 +28,7 @@ async function run(): Promise<void> {
|
|||
core.info(`Using buildx ${buildxVersion}`);
|
||||
|
||||
const builderName: string = inputs.driver == 'docker' ? 'default' : `builder-${require('uuid').v4()}`;
|
||||
core.setOutput('name', builderName);
|
||||
context.setOutput('name', builderName);
|
||||
stateHelper.setBuilderName(builderName);
|
||||
|
||||
if (inputs.driver !== 'docker') {
|
||||
|
@ -69,10 +69,14 @@ async function run(): Promise<void> {
|
|||
core.endGroup();
|
||||
}
|
||||
|
||||
core.startGroup(`Extracting available platforms`);
|
||||
const platforms = await buildx.platforms();
|
||||
core.info(`${platforms}`);
|
||||
core.setOutput('platforms', platforms);
|
||||
core.startGroup(`Inspect builder`);
|
||||
const builder = await buildx.inspect(builderName);
|
||||
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);
|
||||
core.endGroup();
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue