fix issues when building image with dockerfile

Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
This commit is contained in:
Luca Stocchi 2020-11-18 08:24:22 +01:00
parent 1b1386b77e
commit 504c52c4d8
No known key found for this signature in database
GPG key ID: 930BB00F3FCF30A4
5 changed files with 11 additions and 26 deletions

View file

@ -9,18 +9,17 @@ inputs:
description: 'The name (reference) of the image to build'
required: true
base-image:
description: 'The base image to use to create a new container'
description: 'The base image to use to create a new container image'
required: false
dockerfiles:
description: 'The path of one or more Dockerfiles (default: ./Dockerfile)'
description: 'List of Dockerfile paths (eg: ./Dockerfile)'
required: false
default: './Dockerfile'
context:
description: 'Path to the directory to use as context (default: .)'
required: false
default: '.'
content:
description: 'The content to copy inside the base image'
description: 'List of files/directories to copy inside the base image'
required: false
entrypoint:
description: 'The entry point to set for containers based on image'
@ -32,7 +31,7 @@ inputs:
description: 'The working directory to use within the container'
required: false
envs:
description: 'The environment variables to be set when running containers based on image'
description: 'List of environment variables to be set when running containers based on image'
required: false
runs:
using: 'node12'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -31,7 +31,7 @@ export class BuildahCli implements Buildah {
args.push('-f');
args.push(file);
});
args.push('t');
args.push('-t');
args.push(image);
args.push(context);
return await this.execute(args);

View file

@ -20,11 +20,7 @@ export async function run(): Promise<void> {
let dockerFiles = getInputList('dockerfiles');
const newImage = core.getInput('image');
dockerFiles = dockerFiles.map(file => path.join(workspace, file));
const dockerBuild = await isDockerBuild(workspace, dockerFiles);
if (dockerBuild) {
if (dockerFiles.length !== 0) {
doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles);
} else {
doBuildFromScratch(cli, newImage, workspace);
@ -33,6 +29,7 @@ export async function run(): Promise<void> {
async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[]): Promise<void> {
const context = path.join(workspace, core.getInput('context'));
dockerFiles = dockerFiles.map(file => path.join(workspace, file));
const build = await cli.buildUsingDocker(newImage, context, dockerFiles);
if (build.succeeded === false) {
return Promise.reject(new Error('Failed building an image from docker files.'));
@ -42,7 +39,6 @@ async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, worksp
async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace: string) {
let baseImage = core.getInput('base-image');
const content = getInputList('content');
const entrypoint = getInputList('entrypoint');
const port = core.getInput('port');
const workingDir = core.getInput('working-dir');
@ -90,16 +86,6 @@ async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace:
}
}
async function isDockerBuild(workspace: string, dockerFiles: string[]): Promise<boolean> {
for(const file of dockerFiles) {
const fileExists = (await fs.stat(path.join(workspace, file)).then(() => true).catch(() => false));
if (!fileExists) {
return false;
}
}
return true;
}
function getInputList(name: string): string[] {
const items = core.getInput(name);
if (!items) {