Add build-args input

Signed-off-by: Tim Etchells <tetchell@redhat.com>
This commit is contained in:
Tim Etchells 2020-11-23 14:03:32 -05:00
parent 4e70c85f52
commit 54d567b235
4 changed files with 25 additions and 8 deletions

View file

@ -58,6 +58,13 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
Default: <code>.</code></td>
</tr>
<tr>
<td>build-args</td>
<td>No</td>
<td>Build arguments to pass to the Docker build using <code>--build-arg</code>, if using a Dockerfile that requires ARGs.<br>
Uses the form <code>arg_name=arg_value</code>, and separate arguments with newlines.</td>
</tr>
<tr>
<td>content</td>
<td>No</td>
@ -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

View file

@ -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'

View file

@ -3,7 +3,7 @@ import * as exec from "@actions/exec";
import { CommandResult } from "./types";
interface Buildah {
buildUsingDocker(image: string, context: string, dockerFiles: string[]): Promise<CommandResult>;
buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[]): Promise<CommandResult>;
from(baseImage: string): Promise<CommandResult>;
copy(container: string, contentToCopy: string[]): Promise<CommandResult>;
config(container: string, setting: {}): Promise<CommandResult>;
@ -25,12 +25,16 @@ export class BuildahCli implements Buildah {
this.executable = executable;
}
async buildUsingDocker(image: string, context: string, dockerFiles: string[]): Promise<CommandResult> {
async buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[]): Promise<CommandResult> {
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);

View file

@ -29,8 +29,9 @@ 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'));
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.'));
}