Make squashing optional

This commit is contained in:
Sebastian Grabowski 2024-04-27 01:38:16 +02:00
parent 7a95fa7ee0
commit 4a139d5a7a
No known key found for this signature in database
GPG key ID: 6030CFD8428BE75E
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'
default: 'false'
required: false
squash:
description: 'Set to true to squash the image layers.'
default: 'true'
required: false
arch:
description:
'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>;
config(container: string, setting: BuildahConfigSettings): Promise<CommandResult>;
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>;
manifestAdd(manifest: string, imageName: string, tags: string[]): Promise<void>;
}
@ -178,14 +178,15 @@ export class BuildahCli implements Buildah {
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(container);
core.debug(newImageName);
const args: string[] = [
"commit", ...BuildahCli.getImageFormatOption(useOCI),
"--squash", container, newImageName,
];
const args: string[] = [ "commit", ...BuildahCli.getImageFormatOption(useOCI) ];
if (squash) {
args.push("--squash");
}
args.push(container, newImageName);
return this.execute(args);
}

View file

@ -112,6 +112,12 @@ export enum Inputs {
* Default: None.
*/
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".
* Required: false

View file

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