This commit is contained in:
Sebastian Grabowski 2024-04-27 01:54:34 +02:00 committed by GitHub
commit ab27e8e8f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 22 additions and 10 deletions

View file

@ -53,6 +53,10 @@ inputs:
description: 'Set to true to build using the OCI image format instead of the Docker image format' description: 'Set to true to build using the OCI image format instead of the Docker image format'
default: 'false' default: 'false'
required: false required: false
squash:
description: 'Set to true to squash the image layers.'
default: 'true'
required: false
arch: arch:
description: description:
'Label the image with this ARCH, instead of defaulting to the host architecture' 'Label the image with this ARCH, instead of defaulting to the host architecture'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -27,7 +27,7 @@ interface Buildah {
from(baseImage: string, tlsVerify: boolean, extraArgs: string[]): Promise<CommandResult>; from(baseImage: string, tlsVerify: boolean, extraArgs: string[]): Promise<CommandResult>;
config(container: string, setting: BuildahConfigSettings): Promise<CommandResult>; config(container: string, setting: BuildahConfigSettings): Promise<CommandResult>;
copy(container: string, contentToCopy: string[]): Promise<CommandResult | undefined>; copy(container: string, contentToCopy: string[]): Promise<CommandResult | undefined>;
commit(container: string, newImageName: string, useOCI: boolean): Promise<CommandResult>; commit(container: string, newImageName: string, useOCI: boolean, squash: boolean): Promise<CommandResult>;
manifestCreate(manifest: string): Promise<void>; manifestCreate(manifest: string): Promise<void>;
manifestAdd(manifest: string, imageName: string, tags: string[]): Promise<void>; manifestAdd(manifest: string, imageName: string, tags: string[]): Promise<void>;
} }
@ -178,14 +178,15 @@ export class BuildahCli implements Buildah {
return this.execute(args); return this.execute(args);
} }
async commit(container: string, newImageName: string, useOCI: boolean): Promise<CommandResult> { async commit(container: string, newImageName: string, useOCI: boolean, squash: boolean): Promise<CommandResult> {
core.debug("commit"); core.debug("commit");
core.debug(container); core.debug(container);
core.debug(newImageName); core.debug(newImageName);
const args: string[] = [ const args: string[] = [ "commit", ...BuildahCli.getImageFormatOption(useOCI) ];
"commit", ...BuildahCli.getImageFormatOption(useOCI), if (squash) {
"--squash", container, newImageName, args.push("--squash");
]; }
args.push(container, newImageName);
return this.execute(args); return this.execute(args);
} }

View file

@ -112,6 +112,12 @@ export enum Inputs {
* Default: None. * Default: None.
*/ */
PORT = "port", PORT = "port",
/**
* Set to true to squash the image layers.
* Required: false
* Default: "true"
*/
SQUASH = "squash",
/** /**
* The tags of the image to build. For multiple tags, seperate by whitespace. For example, "latest v1". * The tags of the image to build. For multiple tags, seperate by whitespace. For example, "latest v1".
* Required: false * Required: false

View file

@ -266,6 +266,7 @@ async function doBuildFromScratch(
const workingDir = core.getInput(Inputs.WORKDIR); const workingDir = core.getInput(Inputs.WORKDIR);
const envs = getInputList(Inputs.ENVS); const envs = getInputList(Inputs.ENVS);
const tlsVerify = core.getInput(Inputs.TLS_VERIFY) === "true"; const tlsVerify = core.getInput(Inputs.TLS_VERIFY) === "true";
const squash = core.getInput(Inputs.SQUASH) === "true";
const container = await cli.from(baseImage, tlsVerify, extraArgs); const container = await cli.from(baseImage, tlsVerify, extraArgs);
const containerId = container.output.replace("\n", ""); const containerId = container.output.replace("\n", "");
@ -287,7 +288,7 @@ async function doBuildFromScratch(
}; };
await cli.config(containerId, newImageConfig); await cli.config(containerId, newImageConfig);
await cli.copy(containerId, content); await cli.copy(containerId, content);
await cli.commit(containerId, `${newImage}${tagSuffix}`, useOCI); await cli.commit(containerId, `${newImage}${tagSuffix}`, useOCI, squash);
builtImage.push(`${newImage}${tagSuffix}`); builtImage.push(`${newImage}${tagSuffix}`);
} }
} }
@ -301,7 +302,7 @@ async function doBuildFromScratch(
}; };
await cli.config(containerId, newImageConfig); await cli.config(containerId, newImageConfig);
await cli.copy(containerId, content); await cli.copy(containerId, content);
await cli.commit(containerId, newImage, useOCI); await cli.commit(containerId, newImage, useOCI, squash);
builtImage.push(newImage); builtImage.push(newImage);
} }