mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-04-20 01:26:46 +00:00
switch to actions-toolkit implementation
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
2dd22fa31c
commit
987520896f
28 changed files with 209 additions and 1271 deletions
|
@ -1,27 +1,10 @@
|
|||
import fs from 'fs';
|
||||
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';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
import {Node} from '@docker/actions-toolkit/lib/types/builder';
|
||||
|
||||
let _tmpDir: string;
|
||||
export const osPlat: string = os.platform();
|
||||
export const osArch: string = os.arch();
|
||||
|
||||
export function tmpDir(): string {
|
||||
if (!_tmpDir) {
|
||||
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-setup-buildx-')).split(path.sep).join(path.posix.sep);
|
||||
}
|
||||
return _tmpDir;
|
||||
}
|
||||
|
||||
export function tmpNameSync(options?: tmp.TmpNameOptions): string {
|
||||
return tmp.tmpNameSync(options);
|
||||
}
|
||||
export const builderNodeEnvPrefix = 'BUILDER_NODE';
|
||||
|
||||
export interface Inputs {
|
||||
version: string;
|
||||
|
@ -43,9 +26,9 @@ export async function getInputs(): Promise<Inputs> {
|
|||
version: core.getInput('version'),
|
||||
name: getBuilderName(core.getInput('driver') || 'docker-container'),
|
||||
driver: core.getInput('driver') || 'docker-container',
|
||||
driverOpts: await getInputList('driver-opts', true),
|
||||
driverOpts: Util.getInputList('driver-opts', {ignoreComma: true, quote: false}),
|
||||
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
||||
platforms: await getInputList('platforms', false, true),
|
||||
platforms: Util.getInputList('platforms'),
|
||||
install: core.getBooleanInput('install'),
|
||||
use: core.getBooleanInput('use'),
|
||||
endpoint: core.getInput('endpoint'),
|
||||
|
@ -59,10 +42,10 @@ export function getBuilderName(driver: string): string {
|
|||
return driver == 'docker' ? 'default' : `builder-${uuid.v4()}`;
|
||||
}
|
||||
|
||||
export async function getCreateArgs(inputs: Inputs, buildxVersion: string): Promise<Array<string>> {
|
||||
export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
||||
const args: Array<string> = ['create', '--name', inputs.name, '--driver', inputs.driver];
|
||||
if (buildx.satisfies(buildxVersion, '>=0.3.0')) {
|
||||
await asyncForEach(inputs.driverOpts, async driverOpt => {
|
||||
if (await toolkit.buildx.versionSatisfies('>=0.3.0')) {
|
||||
await Util.asyncForEach(inputs.driverOpts, async driverOpt => {
|
||||
args.push('--driver-opt', driverOpt);
|
||||
});
|
||||
if (inputs.driver != 'remote' && inputs.buildkitdFlags) {
|
||||
|
@ -77,9 +60,9 @@ export async function getCreateArgs(inputs: Inputs, buildxVersion: string): Prom
|
|||
}
|
||||
if (inputs.driver != 'remote') {
|
||||
if (inputs.config) {
|
||||
args.push('--config', await buildx.getConfigFile(inputs.config));
|
||||
args.push('--config', toolkit.buildkit.config.resolveFromFile(inputs.config));
|
||||
} else if (inputs.configInline) {
|
||||
args.push('--config', await buildx.getConfigInline(inputs.configInline));
|
||||
args.push('--config', toolkit.buildkit.config.resolveFromString(inputs.configInline));
|
||||
}
|
||||
}
|
||||
if (inputs.endpoint) {
|
||||
|
@ -88,13 +71,13 @@ 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>> {
|
||||
export async function getAppendArgs(inputs: Inputs, node: Node, toolkit: Toolkit): 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 => {
|
||||
if (node['driver-opts'] && (await toolkit.buildx.versionSatisfies('>=0.3.0'))) {
|
||||
await Util.asyncForEach(node['driver-opts'], async driverOpt => {
|
||||
args.push('--driver-opt', driverOpt);
|
||||
});
|
||||
if (inputs.driver != 'remote' && node['buildkitd-flags']) {
|
||||
|
@ -110,47 +93,10 @@ export async function getAppendArgs(inputs: Inputs, node: nodes.Node, buildxVers
|
|||
return args;
|
||||
}
|
||||
|
||||
export async function getInspectArgs(inputs: Inputs, buildxVersion: string): Promise<Array<string>> {
|
||||
export async function getInspectArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
||||
const args: Array<string> = ['inspect', '--bootstrap'];
|
||||
if (buildx.satisfies(buildxVersion, '>=0.4.0')) {
|
||||
if (await toolkit.buildx.versionSatisfies('>=0.4.0')) {
|
||||
args.push('--builder', inputs.name);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
export async function getInputList(name: string, ignoreComma?: boolean, escapeQuotes?: boolean): Promise<string[]> {
|
||||
const res: Array<string> = [];
|
||||
|
||||
const items = core.getInput(name);
|
||||
if (items == '') {
|
||||
return res;
|
||||
}
|
||||
|
||||
const records = parse(items, {
|
||||
columns: false,
|
||||
relaxQuotes: true,
|
||||
comment: '#',
|
||||
relaxColumnCount: true,
|
||||
skipEmptyLines: true,
|
||||
quote: escapeQuotes ? `"` : false
|
||||
});
|
||||
|
||||
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) => {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue