mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-04-23 08:26:38 +02:00
append nodes to builder support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
95cb08cb26
commit
2dfca373f3
12 changed files with 249 additions and 14 deletions
|
@ -3,7 +3,9 @@ import * as os from 'os';
|
|||
import path from 'path';
|
||||
import * as tmp from 'tmp';
|
||||
import * as uuid from 'uuid';
|
||||
import {parse} from 'csv-parse/sync';
|
||||
import * as buildx from './buildx';
|
||||
import * as nodes from './nodes';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
let _tmpDir: string;
|
||||
|
@ -32,6 +34,7 @@ export interface Inputs {
|
|||
endpoint: string;
|
||||
config: string;
|
||||
configInline: string;
|
||||
append: string;
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
|
@ -45,7 +48,8 @@ export async function getInputs(): Promise<Inputs> {
|
|||
use: core.getBooleanInput('use'),
|
||||
endpoint: core.getInput('endpoint'),
|
||||
config: core.getInput('config'),
|
||||
configInline: core.getInput('config-inline')
|
||||
configInline: core.getInput('config-inline'),
|
||||
append: core.getInput('append')
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -79,6 +83,28 @@ export async function getCreateArgs(inputs: Inputs, buildxVersion: string): Prom
|
|||
return args;
|
||||
}
|
||||
|
||||
export async function getAppendArgs(inputs: Inputs, node: nodes.Node, buildxVersion: string): Promise<Array<string>> {
|
||||
const args: Array<string> = ['create', '--name', inputs.name, '--append'];
|
||||
if (node.name) {
|
||||
args.push('--node', node.name);
|
||||
}
|
||||
if (node['driver-opts'] && buildx.satisfies(buildxVersion, '>=0.3.0')) {
|
||||
await asyncForEach(node['driver-opts'], async driverOpt => {
|
||||
args.push('--driver-opt', driverOpt);
|
||||
});
|
||||
if (inputs.driver != 'remote' && node['buildkitd-flags']) {
|
||||
args.push('--buildkitd-flags', node['buildkitd-flags']);
|
||||
}
|
||||
}
|
||||
if (node.platforms) {
|
||||
args.push('--platform', node.platforms);
|
||||
}
|
||||
if (node.endpoint) {
|
||||
args.push(node.endpoint);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
export async function getInspectArgs(inputs: Inputs, buildxVersion: string): Promise<Array<string>> {
|
||||
const args: Array<string> = ['inspect', '--bootstrap'];
|
||||
if (buildx.satisfies(buildxVersion, '>=0.4.0')) {
|
||||
|
@ -88,14 +114,33 @@ export async function getInspectArgs(inputs: Inputs, buildxVersion: string): Pro
|
|||
}
|
||||
|
||||
export async function getInputList(name: string, ignoreComma?: boolean): Promise<string[]> {
|
||||
const res: Array<string> = [];
|
||||
|
||||
const items = core.getInput(name);
|
||||
if (items == '') {
|
||||
return [];
|
||||
return res;
|
||||
}
|
||||
return items
|
||||
.split(/\r?\n/)
|
||||
.filter(x => x)
|
||||
.reduce<string[]>((acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()), []);
|
||||
|
||||
const records = parse(items, {
|
||||
columns: false,
|
||||
relaxQuotes: true,
|
||||
comment: '#',
|
||||
relaxColumnCount: true,
|
||||
skipEmptyLines: true
|
||||
});
|
||||
|
||||
for (const record of records as Array<string[]>) {
|
||||
if (record.length == 1) {
|
||||
res.push(record[0]);
|
||||
continue;
|
||||
} else if (!ignoreComma) {
|
||||
res.push(...record);
|
||||
continue;
|
||||
}
|
||||
res.push(record.join(','));
|
||||
}
|
||||
|
||||
return res.filter(item => item).map(pat => pat.trim());
|
||||
}
|
||||
|
||||
export const asyncForEach = async (array, callback) => {
|
||||
|
|
27
src/main.ts
27
src/main.ts
|
@ -5,6 +5,7 @@ import * as auth from './auth';
|
|||
import * as buildx from './buildx';
|
||||
import * as context from './context';
|
||||
import * as docker from './docker';
|
||||
import * as nodes from './nodes';
|
||||
import * as stateHelper from './state-helper';
|
||||
import * as util from './util';
|
||||
import * as core from '@actions/core';
|
||||
|
@ -71,6 +72,21 @@ async function run(): Promise<void> {
|
|||
core.endGroup();
|
||||
}
|
||||
|
||||
if (inputs.append) {
|
||||
core.startGroup(`Appending node(s) to builder`);
|
||||
let nodeIndex = 1;
|
||||
for (const node of nodes.Parse(inputs.append)) {
|
||||
const authOpts = auth.setCredentials(credsdir, nodeIndex, inputs.driver, node.endpoint || '');
|
||||
if (authOpts.length > 0) {
|
||||
node['driver-opts'] = [...(node['driver-opts'] || []), ...authOpts];
|
||||
}
|
||||
const appendCmd = buildx.getCommand(await context.getAppendArgs(inputs, node, buildxVersion), standalone);
|
||||
await exec.exec(appendCmd.commandLine, appendCmd.args);
|
||||
nodeIndex++;
|
||||
}
|
||||
core.endGroup();
|
||||
}
|
||||
|
||||
core.startGroup(`Booting builder`);
|
||||
const inspectCmd = buildx.getCommand(await context.getInspectArgs(inputs, buildxVersion), standalone);
|
||||
await exec.exec(inspectCmd.commandLine, inspectCmd.args);
|
||||
|
@ -88,9 +104,18 @@ async function run(): Promise<void> {
|
|||
core.startGroup(`Inspect builder`);
|
||||
const builder = await buildx.inspect(inputs.name, standalone);
|
||||
const firstNode = builder.nodes[0];
|
||||
const reducedPlatforms: Array<string> = [];
|
||||
for (const node of builder.nodes) {
|
||||
for (const platform of node.platforms?.split(',') || []) {
|
||||
if (reducedPlatforms.indexOf(platform) > -1) {
|
||||
continue;
|
||||
}
|
||||
reducedPlatforms.push(platform);
|
||||
}
|
||||
}
|
||||
core.info(JSON.stringify(builder, undefined, 2));
|
||||
core.setOutput('driver', builder.driver);
|
||||
core.setOutput('platforms', firstNode.platforms);
|
||||
core.setOutput('platforms', reducedPlatforms.join(','));
|
||||
core.setOutput('nodes', JSON.stringify(builder.nodes, undefined, 2));
|
||||
core.setOutput('endpoint', firstNode.endpoint); // TODO: deprecated, to be removed in a later version
|
||||
core.setOutput('status', firstNode.status); // TODO: deprecated, to be removed in a later version
|
||||
|
|
13
src/nodes.ts
Normal file
13
src/nodes.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import * as yaml from 'js-yaml';
|
||||
|
||||
export type Node = {
|
||||
name?: string;
|
||||
endpoint?: string;
|
||||
'driver-opts'?: Array<string>;
|
||||
'buildkitd-flags'?: string;
|
||||
platforms?: string;
|
||||
};
|
||||
|
||||
export function Parse(data: string): Node[] {
|
||||
return yaml.load(data) as Node[];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue