mirror of
https://github.com/docker/setup-buildx-action.git
synced 2025-04-20 09:36:45 +00:00
move args logic to context module and add tests
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
6c48dad5f0
commit
5a9fc40575
5 changed files with 145 additions and 41 deletions
|
@ -2,6 +2,8 @@ import fs from 'fs';
|
|||
import * as os from 'os';
|
||||
import path from 'path';
|
||||
import * as tmp from 'tmp';
|
||||
import * as uuid from 'uuid';
|
||||
import * as buildx from './buildx';
|
||||
import * as core from '@actions/core';
|
||||
import {issueCommand} from '@actions/core/lib/command';
|
||||
|
||||
|
@ -22,6 +24,7 @@ export function tmpNameSync(options?: tmp.TmpNameOptions): string {
|
|||
|
||||
export interface Inputs {
|
||||
version: string;
|
||||
name: string;
|
||||
driver: string;
|
||||
driverOpts: string[];
|
||||
buildkitdFlags: string;
|
||||
|
@ -35,6 +38,7 @@ export interface Inputs {
|
|||
export async function getInputs(): Promise<Inputs> {
|
||||
return {
|
||||
version: core.getInput('version'),
|
||||
name: getBuilderName(core.getInput('driver') || 'docker-container'),
|
||||
driver: core.getInput('driver') || 'docker-container',
|
||||
driverOpts: await getInputList('driver-opts', true),
|
||||
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
||||
|
@ -46,6 +50,44 @@ export async function getInputs(): Promise<Inputs> {
|
|||
};
|
||||
}
|
||||
|
||||
export function getBuilderName(driver: string): string {
|
||||
return driver == 'docker' ? 'default' : `builder-${uuid.v4()}`;
|
||||
}
|
||||
|
||||
export async function getCreateArgs(inputs: Inputs, buildxVersion: string): 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 => {
|
||||
args.push('--driver-opt', driverOpt);
|
||||
});
|
||||
if (inputs.driver != 'remote' && inputs.buildkitdFlags) {
|
||||
args.push('--buildkitd-flags', inputs.buildkitdFlags);
|
||||
}
|
||||
}
|
||||
if (inputs.use) {
|
||||
args.push('--use');
|
||||
}
|
||||
if (inputs.driver != 'remote') {
|
||||
if (inputs.config) {
|
||||
args.push('--config', await buildx.getConfigFile(inputs.config));
|
||||
} else if (inputs.configInline) {
|
||||
args.push('--config', await buildx.getConfigInline(inputs.configInline));
|
||||
}
|
||||
}
|
||||
if (inputs.endpoint) {
|
||||
args.push(inputs.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')) {
|
||||
args.push('--builder', inputs.name);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
export async function getInputList(name: string, ignoreComma?: boolean): Promise<string[]> {
|
||||
const items = core.getInput(name);
|
||||
if (items == '') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue