mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-19 00:41:23 +00:00
Add extra-args input for build using dockerfile (#53)
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
b78bde0b60
commit
2f7f68ec84
10 changed files with 59 additions and 5 deletions
2
.github/workflows/dockerfile_build.yml
vendored
2
.github/workflows/dockerfile_build.yml
vendored
|
@ -41,6 +41,8 @@ jobs:
|
||||||
tags: 'latest ${{ github.sha }}'
|
tags: 'latest ${{ github.sha }}'
|
||||||
dockerfiles: |
|
dockerfiles: |
|
||||||
./Dockerfile
|
./Dockerfile
|
||||||
|
extra-args: |
|
||||||
|
--pull
|
||||||
|
|
||||||
- name: Echo Outputs
|
- name: Echo Outputs
|
||||||
run: |
|
run: |
|
||||||
|
|
|
@ -29,6 +29,7 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
|
||||||
| build-args | Build arguments to pass to the Docker build using `--build-arg`, if using a Dockerfile that requires ARGs. Use the form `arg_name=arg_value`, and separate arguments with newlines. | None
|
| build-args | Build arguments to pass to the Docker build using `--build-arg`, if using a Dockerfile that requires ARGs. Use the form `arg_name=arg_value`, and separate arguments with newlines. | None
|
||||||
| context | Path to directory to use as the build context. | `.`
|
| context | Path to directory to use as the build context. | `.`
|
||||||
| dockerfiles | The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to allow multiple Dockerfiles. | **Must be provided**
|
| dockerfiles | The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to allow multiple Dockerfiles. | **Must be provided**
|
||||||
|
| extra-args | Extra args to be passed to buildah bud. Separate arguments by newline. Do not use quotes. | None
|
||||||
| image | Name to give to the output image. | **Must be provided**
|
| image | Name to give to the output image. | **Must be provided**
|
||||||
| layers | Set to true to cache intermediate layers during the build process. | None
|
| layers | Set to true to cache intermediate layers during the build process. | None
|
||||||
| oci | Build the image using the OCI format, instead of the Docker format. By default, this is `false`, because images built using the OCI format have issues when published to Dockerhub. | `false`
|
| oci | Build the image using the OCI format, instead of the Docker format. By default, this is `false`, because images built using the OCI format have issues when published to Dockerhub. | `false`
|
||||||
|
|
|
@ -53,6 +53,11 @@ inputs:
|
||||||
separate by a comma.
|
separate by a comma.
|
||||||
default: 'amd64'
|
default: 'amd64'
|
||||||
required: false
|
required: false
|
||||||
|
extra-args:
|
||||||
|
description: |
|
||||||
|
Extra args to be passed to buildah bud.
|
||||||
|
Separate arguments by newline. Do not use quotes - @actions/exec will do the quoting for you.
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
image:
|
image:
|
||||||
description: 'Name of the image built'
|
description: 'Name of the image built'
|
||||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,8 @@
|
||||||
|
/***************************************************************************************************
|
||||||
|
* Copyright (c) Red Hat, Inc. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
||||||
|
**************************************************************************************************/
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
@ -15,7 +20,7 @@ export interface BuildahConfigSettings {
|
||||||
interface Buildah {
|
interface Buildah {
|
||||||
buildUsingDocker(
|
buildUsingDocker(
|
||||||
image: string, context: string, dockerFiles: string[], buildArgs: string[],
|
image: string, context: string, dockerFiles: string[], buildArgs: string[],
|
||||||
useOCI: boolean, archs: string, layers: string
|
useOCI: boolean, archs: string, layers: string, extraArgs: string[]
|
||||||
): Promise<CommandResult>;
|
): Promise<CommandResult>;
|
||||||
from(baseImage: string): Promise<CommandResult>;
|
from(baseImage: string): Promise<CommandResult>;
|
||||||
copy(container: string, contentToCopy: string[]): Promise<CommandResult | undefined>;
|
copy(container: string, contentToCopy: string[]): Promise<CommandResult | undefined>;
|
||||||
|
@ -58,7 +63,7 @@ export class BuildahCli implements Buildah {
|
||||||
|
|
||||||
async buildUsingDocker(
|
async buildUsingDocker(
|
||||||
image: string, context: string, dockerFiles: string[], buildArgs: string[],
|
image: string, context: string, dockerFiles: string[], buildArgs: string[],
|
||||||
useOCI: boolean, archs: string, layers: string
|
useOCI: boolean, archs: string, layers: string, extraArgs: string[]
|
||||||
): Promise<CommandResult> {
|
): Promise<CommandResult> {
|
||||||
const args: string[] = [ "bud" ];
|
const args: string[] = [ "bud" ];
|
||||||
if (archs) {
|
if (archs) {
|
||||||
|
@ -77,6 +82,9 @@ export class BuildahCli implements Buildah {
|
||||||
if (layers) {
|
if (layers) {
|
||||||
args.push(`--layers=${layers}`);
|
args.push(`--layers=${layers}`);
|
||||||
}
|
}
|
||||||
|
if (extraArgs.length > 0) {
|
||||||
|
args.push(...extraArgs);
|
||||||
|
}
|
||||||
args.push("-t");
|
args.push("-t");
|
||||||
args.push(image);
|
args.push(image);
|
||||||
args.push(context);
|
args.push(context);
|
||||||
|
|
|
@ -49,6 +49,13 @@ export enum Inputs {
|
||||||
* Default: None.
|
* Default: None.
|
||||||
*/
|
*/
|
||||||
ENVS = "envs",
|
ENVS = "envs",
|
||||||
|
/**
|
||||||
|
* Extra args to be passed to buildah bud.
|
||||||
|
* Separate arguments by newline. Do not use quotes - @actions/exec will do the quoting for you.
|
||||||
|
* Required: false
|
||||||
|
* Default: None.
|
||||||
|
*/
|
||||||
|
EXTRA_ARGS = "extra-args",
|
||||||
/**
|
/**
|
||||||
* The name (reference) of the image to build
|
* The name (reference) of the image to build
|
||||||
* Required: true
|
* Required: true
|
||||||
|
|
19
src/index.ts
19
src/index.ts
|
@ -1,8 +1,14 @@
|
||||||
|
/***************************************************************************************************
|
||||||
|
* Copyright (c) Red Hat, Inc. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
||||||
|
**************************************************************************************************/
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { Inputs, Outputs } from "./generated/inputs-outputs";
|
import { Inputs, Outputs } from "./generated/inputs-outputs";
|
||||||
import { BuildahCli, BuildahConfigSettings } from "./buildah";
|
import { BuildahCli, BuildahConfigSettings } from "./buildah";
|
||||||
|
import { splitByNewline } from "./utils";
|
||||||
|
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
if (process.env.RUNNER_OS !== "Linux") {
|
if (process.env.RUNNER_OS !== "Linux") {
|
||||||
|
@ -65,7 +71,18 @@ async function doBuildUsingDockerFiles(
|
||||||
const buildArgs = getInputList(Inputs.BUILD_ARGS);
|
const buildArgs = getInputList(Inputs.BUILD_ARGS);
|
||||||
const dockerFileAbsPaths = dockerFiles.map((file) => path.join(workspace, file));
|
const dockerFileAbsPaths = dockerFiles.map((file) => path.join(workspace, file));
|
||||||
const layers = core.getInput(Inputs.LAYERS);
|
const layers = core.getInput(Inputs.LAYERS);
|
||||||
await cli.buildUsingDocker(newImage, context, dockerFileAbsPaths, buildArgs, useOCI, archs, layers);
|
|
||||||
|
const inputExtraArgsStr = core.getInput(Inputs.EXTRA_ARGS);
|
||||||
|
let buildahBudExtraArgs: string[] = [];
|
||||||
|
if (inputExtraArgsStr) {
|
||||||
|
// transform the array of lines into an array of arguments
|
||||||
|
// by splitting over lines, then over spaces, then trimming.
|
||||||
|
const lines = splitByNewline(inputExtraArgsStr);
|
||||||
|
buildahBudExtraArgs = lines.flatMap((line) => line.split(" ")).map((arg) => arg.trim());
|
||||||
|
}
|
||||||
|
await cli.buildUsingDocker(
|
||||||
|
newImage, context, dockerFileAbsPaths, buildArgs, useOCI, archs, layers, buildahBudExtraArgs
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doBuildFromScratch(
|
async function doBuildFromScratch(
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/***************************************************************************************************
|
||||||
|
* Copyright (c) Red Hat, Inc. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
||||||
|
**************************************************************************************************/
|
||||||
|
|
||||||
type CommandResult = {
|
type CommandResult = {
|
||||||
exitCode: number
|
exitCode: number
|
||||||
output: string
|
output: string
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
/***************************************************************************************************
|
||||||
|
* Copyright (c) Red Hat, Inc. All rights reserved.
|
||||||
|
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
||||||
|
**************************************************************************************************/
|
||||||
|
|
||||||
import * as ini from "ini";
|
import * as ini from "ini";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
@ -54,3 +59,7 @@ export async function findFuseOverlayfsPath(): Promise<string | undefined> {
|
||||||
|
|
||||||
return fuseOverlayfsPath;
|
return fuseOverlayfsPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function splitByNewline(s: string): string[] {
|
||||||
|
return s.split(/\r?\n/);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue