assembled docker args

This commit is contained in:
2023-12-02 20:38:18 +01:00
parent 8b24f0e395
commit e35b2f2658
3 changed files with 72 additions and 12 deletions
+2
View File
@@ -46,6 +46,8 @@ try {
if (debug) {
console.log('dockerArgs:', JSON.stringify(dockerArgs, null, 2));
}
executeDockerBuild(dockerArgs);
}
catch (error) {
console.log('Failed to build docker image', error);
+33 -6
View File
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import * as child_process from 'child_process';
import * as fs from 'fs';
import {Base64} from 'js-base64';
import * as path from 'path';
@@ -124,6 +125,15 @@ export function prepareDestinations(registries, tags) {
return destinations;
}
export function getDockerContextDir() {
if (isNonEmptyStr(core.getInput('docker_context_dir'))) {
return core.getInput('docker_context_dir');
}
else {
return process.env['GITHUB_WORKSPACE'];
}
}
export function prepareDockerArgs(destinations) {
let dockerArgs = (core.getInput('docker_args') ?? '').trim();
if (dockerArgs.length > 0) {
@@ -137,12 +147,7 @@ export function prepareDockerArgs(destinations) {
dockerArgs.unshift('--file ' + core.getInput('dockerfile'));
}
if (isNonEmptyStr(core.getInput('docker_context_dir'))) {
dockerArgs.unshift(core.getInput('docker_context_dir'));
}
else {
dockerArgs.unshift(process.env['GITHUB_WORKSPACE']);
}
dockerArgs.unshift(getDockerContextDir());
if (core.getBooleanInput('squash_layers')) {
dockerArgs.push('--squash');
@@ -158,3 +163,25 @@ export function prepareDockerArgs(destinations) {
return dockerArgs;
}
export function executeDockerBuild(dockerArgs) {
const dockerArgsStr = dockerArgs.join(' ');
const proc = child_process.spawnSync('docker ' + dockerArgsStr, {
shell: true,
stdio: 'inherit',
cwd : getDockerContextDir()
});
// proc.on('exit', function (code, signal) {
// console.log(`docker process exited with code ${code} and signal ${signal}`);
// });
// proc.stdout.on('data', (data) => {
// console.log(`docker: ${data}`);
// });
//
// proc.stderr.on('data', (data) => {
// console.error(`docker: ${data}`);
// });
}