Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make squashing optional #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/buildah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions src/generated/inputs-outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand All @@ -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}`);
}
}
Expand All @@ -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);
}

Expand Down