From 54d567b2354e88eff94ab1a52fd1f77a42423c1c Mon Sep 17 00:00:00 2001 From: Tim Etchells Date: Mon, 23 Nov 2020 14:03:32 -0500 Subject: [PATCH] Add build-args input Signed-off-by: Tim Etchells --- README.md | 11 ++++++++++- action.yml | 3 +++ src/buildah.ts | 16 ++++++++++------ src/index.ts | 3 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index af84702..ccd44c8 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,13 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti Default: . + + build-args + No + Build arguments to pass to the Docker build using --build-arg, if using a Dockerfile that requires ARGs.
+ Uses the form arg_name=arg_value, and separate arguments with newlines. + + content No @@ -109,7 +116,7 @@ You can configure the `buildah` action to build your image using one or more Doc If you have been using Docker and have an existing Dockerfile, `buildah` can reuse your dockerfile. -In this case the inputs needed are `image` and `dockerfiles`. `tag` is also recommended. +In this case the inputs needed are `image` and `dockerfiles`. `tag` is also recommended. If your Dockerfile requires ARGs, these can be passed using `build-arg`. ```yaml name: Build Image using Dockerfile @@ -130,6 +137,8 @@ jobs: tag: v1 dockerfiles: | ./Dockerfile + build-args: | + some_arg=some_value ``` ### Building from scratch diff --git a/action.yml b/action.yml index f869936..f76bb8a 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,9 @@ inputs: envs: description: 'List of environment variables to be set when running containers based on image' required: false + build-args: + description: 'List of --build-args to pass to buildah.' + required: false runs: using: 'node12' main: 'dist/index.js' diff --git a/src/buildah.ts b/src/buildah.ts index 58d4a89..00ee13e 100644 --- a/src/buildah.ts +++ b/src/buildah.ts @@ -3,7 +3,7 @@ import * as exec from "@actions/exec"; import { CommandResult } from "./types"; interface Buildah { - buildUsingDocker(image: string, context: string, dockerFiles: string[]): Promise; + buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[]): Promise; from(baseImage: string): Promise; copy(container: string, contentToCopy: string[]): Promise; config(container: string, setting: {}): Promise; @@ -25,12 +25,16 @@ export class BuildahCli implements Buildah { this.executable = executable; } - async buildUsingDocker(image: string, context: string, dockerFiles: string[]): Promise { + async buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[]): Promise { const args: string[] = ['bud']; dockerFiles.forEach(file => { args.push('-f'); args.push(file); }); + buildArgs.forEach((buildArg) => { + args.push('--build-arg'); + args.push(buildArg); + }) args.push('-t'); args.push(image); args.push(context); @@ -55,7 +59,7 @@ export class BuildahCli implements Buildah { return result; } } - + return result; } @@ -104,7 +108,7 @@ export class BuildahCli implements Buildah { let output = ''; let error = ''; - + const options: exec.ExecOptions = {}; options.listeners = { stdout: (data: Buffer): void => { @@ -117,7 +121,7 @@ export class BuildahCli implements Buildah { const exitCode = await exec.exec(this.executable, args, options); if (exitCode === 1) { return Promise.resolve({ succeeded: false, error }); - } + } return Promise.resolve({ succeeded: true, output }); } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index d9b5a7d..8cc0394 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,8 +29,9 @@ export async function run(): Promise { async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[]): Promise { const context = path.join(workspace, core.getInput('context')); + const buildArgs = getInputList(core.getInput('build-args')); dockerFiles = dockerFiles.map(file => path.join(workspace, file)); - const build = await cli.buildUsingDocker(newImage, context, dockerFiles); + const build = await cli.buildUsingDocker(newImage, context, dockerFiles, buildArgs); if (build.succeeded === false) { return Promise.reject(new Error('Failed building an image from docker files.')); }