From 9d76cc20742e8cb0e9224971c3c0e10332a09cb9 Mon Sep 17 00:00:00 2001 From: David Hiendl Date: Sat, 2 Dec 2023 21:52:09 +0100 Subject: [PATCH] assembled docker args --- action.yml | 2 +- dist/index.js | 33 +++++++++++++++++++++++++++++---- src/action.js | 2 +- src/lib.js | 31 ++++++++++++++++++++++++++++--- 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index c9fee3b..bd9e988 100644 --- a/action.yml +++ b/action.yml @@ -72,7 +72,7 @@ inputs: description: "" default: "true" - push_tags: + docker_push: description: "" default: "true" diff --git a/dist/index.js b/dist/index.js index 4048fa4..d286f74 100644 --- a/dist/index.js +++ b/dist/index.js @@ -62266,16 +62266,41 @@ function prepareDockerArgs(destinations) { return dockerArgs; } -function executeDockerBuild(dockerArgs) { +function executeDockerBuild(dockerArgs, destinations) { const dockerArgsStr = dockerArgs.join(' '); - const dockerSubCmd = core.getBooleanInput('use_buildx') ? 'buildx build' : 'build'; + const isBuildX = core.getBooleanInput('use_buildx'); + let dockerSubCmd = isBuildX ? 'buildx build' : 'build'; + if (core.getBooleanInput('docker_push')) { + dockerSubCmd += ' --push'; + } + const execStr = `docker ${dockerSubCmd} ${dockerArgsStr}`; + console.log(`executing: ${execStr}`); - const proc = external_child_process_namespaceObject.spawnSync(`docker ${dockerSubCmd} ${dockerArgsStr}`, { + const proc = external_child_process_namespaceObject.spawnSync(execStr, { shell: true, stdio: 'inherit', cwd : getDockerContextDir() }); + // push for legacy builder + // if (!isBuildX && core.getBooleanInput('docker_push')) { + // destinations.forEach(dst => { + // const pushProc = child_process.spawnSync('docker push ' + dst, { + // shell: true, + // stdio: 'inherit', + // cwd : getDockerContextDir() + // }); + // if (pushProc.status != null && pushProc.status > 0) { + // throw new Error('docker push ' + dst + ' failed'); + // } + // }); + // } + + if (proc.status != null && proc.status > 0) { + throw new Error('docker build failed'); + } + + console.log('proc error check'); // TODO remove debug if (proc.error != null) { throw proc.error; } @@ -62324,7 +62349,7 @@ try { console.log('dockerArgs:', JSON.stringify(dockerArgs, null, 2)); } - executeDockerBuild(dockerArgs); + executeDockerBuild(dockerArgs, destinations); } catch (error) { console.log('Failed to build docker image', error); diff --git a/src/action.js b/src/action.js index f76aca9..2316bb3 100644 --- a/src/action.js +++ b/src/action.js @@ -47,7 +47,7 @@ try { console.log('dockerArgs:', JSON.stringify(dockerArgs, null, 2)); } - executeDockerBuild(dockerArgs); + executeDockerBuild(dockerArgs, destinations); } catch (error) { console.log('Failed to build docker image', error); diff --git a/src/lib.js b/src/lib.js index 72a8f4f..75ab61e 100644 --- a/src/lib.js +++ b/src/lib.js @@ -164,16 +164,41 @@ export function prepareDockerArgs(destinations) { return dockerArgs; } -export function executeDockerBuild(dockerArgs) { +export function executeDockerBuild(dockerArgs, destinations) { const dockerArgsStr = dockerArgs.join(' '); - const dockerSubCmd = core.getBooleanInput('use_buildx') ? 'buildx build' : 'build'; + const isBuildX = core.getBooleanInput('use_buildx'); + let dockerSubCmd = isBuildX ? 'buildx build' : 'build'; + if (core.getBooleanInput('docker_push')) { + dockerSubCmd += ' --push'; + } + const execStr = `docker ${dockerSubCmd} ${dockerArgsStr}`; + console.log(`executing: ${execStr}`); - const proc = child_process.spawnSync(`docker ${dockerSubCmd} ${dockerArgsStr}`, { + const proc = child_process.spawnSync(execStr, { shell: true, stdio: 'inherit', cwd : getDockerContextDir() }); + // push for legacy builder + // if (!isBuildX && core.getBooleanInput('docker_push')) { + // destinations.forEach(dst => { + // const pushProc = child_process.spawnSync('docker push ' + dst, { + // shell: true, + // stdio: 'inherit', + // cwd : getDockerContextDir() + // }); + // if (pushProc.status != null && pushProc.status > 0) { + // throw new Error('docker push ' + dst + ' failed'); + // } + // }); + // } + + if (proc.status != null && proc.status > 0) { + throw new Error('docker build failed'); + } + + console.log('proc error check'); // TODO remove debug if (proc.error != null) { throw proc.error; }