-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
1245bfb
to
9f773e1
Compare
2a6e65e
to
453f852
Compare
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. |
67d2818
to
37cce38
Compare
} | ||
|
||
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
beb96b5
to
3afe466
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
3afe466
to
f022b04
Compare
cac5b5b
to
0644ce6
Compare
Signed-off-by: Nitish Gupta <imnitish.ng@gmail.com>
0644ce6
to
56d8dc0
Compare
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>
There was a problem hiding this 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!
Hey I just noticed the same, thanks for the cleanup! |
Summary
Add bind cache support to pack
Output
Before
After
Documentation
Related
Resolves #1474
Resolves #1473