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

Add (glob), (only-globs), and (except-globs) for fine-grained caching via include/exclude glob patterns #282

Merged
merged 24 commits into from
Apr 18, 2023

Conversation

vito
Copy link
Owner

@vito vito commented Apr 16, 2023

This is a major new feature for fine-grained cache control.

Now you can take a thunk path or a host path and use (glob) to scope it down to certain paths:

❯ bass
=> (glob *dir* ./**/*.go ./Makefile)
<host: .>/?[./**/*.go ./Makefile]

When passing this path to another thunk, not only will only the requested files be included, and downstream consumers will only have their cache busted if the requested files changed.

You can also exclude files by adding a ! argument ahead of them:

=> (glob *dir* ./**/*.go ./Makefile ! ./main.go)
<host: .>/?[./**/*.go ./Makefile]![./main.go]

Excludes are processed after includes, so the above example will include all *.go files, the a Makefile, but will not include main.go.

Check out the changes to bass/bass.bass in this PR for real-world usage examples. Notably this completely removed the need for (subgit) which was always janky; it was git-specific so it wouldn't play nice if you were running from local paths.

Breaking change

  • Non-service thunks now have a static thunk hostname instead of the thunk name.
  • (with-label) no longer busts caches. (This used to work by virtue of changing the hostname.)

This change was necessary because otherwise thunk caches would bust when they run against new inputs (e.g. git clone for a new commit) even if the glob rules scoped the changes out.

Having (with-label) bust caches became really awkward when I wanted to use them for OCI image labels, so at least that change was probably inevitable.

The docs have been updated to use (with-env) as the cache buster instead, since this directly affects the LLB.

vito added 14 commits April 16, 2023 01:58
+ fix up tests
+ pend glob test since it fails. seems like this only works for local
  dirs. :(
Using labels in this way was always a bit confusing, since labels would
otherwise be appropriate to set on container images, where they don't
normally bust caches. Use env vars instead.

On the plus side, now globs don't bust caches, which is much more useful
than using labels to! (Classic carrot + stick scenario.)
* push file vs directory logic down into Includes()/Excludes()
* file globbables implicitly include only the specified file
they don't actually prevent cache busting at the moment, for the same
reason it was broken in Bass (setting hostname busts cache)
timestamp wasn't enough to prevent concurrent runs of same tests via
gRPC->Buildkit + Buildkit
this was always a decision of convenience, doesn't make sense when
they're more useful as image metadata, which shouldn't bust caches
tricky interaction between thunk output caching + cache dirs. now that
thunk names don't cause a cache bust for "free" we need to more
explicitly bust them so the next test run doesn't just see the output
generated later in the test run.
is this the same as before? maybe caches themselves aren't a part of the outer cache key?
Suspecting this is the root cause of duplicate runs in cache test, but
my understanding of it is hazy at best. Seems like this should have been
cached regardless.
This reverts commit 576d9ab.
@vito vito added the enhancement New feature or request label Apr 18, 2023
@vito vito changed the title Add (glob) for fine-grained caching via include/exclude filters Add (glob), (only-globs), and (except-globs) for fine-grained caching via include/exclude glob patterns Apr 18, 2023
@vito vito added the breaking Removes or replaces previously supported functionality label Apr 18, 2023
@vito vito merged commit 0537fa0 into main Apr 18, 2023
@vito vito deleted the include-exclude branch April 18, 2023 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Removes or replaces previously supported functionality enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant