2022-09-19 17:36:58 +08:00
|
|
|
import * as uuid from 'uuid';
|
2020-09-03 22:23:15 +08:00
|
|
|
import * as core from '@actions/core';
|
2023-02-25 23:16:08 +08:00
|
|
|
import {Docker} from '@docker/actions-toolkit/lib/docker';
|
2023-02-19 09:12:29 +08:00
|
|
|
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';
|
2020-09-03 22:23:15 +08:00
|
|
|
|
2023-02-19 09:12:29 +08:00
|
|
|
export const builderNodeEnvPrefix = 'BUILDER_NODE';
|
2021-09-04 04:21:20 +08:00
|
|
|
|
2020-09-03 22:23:15 +08:00
|
|
|
export interface Inputs {
|
|
|
|
version: string;
|
2022-09-19 17:36:58 +08:00
|
|
|
name: string;
|
2020-09-03 22:23:15 +08:00
|
|
|
driver: string;
|
|
|
|
driverOpts: string[];
|
|
|
|
buildkitdFlags: string;
|
2022-09-22 17:54:00 +08:00
|
|
|
platforms: string[];
|
2020-09-03 22:23:15 +08:00
|
|
|
install: boolean;
|
|
|
|
use: boolean;
|
2020-09-08 21:52:09 +08:00
|
|
|
endpoint: string;
|
2021-04-22 01:37:54 +08:00
|
|
|
config: string;
|
2021-09-04 04:21:20 +08:00
|
|
|
configInline: string;
|
2022-09-19 17:34:47 +08:00
|
|
|
append: string;
|
2023-03-03 18:56:21 +08:00
|
|
|
cleanup: boolean;
|
2020-09-03 22:23:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getInputs(): Promise<Inputs> {
|
|
|
|
return {
|
|
|
|
version: core.getInput('version'),
|
2023-02-25 23:16:08 +08:00
|
|
|
name: await getBuilderName(core.getInput('driver') || 'docker-container'),
|
2020-09-03 22:23:15 +08:00
|
|
|
driver: core.getInput('driver') || 'docker-container',
|
2023-02-19 09:12:29 +08:00
|
|
|
driverOpts: Util.getInputList('driver-opts', {ignoreComma: true, quote: false}),
|
2021-07-02 13:02:22 +08:00
|
|
|
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
2023-02-19 09:12:29 +08:00
|
|
|
platforms: Util.getInputList('platforms'),
|
2021-06-23 21:43:25 +08:00
|
|
|
install: core.getBooleanInput('install'),
|
|
|
|
use: core.getBooleanInput('use'),
|
2021-04-22 01:37:54 +08:00
|
|
|
endpoint: core.getInput('endpoint'),
|
2021-09-04 04:21:20 +08:00
|
|
|
config: core.getInput('config'),
|
2022-09-19 17:34:47 +08:00
|
|
|
configInline: core.getInput('config-inline'),
|
2023-03-03 18:56:21 +08:00
|
|
|
append: core.getInput('append'),
|
|
|
|
cleanup: core.getBooleanInput('cleanup')
|
2020-09-03 22:23:15 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-25 23:16:08 +08:00
|
|
|
export async function getBuilderName(driver: string): Promise<string> {
|
|
|
|
return driver == 'docker' ? await Docker.context() : `builder-${uuid.v4()}`;
|
2022-09-19 17:36:58 +08:00
|
|
|
}
|
|
|
|
|
2023-02-19 09:12:29 +08:00
|
|
|
export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
2022-09-19 17:36:58 +08:00
|
|
|
const args: Array<string> = ['create', '--name', inputs.name, '--driver', inputs.driver];
|
2023-02-19 09:12:29 +08:00
|
|
|
if (await toolkit.buildx.versionSatisfies('>=0.3.0')) {
|
|
|
|
await Util.asyncForEach(inputs.driverOpts, async driverOpt => {
|
2022-09-19 17:36:58 +08:00
|
|
|
args.push('--driver-opt', driverOpt);
|
|
|
|
});
|
|
|
|
if (inputs.driver != 'remote' && inputs.buildkitdFlags) {
|
|
|
|
args.push('--buildkitd-flags', inputs.buildkitdFlags);
|
|
|
|
}
|
|
|
|
}
|
2022-09-22 17:54:00 +08:00
|
|
|
if (inputs.platforms.length > 0) {
|
|
|
|
args.push('--platform', inputs.platforms.join(','));
|
|
|
|
}
|
2022-09-19 17:36:58 +08:00
|
|
|
if (inputs.use) {
|
|
|
|
args.push('--use');
|
|
|
|
}
|
|
|
|
if (inputs.driver != 'remote') {
|
|
|
|
if (inputs.config) {
|
2023-02-19 09:12:29 +08:00
|
|
|
args.push('--config', toolkit.buildkit.config.resolveFromFile(inputs.config));
|
2022-09-19 17:36:58 +08:00
|
|
|
} else if (inputs.configInline) {
|
2023-02-19 09:12:29 +08:00
|
|
|
args.push('--config', toolkit.buildkit.config.resolveFromString(inputs.configInline));
|
2022-09-19 17:36:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inputs.endpoint) {
|
|
|
|
args.push(inputs.endpoint);
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2023-02-19 09:12:29 +08:00
|
|
|
export async function getAppendArgs(inputs: Inputs, node: Node, toolkit: Toolkit): Promise<Array<string>> {
|
2022-09-19 17:34:47 +08:00
|
|
|
const args: Array<string> = ['create', '--name', inputs.name, '--append'];
|
|
|
|
if (node.name) {
|
|
|
|
args.push('--node', node.name);
|
|
|
|
}
|
2023-02-19 09:12:29 +08:00
|
|
|
if (node['driver-opts'] && (await toolkit.buildx.versionSatisfies('>=0.3.0'))) {
|
|
|
|
await Util.asyncForEach(node['driver-opts'], async driverOpt => {
|
2022-09-19 17:34:47 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-19 09:12:29 +08:00
|
|
|
export async function getInspectArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
2022-09-19 17:36:58 +08:00
|
|
|
const args: Array<string> = ['inspect', '--bootstrap'];
|
2023-02-19 09:12:29 +08:00
|
|
|
if (await toolkit.buildx.versionSatisfies('>=0.4.0')) {
|
2022-09-19 17:36:58 +08:00
|
|
|
args.push('--builder', inputs.name);
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|