mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-06-08 01:49:03 +00:00
Rename 'archs' input and improve multiarch (#62)
- Expand readme - Add example Signed-off-by: Tim Etchells <tetchel@gmail.com>
This commit is contained in:
parent
098556ccc2
commit
48fe07762a
13 changed files with 674 additions and 424 deletions
|
@ -14,13 +14,13 @@ export interface BuildahConfigSettings {
|
|||
envs?: string[];
|
||||
port?: string;
|
||||
workingdir?: string;
|
||||
archs?: string;
|
||||
arch?: string;
|
||||
}
|
||||
|
||||
interface Buildah {
|
||||
buildUsingDocker(
|
||||
image: string, context: string, dockerFiles: string[], buildArgs: string[],
|
||||
useOCI: boolean, archs: string, layers: string, extraArgs: string[]
|
||||
useOCI: boolean, arch: string, layers: string, extraArgs: string[]
|
||||
): Promise<CommandResult>;
|
||||
from(baseImage: string): Promise<CommandResult>;
|
||||
copy(container: string, contentToCopy: string[]): Promise<CommandResult | undefined>;
|
||||
|
@ -63,12 +63,12 @@ export class BuildahCli implements Buildah {
|
|||
|
||||
async buildUsingDocker(
|
||||
image: string, context: string, dockerFiles: string[], buildArgs: string[],
|
||||
useOCI: boolean, archs: string, layers: string, extraArgs: string[]
|
||||
useOCI: boolean, arch: string, layers: string, extraArgs: string[]
|
||||
): Promise<CommandResult> {
|
||||
const args: string[] = [ "bud" ];
|
||||
if (archs) {
|
||||
if (arch) {
|
||||
args.push("--arch");
|
||||
args.push(archs);
|
||||
args.push(arch);
|
||||
}
|
||||
dockerFiles.forEach((file) => {
|
||||
args.push("-f");
|
||||
|
@ -131,9 +131,9 @@ export class BuildahCli implements Buildah {
|
|||
args.push(env);
|
||||
});
|
||||
}
|
||||
if (settings.archs) {
|
||||
if (settings.arch) {
|
||||
args.push("--arch");
|
||||
args.push(settings.archs);
|
||||
args.push(settings.arch);
|
||||
}
|
||||
if (settings.workingdir) {
|
||||
args.push("--workingdir");
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
// This file was auto-generated by action-io-generator. Do not edit by hand!
|
||||
export enum Inputs {
|
||||
/**
|
||||
* Architecture(s) to build the image(s) for. For multiple architectures,
|
||||
* separate by a comma.
|
||||
* Label the image with this ARCH, instead of defaulting to the host architecture.
|
||||
* Required: false
|
||||
* Default: "amd64"
|
||||
* Default: None.
|
||||
*/
|
||||
ARCH = "arch",
|
||||
/**
|
||||
* Alias for "arch". "arch" takes precedence if both are set.
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
ARCHS = "archs",
|
||||
/**
|
||||
|
|
34
src/index.ts
34
src/index.ts
|
@ -33,21 +33,20 @@ export async function run(): Promise<void> {
|
|||
const tagsList: string[] = tags.split(" ");
|
||||
|
||||
// info message if user doesn't provides any tag
|
||||
if (!tagsList.length) {
|
||||
if (tagsList.length === 0) {
|
||||
core.info(`Input "${Inputs.TAGS}" is not provided, using default tag "${DEFAULT_TAG}"`);
|
||||
tagsList.push(DEFAULT_TAG);
|
||||
}
|
||||
const newImage = `${image}:${tagsList[0]}`;
|
||||
const useOCI = core.getInput(Inputs.OCI) === "true";
|
||||
let archs: string | undefined = core.getInput(Inputs.ARCHS);
|
||||
// remove white spaces (if any) in archs input
|
||||
archs = archs.replace(/\s+/g, "");
|
||||
|
||||
const arch = getArch();
|
||||
|
||||
if (dockerFiles.length !== 0) {
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI, archs);
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI, arch);
|
||||
}
|
||||
else {
|
||||
await doBuildFromScratch(cli, newImage, useOCI, archs);
|
||||
await doBuildFromScratch(cli, newImage, useOCI, arch);
|
||||
}
|
||||
|
||||
if (tagsList.length > 1) {
|
||||
|
@ -58,7 +57,7 @@ export async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
async function doBuildUsingDockerFiles(
|
||||
cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[], useOCI: boolean, archs: string
|
||||
cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[], useOCI: boolean, arch: string
|
||||
): Promise<void> {
|
||||
if (dockerFiles.length === 1) {
|
||||
core.info(`Performing build from Dockerfile`);
|
||||
|
@ -81,12 +80,12 @@ async function doBuildUsingDockerFiles(
|
|||
buildahBudExtraArgs = lines.flatMap((line) => line.split(" ")).map((arg) => arg.trim());
|
||||
}
|
||||
await cli.buildUsingDocker(
|
||||
newImage, context, dockerFileAbsPaths, buildArgs, useOCI, archs, layers, buildahBudExtraArgs
|
||||
newImage, context, dockerFileAbsPaths, buildArgs, useOCI, arch, layers, buildahBudExtraArgs
|
||||
);
|
||||
}
|
||||
|
||||
async function doBuildFromScratch(
|
||||
cli: BuildahCli, newImage: string, useOCI: boolean, archs: string
|
||||
cli: BuildahCli, newImage: string, useOCI: boolean, arch: string
|
||||
): Promise<void> {
|
||||
core.info(`Performing build from scratch`);
|
||||
|
||||
|
@ -107,7 +106,7 @@ async function doBuildFromScratch(
|
|||
port,
|
||||
workingdir: workingDir,
|
||||
envs,
|
||||
archs,
|
||||
arch,
|
||||
};
|
||||
await cli.config(containerId, newImageConfig);
|
||||
await cli.commit(containerId, newImage, useOCI);
|
||||
|
@ -127,4 +126,19 @@ function getInputList(name: string): string[] {
|
|||
);
|
||||
}
|
||||
|
||||
function getArch(): string {
|
||||
// 'arch' should be used over 'archs', see https://github.com/redhat-actions/buildah-build/issues/60
|
||||
const archs = core.getInput(Inputs.ARCHS);
|
||||
const arch = core.getInput(Inputs.ARCH);
|
||||
|
||||
if (arch && archs) {
|
||||
core.warning(
|
||||
`Please use only one input of "${Inputs.ARCH}" and "${Inputs.ARCHS}". "${Inputs.ARCH}" takes precedence, `
|
||||
+ `so --arch argument will be "${arch}".`
|
||||
);
|
||||
}
|
||||
|
||||
return arch || archs;
|
||||
}
|
||||
|
||||
run().catch(core.setFailed);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue