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' description: 'The name (reference) of the image to build'
required: true required: true
base-image: 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 required: false
dockerfiles: dockerfiles:
description: 'The path of one or more Dockerfiles (default: ./Dockerfile)' description: 'List of Dockerfile paths (eg: ./Dockerfile)'
required: false required: false
default: './Dockerfile'
context: context:
description: 'Path to the directory to use as context (default: .)' description: 'Path to the directory to use as context (default: .)'
required: false required: false
default: '.' default: '.'
content: content:
description: 'The content to copy inside the base image' description: 'List of files/directories to copy inside the base image'
required: false required: false
entrypoint: entrypoint:
description: 'The entry point to set for containers based on image' 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' description: 'The working directory to use within the container'
required: false required: false
envs: 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 required: false
runs: runs:
using: 'node12' 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('-f');
args.push(file); args.push(file);
}); });
args.push('t'); args.push('-t');
args.push(image); args.push(image);
args.push(context); args.push(context);
return await this.execute(args); return await this.execute(args);

View file

@ -20,11 +20,7 @@ export async function run(): Promise<void> {
let dockerFiles = getInputList('dockerfiles'); let dockerFiles = getInputList('dockerfiles');
const newImage = core.getInput('image'); const newImage = core.getInput('image');
dockerFiles = dockerFiles.map(file => path.join(workspace, file)); if (dockerFiles.length !== 0) {
const dockerBuild = await isDockerBuild(workspace, dockerFiles);
if (dockerBuild) {
doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles); doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles);
} else { } else {
doBuildFromScratch(cli, newImage, workspace); 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> { async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[]): Promise<void> {
const context = path.join(workspace, core.getInput('context')); const context = path.join(workspace, core.getInput('context'));
dockerFiles = dockerFiles.map(file => path.join(workspace, file));
const build = await cli.buildUsingDocker(newImage, context, dockerFiles); const build = await cli.buildUsingDocker(newImage, context, dockerFiles);
if (build.succeeded === false) { if (build.succeeded === false) {
return Promise.reject(new Error('Failed building an image from docker files.')); 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) { async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace: string) {
let baseImage = core.getInput('base-image'); let baseImage = core.getInput('base-image');
const content = getInputList('content'); const content = getInputList('content');
const entrypoint = getInputList('entrypoint'); const entrypoint = getInputList('entrypoint');
const port = core.getInput('port'); const port = core.getInput('port');
const workingDir = core.getInput('working-dir'); 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[] { function getInputList(name: string): string[] {
const items = core.getInput(name); const items = core.getInput(name);
if (!items) { if (!items) {