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

cache: Add support for bind cache #1497

Merged
merged 5 commits into from
Sep 14, 2022

Conversation

imnitishng
Copy link
Contributor

Summary

Add bind cache support to pack

Output

Before

After

Documentation

  • Should this change be documented?
    • Yes, see #___
    • No

Related

Resolves #1474
Resolves #1473

@imnitishng imnitishng requested a review from a team as a code owner August 10, 2022 18:44
@github-actions github-actions bot added this to the 0.28.0 milestone Aug 10, 2022
@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Aug 10, 2022
@imnitishng imnitishng marked this pull request as draft August 10, 2022 18:45
@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch 4 times, most recently from 1245bfb to 9f773e1 Compare August 11, 2022 15:14
@github-actions github-actions bot added the type/chore Issue that requests non-user facing changes. label Aug 11, 2022
@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch 3 times, most recently from 2a6e65e to 453f852 Compare August 11, 2022 15:42
@codecov
Copy link

codecov bot commented Aug 11, 2022

Codecov Report

Merging #1497 (c0b32c3) into main (a2941f1) will decrease coverage by 0.13%.
The diff coverage is 66.67%.

❗ Current head c0b32c3 differs from pull request most recent head 32dabff. Consider uploading reports for the commit 32dabff to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1497      +/-   ##
==========================================
- Coverage   80.25%   80.12%   -0.12%     
==========================================
  Files         154      155       +1     
  Lines       10021    10084      +63     
==========================================
+ Hits         8041     8079      +38     
- Misses       1499     1522      +23     
- Partials      481      483       +2     
Flag Coverage Δ
os_linux 79.89% <66.67%> (-0.12%) ⬇️
os_macos 77.37% <66.67%> (-0.10%) ⬇️
os_windows 80.00% <66.67%> (-0.12%) ⬇️
unit 80.12% <66.67%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@imnitishng imnitishng marked this pull request as ready for review August 11, 2022 15:53
@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch 4 times, most recently from 67d2818 to 37cce38 Compare August 11, 2022 16:56
}

l.logger.Debugf("Using build cache volume %s", style.Symbol(buildCache.Name()))
if l.opts.ClearCache {
if l.opts.ClearCache && l.opts.Cache.Build.Format != cache.CacheBind {
Copy link
Contributor Author

@imnitishng imnitishng Aug 11, 2022

Choose a reason for hiding this comment

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

I have not allowed clear cache support for bind caches due to security reasons (since clearing the bind cache means removing the directory from host and we wouldn't want to allow users to delete files on host), let me know if this needs to be changed.

Copy link
Member

Choose a reason for hiding this comment

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

If the user provides a very specific directory to use as a cache, why would we want to make an exception in this case but not in a named volume? I think the unexpected difference in behavior is more problematic than deleting files within a targeted directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the user provides a very specific directory to use as a cache, why would we want to make an exception in this case but not in a named volume?

I feel like if user does something like --cache="type=build;format=bind;name=." alongwith --clear-cache, then we'd be cleaning up the current dir. How do we tackle this?

Copy link
Member

Choose a reason for hiding this comment

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

That's an interesting callout. I would agree that it could be dangerous. What if we completely restricted the combination of options instead of bypassing the functionality? IOW, what do you think about failing early if the user provides any bind format with --clear-cache.

We can provide a helpful message like "'--clear-cache' is not supported when using 'bind' cache. You may instead delete the cache directory manually.".

The only drawback is that it would prevent --clear-cache when using a mix of any other cache format.


Alternatively, what if we had a nested directory with an explicit name for bind? That way at least it's less likely that we could delete unexpected content.

.
└── <user-defined>/
    └── <type>-cache/

For example, when the user provides:
--cache="type=build;format=bind;name=./my-cache/"

we create the parent directory (if missing), but additionally create a child directory <type>-cache (ie. build-cache) such as:

.
└── my-cache/
    └── build-cache/

then when the users provides the same flag --cache="type=build;format=bind;name=./my-cache/" plus --clear-cache we only delete the my-cache/build-cache directory.

WDYT?

@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch 2 times, most recently from beb96b5 to 3afe466 Compare August 11, 2022 17:15
@jromero jromero removed the type/chore Issue that requests non-user facing changes. label Aug 16, 2022
Copy link
Member

@jromero jromero left a comment

Choose a reason for hiding this comment

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

Overall this PR is 💯. I'd like to discuss the behavior of ClearCache.

Maybe @dfreilich has some opinions here as well.

}

l.logger.Debugf("Using build cache volume %s", style.Symbol(buildCache.Name()))
if l.opts.ClearCache {
if l.opts.ClearCache && l.opts.Cache.Build.Format != cache.CacheBind {
Copy link
Member

Choose a reason for hiding this comment

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

If the user provides a very specific directory to use as a cache, why would we want to make an exception in this case but not in a named volume? I think the unexpected difference in behavior is more problematic than deleting files within a targeted directory.

internal/build/lifecycle_execution.go Outdated Show resolved Hide resolved
@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch from 3afe466 to f022b04 Compare September 5, 2022 17:45
@github-actions github-actions bot added the type/chore Issue that requests non-user facing changes. label Sep 5, 2022
@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch 3 times, most recently from cac5b5b to 0644ce6 Compare September 5, 2022 18:16
Signed-off-by: Nitish Gupta <imnitish.ng@gmail.com>
@imnitishng imnitishng force-pushed the cache-flag/bind-cache branch from 0644ce6 to 56d8dc0 Compare September 5, 2022 18:49
Changes:
1. Align flag options with RFC 'name' => 'source'
2. Add more detail to 'pack help build'
3. Omit empty 'name' flag option from output

Signed-off-by: Javier Romero <root@jromero.codes>
Copy link
Member

@jromero jromero left a comment

Choose a reason for hiding this comment

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

@imnitishng, It looks like I made a mistake in the original issues I created for this feature. As per the RFC, the "name" option of the "bind" format should have been "source". I went ahead and made the changes along with other minor polishing items. You can review the changes in this commit.

Overall, 💯 implementation. Thank you!

@jromero jromero enabled auto-merge September 13, 2022 14:44
@jromero jromero removed the type/chore Issue that requests non-user facing changes. label Sep 13, 2022
@github-actions github-actions bot added the type/chore Issue that requests non-user facing changes. label Sep 13, 2022
@imnitishng
Copy link
Contributor Author

Hey I just noticed the same, thanks for the cleanup!

@jromero jromero merged commit 100f656 into buildpacks:main Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/chore Issue that requests non-user facing changes. type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cache-flag] Support launch bind cache [cache-flag] Support build bind cache
2 participants