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

Fix caching when mounting a cached stage with COPY/ADD #5445

Merged

Conversation

aaronlehmann
Copy link
Contributor

@aaronlehmann aaronlehmann commented Mar 31, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

A comment states that avoidLookingCache is set when a previous stage that executed as part of the build is referenced by --mount, to avoid reusing content from an older build of the stage:

// Only attempt to find cache if its needed, this part
// so that if a step is using RUN --mount and mounts
// previous stages then it uses the freshly built stage
// of re-using the older stage from the store.

However, stages consisting of COPY/ADD seem to be flagged with didExecute even if they were fetched from cache instead. I believe this is an oversight, and these stages should not prevent subsequent caching.

Also, avoidLookingCache would prevent a cache push, but I think it should only prevent cache lookups, since populating the cache is still useful in these caess.

How to verify it

Run the provided test case.

Which issue(s) this PR fixes:

Consider the test case added in this PR:

FROM scratch AS stage1
COPY / /

FROM alpine
RUN --mount=type=bind,from=stage1,target=/mnt echo hi > test

Without this fix, the RUN step skips cache completely when running with --cache-from and --cache-to. Cache is neither pulled nor pushed for this step, even when the COPY in stage1 is cached. This seems to happen because stage1 has the didExecute flag set, regardless of whether the stage was cached or not.

Special notes for your reviewer:

It's very possible I'm misunderstanding something, but I believe the RUN step in test case I've added wrongly skips cache, and I'd appreciate some pointers in the right direction if what I've proposed here isn't the right solution.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 31, 2024
@rhatdan
Copy link
Member

rhatdan commented Mar 31, 2024

/approve
LGTM
@nalind @flouthoc PTAL

@rhatdan
Copy link
Member

rhatdan commented Mar 31, 2024

Thanks @aaronlehmann

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

@aaronlehmann Thanks for PR, could you fill the section of issue in PR description with a small reproduce so its easier to verify. As of now I'm unable to exactly understand what was the problem before this PR.

@aaronlehmann
Copy link
Contributor Author

@flouthoc: I added some notes in the "Issue" section. Please let me know if I can clarify further.

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

@aaronlehmann Thanks PR LGTM, could you please rebase it :)

Copy link
Contributor

openshift-ci bot commented Apr 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aaronlehmann, flouthoc, rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

A comment states that avoidLookingCache is set when a previous stage
that executed as part of the build is referenced by --mount, to avoid
reusing content from an older build of the stage:

    // Only attempt to find cache if its needed, this part
    // so that if a step is using RUN --mount and mounts
    // previous stages then it uses the freshly built stage
    // of re-using the older stage from the store.

However, stages consisting of COPY/ADD seem to be flagged with
didExecute even if they were fetched from cache instead. I believe
this is an oversight, and these stages should not prevent subsequent
caching.

Also, avoidLookingCache would prevent a cache push, but I think it
should only prevent cache lookups, since populating the cache is still
useful in these caess.

It's very possible I'm misunderstanding something, but I believe the
RUN step in test case I've added wrongly skips cache, and I'd appreciate
some pointers in the right direction if what I've proposed here isn't
the right solution.

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
@aaronlehmann aaronlehmann force-pushed the mount-stage-cache-from branch from b413360 to d9129b4 Compare April 2, 2024 19:58
@aaronlehmann
Copy link
Contributor Author

Thanks! Rebased.

@rhatdan
Copy link
Member

rhatdan commented Apr 2, 2024

/lgtm
/hold

@rhatdan
Copy link
Member

rhatdan commented Apr 3, 2024

/unhold

@openshift-merge-bot openshift-merge-bot bot merged commit 45bbc1f into containers:main Apr 3, 2024
36 checks passed
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators Jul 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved kind/bug Categorizes issue or PR as related to a bug. lgtm locked - please file new issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants