mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-06-08 01:49:03 +00:00
Add feature to build multi-arch image (#27)
Since buildah now supports multi arch image support (ref: https://github.com/containers/buildah/issues/1590) This feature will allow building images for multiple architectures. Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
21e07c3197
commit
803a1413e7
9 changed files with 40 additions and 10 deletions
|
@ -8,11 +8,12 @@ export interface BuildahConfigSettings {
|
|||
envs?: string[];
|
||||
port?: string;
|
||||
workingdir?: string;
|
||||
archs?: string;
|
||||
}
|
||||
|
||||
interface Buildah {
|
||||
buildUsingDocker(
|
||||
image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean,
|
||||
image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean, archs: string,
|
||||
): Promise<CommandResult>;
|
||||
from(baseImage: string): Promise<CommandResult>;
|
||||
copy(container: string, contentToCopy: string[]): Promise<CommandResult | undefined>;
|
||||
|
@ -32,9 +33,13 @@ export class BuildahCli implements Buildah {
|
|||
}
|
||||
|
||||
async buildUsingDocker(
|
||||
image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean,
|
||||
image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean, archs: string
|
||||
): Promise<CommandResult> {
|
||||
const args: string[] = [ "bud" ];
|
||||
if (archs) {
|
||||
args.push("--arch");
|
||||
args.push(archs);
|
||||
}
|
||||
dockerFiles.forEach((file) => {
|
||||
args.push("-f");
|
||||
args.push(file);
|
||||
|
@ -90,6 +95,10 @@ export class BuildahCli implements Buildah {
|
|||
args.push(env);
|
||||
});
|
||||
}
|
||||
if (settings.archs) {
|
||||
args.push("--arch");
|
||||
args.push(settings.archs);
|
||||
}
|
||||
args.push(container);
|
||||
return this.execute(args);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
// 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.
|
||||
* Required: false
|
||||
* Default: "amd64"
|
||||
*/
|
||||
ARCHS = "archs",
|
||||
/**
|
||||
* The base image to use to create a new container image
|
||||
* Required: true
|
||||
|
|
14
src/index.ts
14
src/index.ts
|
@ -20,12 +20,15 @@ export async function run(): Promise<void> {
|
|||
const tagsList: string[] = tags.split(" ");
|
||||
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, "");
|
||||
|
||||
if (dockerFiles.length !== 0) {
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI, archs);
|
||||
}
|
||||
else {
|
||||
await doBuildFromScratch(cli, newImage, useOCI);
|
||||
await doBuildFromScratch(cli, newImage, useOCI, archs);
|
||||
}
|
||||
|
||||
if (tagsList.length > 1) {
|
||||
|
@ -36,7 +39,7 @@ export async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
async function doBuildUsingDockerFiles(
|
||||
cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[], useOCI: boolean,
|
||||
cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[], useOCI: boolean, archs: string
|
||||
): Promise<void> {
|
||||
if (dockerFiles.length === 1) {
|
||||
core.info(`Performing build from Dockerfile`);
|
||||
|
@ -48,11 +51,11 @@ async function doBuildUsingDockerFiles(
|
|||
const context = path.join(workspace, core.getInput(Inputs.CONTEXT));
|
||||
const buildArgs = getInputList(Inputs.BUILD_ARGS);
|
||||
const dockerFileAbsPaths = dockerFiles.map((file) => path.join(workspace, file));
|
||||
await cli.buildUsingDocker(newImage, context, dockerFileAbsPaths, buildArgs, useOCI);
|
||||
await cli.buildUsingDocker(newImage, context, dockerFileAbsPaths, buildArgs, useOCI, archs);
|
||||
}
|
||||
|
||||
async function doBuildFromScratch(
|
||||
cli: BuildahCli, newImage: string, useOCI: boolean,
|
||||
cli: BuildahCli, newImage: string, useOCI: boolean, archs: string
|
||||
): Promise<void> {
|
||||
core.info(`Performing build from scratch`);
|
||||
|
||||
|
@ -73,6 +76,7 @@ async function doBuildFromScratch(
|
|||
port,
|
||||
workingdir: workingDir,
|
||||
envs,
|
||||
archs,
|
||||
};
|
||||
await cli.config(containerId, newImageConfig);
|
||||
await cli.commit(containerId, newImage, useOCI);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue