Skip to content

Support to keep BuildKit state #211

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ibalajiarun
Copy link

@ibalajiarun ibalajiarun commented Feb 27, 2023

This PR adds support to keep the cache state when the builder is removed in the post-action step. For certain usecases such as CI builds, it is helpful to keep the cache and reuse it with re-created builders. For this purpose, there is a new keep-state optional actions flag that defaults to false.

To support cache reuse, this PR also allows specifying a custom name to the builder, since cache reuse is no possible with the exiting random names generated using uuid.v4(). For this purpose, there is a new name optional actions flag.

@ibalajiarun ibalajiarun force-pushed the balaji/retain-cache branch 2 times, most recently from 9ce6fa8 to 3e3b65a Compare April 17, 2023 23:04
@ibalajiarun
Copy link
Author

Hey @crazy-max , can I get a review on this one?

@ibalajiarun
Copy link
Author

/cc @jedevc

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I left some comments.

Also have you tested this change on your side? Keeping the BuildKit state will only work on persistent runners (self-hosted) and not public ones that are ephemeral. If this is your intent then it should be documented to avoid confusion.

@ibalajiarun ibalajiarun force-pushed the balaji/retain-cache branch from 3e3b65a to ff70196 Compare April 19, 2023 15:19
@ibalajiarun
Copy link
Author

Thanks for the review @crazy-max. I've addressed your feedback.

We have been using this change at aptos-labs/aptos-core for over a month now with persistent self-hosted runners and have seen speed ups of up to 50% in build times.

https://github.com/aptos-labs/aptos-core/blob/751153f20f3068ed71cfe3d79ab9fe0212cc4107/.github/actions/docker-setup/action.yaml#L41-L58

@ibalajiarun ibalajiarun requested a review from crazy-max April 22, 2023 19:22
@ibalajiarun
Copy link
Author

@crazy-max can we get this merged please?

Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry got pending reviews I forgot to submit 😣

It would be better if we have another PR for the name input being added.

src/context.ts Outdated
}

export async function getInputs(): Promise<Inputs> {
return {
version: core.getInput('version'),
name: await getBuilderName(core.getInput('driver') || 'docker-container'),
name: getBuilderName(core.getInput('name'), core.getInput('driver') || 'docker-container'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name needs to be defined in https://github.com/docker/setup-buildx-action/blob/master/action.yml. Also needs to update README to add this new input.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being able to set a custom name would help with reusing the builder's cache across CI runs (assuming e.g. /var/lib/docker can be restored across runs). Would be even better if it could also check for an env var so that CI platforms (e.g. RunsOn) can automatically set it without user intervention.

@zpiazza-combocurve
Copy link

Any movement on this?

@tobiaszuercher
Copy link

just stumpled upon this, the --keep-state flag in docker buildx rm for self-hosted runners could speed up builds drastically.

what is needed to get any movement on this?

@rarecrumb
Copy link

@ibalajiarun @crazy-max can we take another look at this? Would be great to have.

@nelyodev
Copy link

nelyodev commented Jul 5, 2024

This PR might be the missing piece of my ultimate caching pipeline quest. Any chance it will be merged in the near future?

@tobiaszuercher
Copy link

@ibalajiarun @crazy-max is there something still open? happy to contribute

@crohr
Copy link

crohr commented May 21, 2025

This is a much needed feature: without being able to assign a stable builder name (PR probably needs to be amended so that the name is only used for docker-container driver), we can't easily reuse a previous cache. So being able to set the name and retain the state go together and I think both changes should be part of this PR @crazy-max.

The PR as it is works very well even on ephemeral runners, when you are able to make block-level snapshots (and restore) e.g. /var/lib/docker.

@crazy-max crazy-max changed the title Support to retain cache Support to keep BuildKit state May 21, 2025
@ibalajiarun ibalajiarun force-pushed the balaji/retain-cache branch 2 times, most recently from ae9b987 to c94c853 Compare May 27, 2025 20:38
@ibalajiarun ibalajiarun requested review from crazy-max and crohr May 27, 2025 20:39
src/context.ts Outdated
};
}

export async function getBuilderName(driver: string): Promise<string> {
export async function getBuilderName(name: string, driver: string): Promise<string> {
if (name) {
Copy link

@crohr crohr May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibalajiarun I suppose (?) a custom name doesn't make sense if the driver is docker, so maybe do it like this?

Suggested change
if (name) {
if (driver == 'docker') {
return await Docker.context()
}
return name || `builder-${crypto.randomUUID()}`;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Updated.

Signed-off-by: Balaji Arun <[email protected]>
@ibalajiarun ibalajiarun force-pushed the balaji/retain-cache branch from c94c853 to 703e959 Compare May 27, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants