mirror of
https://github.com/docker/setup-buildx-action
synced 2024-11-24 19:31:42 +00:00
Support to retain cache
Signed-off-by: Balaji Arun <balajia@vt.edu>
This commit is contained in:
parent
a946f06b5d
commit
ff70196977
7 changed files with 52 additions and 9 deletions
|
@ -33,6 +33,7 @@ describe('getCreateArgs', () => {
|
|||
['install', 'false'],
|
||||
['use', 'true'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false']
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -50,6 +51,7 @@ describe('getCreateArgs', () => {
|
|||
['install', 'false'],
|
||||
['use', 'true'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false']
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -67,6 +69,7 @@ describe('getCreateArgs', () => {
|
|||
['use', 'false'],
|
||||
['driver-opts', 'image=moby/buildkit:master\nnetwork=host'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false']
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -86,6 +89,7 @@ describe('getCreateArgs', () => {
|
|||
['install', 'false'],
|
||||
['use', 'true'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false']
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -105,6 +109,7 @@ describe('getCreateArgs', () => {
|
|||
['install', 'false'],
|
||||
['use', 'true'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false']
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -123,6 +128,7 @@ describe('getCreateArgs', () => {
|
|||
['use', 'false'],
|
||||
['driver-opts', `"env.no_proxy=localhost,127.0.0.1,.mydomain"`],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false'],
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -140,6 +146,7 @@ describe('getCreateArgs', () => {
|
|||
['use', 'false'],
|
||||
['platforms', 'linux/amd64\n"linux/arm64,linux/arm/v7"'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false'],
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
|
@ -148,7 +155,25 @@ describe('getCreateArgs', () => {
|
|||
'--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
||||
'--platform', 'linux/amd64,linux/arm64,linux/arm/v7'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
7,
|
||||
'v0.10.3',
|
||||
new Map<string, string>([
|
||||
['install', 'false'],
|
||||
['use', 'true'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false'],
|
||||
['name', 'test-builder-name'],
|
||||
]),
|
||||
[
|
||||
'create',
|
||||
'--name', 'test-builder-name',
|
||||
'--driver', 'docker-container',
|
||||
'--buildkitd-flags', '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
||||
'--use'
|
||||
]
|
||||
],
|
||||
])(
|
||||
'[%d] given buildx %s and %p as inputs, returns %p',
|
||||
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {
|
||||
|
@ -185,6 +210,7 @@ describe('getAppendArgs', () => {
|
|||
['install', 'false'],
|
||||
['use', 'true'],
|
||||
['cleanup', 'true'],
|
||||
['keep-state', 'false']
|
||||
]),
|
||||
{
|
||||
"name": "aws_graviton2",
|
||||
|
|
|
@ -47,6 +47,12 @@ inputs:
|
|||
cleanup:
|
||||
description: 'Cleanup temp files and remove builder at the end of a job'
|
||||
default: 'true'
|
||||
keep-state:
|
||||
description: 'Keep state on cleanup'
|
||||
default: 'false'
|
||||
required: false
|
||||
name:
|
||||
description: 'Builder name use use when creating the builder. If not specified, one will be generated. Specifying a name enables reusing a buildkit volume in persistent self-hosted runners.'
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
|
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -21,12 +21,13 @@ export interface Inputs {
|
|||
configInline: string;
|
||||
append: string;
|
||||
cleanup: boolean;
|
||||
keepState: boolean;
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
return {
|
||||
version: core.getInput('version'),
|
||||
name: await getBuilderName(core.getInput('driver') || 'docker-container'),
|
||||
name: getBuilderName(core.getInput('name'), core.getInput('driver') || 'docker-container'),
|
||||
driver: core.getInput('driver') || 'docker-container',
|
||||
driverOpts: Util.getInputList('driver-opts', {ignoreComma: true, quote: false}),
|
||||
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
|
||||
|
@ -37,12 +38,16 @@ export async function getInputs(): Promise<Inputs> {
|
|||
config: core.getInput('config'),
|
||||
configInline: core.getInput('config-inline'),
|
||||
append: core.getInput('append'),
|
||||
cleanup: core.getBooleanInput('cleanup')
|
||||
cleanup: core.getBooleanInput('cleanup'),
|
||||
keepState: core.getBooleanInput('keep-state')
|
||||
};
|
||||
}
|
||||
|
||||
export async function getBuilderName(driver: string): Promise<string> {
|
||||
return driver == 'docker' ? await Docker.context() : `builder-${uuid.v4()}`;
|
||||
export function getBuilderName(name: string, driver: string): string {
|
||||
if (name) {
|
||||
return name;
|
||||
}
|
||||
return driver == 'docker' ? 'default' : `builder-${uuid.v4()}`;
|
||||
}
|
||||
|
||||
export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {
|
||||
|
|
|
@ -66,6 +66,8 @@ actionsToolkit.run(
|
|||
fs.mkdirSync(Buildx.certsDir, {recursive: true});
|
||||
stateHelper.setCertsDir(Buildx.certsDir);
|
||||
|
||||
stateHelper.setKeepState(inputs.keepState);
|
||||
|
||||
if (inputs.driver !== 'docker') {
|
||||
await core.group(`Creating a new builder instance`, async () => {
|
||||
const certsDriverOpts = Buildx.resolveCertsDriverOpts(inputs.driver, inputs.endpoint, {
|
||||
|
@ -176,7 +178,7 @@ actionsToolkit.run(
|
|||
const buildx = new Buildx({standalone: stateHelper.standalone});
|
||||
const builder = new Builder({buildx: buildx});
|
||||
if (await builder.exists(stateHelper.builderName)) {
|
||||
const rmCmd = await buildx.getCommand(['rm', stateHelper.builderName]);
|
||||
const rmCmd = await buildx.getCommand(['rm', stateHelper.builderName, stateHelper.keepState ? '--keep-state' : '']);
|
||||
await exec
|
||||
.getExecOutput(rmCmd.command, rmCmd.args, {
|
||||
ignoreReturnCode: true
|
||||
|
|
|
@ -7,7 +7,7 @@ export const builderDriver = process.env['STATE_builderDriver'] || '';
|
|||
export const containerName = process.env['STATE_containerName'] || '';
|
||||
export const certsDir = process.env['STATE_certsDir'] || '';
|
||||
export const cleanup = /true/i.test(process.env['STATE_cleanup'] || '');
|
||||
|
||||
export const keepState = !!process.env['STATE_keepState'];
|
||||
export function setDebug(debug: string) {
|
||||
core.saveState('isDebug', debug);
|
||||
}
|
||||
|
@ -35,3 +35,7 @@ export function setCertsDir(certsDir: string) {
|
|||
export function setCleanup(cleanup: boolean) {
|
||||
core.saveState('cleanup', cleanup);
|
||||
}
|
||||
|
||||
export function setKeepState(retain: boolean) {
|
||||
core.saveState('keepState', retain);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue