Skip to content

Support to keep BuildKit state#211

Closed
ibalajiarun wants to merge 1 commit into
docker:masterfrom
aptos-labs:balaji/retain-cache
Closed

Support to keep BuildKit state#211
ibalajiarun wants to merge 1 commit into
docker:masterfrom
aptos-labs:balaji/retain-cache

Conversation

@ibalajiarun

@ibalajiarun ibalajiarun commented Feb 27, 2023

Copy link
Copy Markdown

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
Copy Markdown
Author

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

@ibalajiarun

Copy link
Copy Markdown
Author

/cc @jedevc

@crazy-max crazy-max left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/context.ts Outdated
Comment thread src/state-helper.ts Outdated
Comment thread action.yml Outdated
@ibalajiarun
ibalajiarun force-pushed the balaji/retain-cache branch from 3e3b65a to ff70196 Compare April 19, 2023 15:19
@ibalajiarun

Copy link
Copy Markdown
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
Copy Markdown
Author

@crazy-max can we get this merged please?

@crazy-max crazy-max left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/context.ts Outdated
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

Any movement on this?

@tobiaszuercher

Copy link
Copy Markdown

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
Copy Markdown

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

@nelyodev

nelyodev commented Jul 5, 2024

Copy link
Copy Markdown

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
Copy Markdown

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

@crohr

crohr commented May 21, 2025

Copy link
Copy Markdown

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.

Comment thread action.yml Outdated
Comment thread action.yml Outdated
Comment thread src/context.ts Outdated
Comment thread src/main.ts Outdated
Comment thread src/state-helper.ts
@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
Comment thread src/context.ts Outdated

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

@crohr crohr May 27, 2025

Copy link
Copy Markdown

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
Copy Markdown
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 <balajia@vt.edu>
@ibalajiarun
ibalajiarun force-pushed the balaji/retain-cache branch from c94c853 to 703e959 Compare May 27, 2025 21:49
@crohr

crohr commented Jun 2, 2025

Copy link
Copy Markdown

Hi @crazy-max, any chance to get a final review on this? Thanks!

@crohr

crohr commented Jun 11, 2025

Copy link
Copy Markdown

This change is now used by https://github.com/runs-on/snapshot to make buildkit caches persistent across ephemeral runner jobs. Would be great to get it merged so that I can point to the official action tag :)

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