Skip to content

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Aug 28, 2025

follow-up:

fixes #1922

Currently we have filters for the following keys: https://github.com/moby/buildkit/blob/3d43066f2e814d4d10383ba871256245edf08a25/cache/manager.go#L1641-L1659

Key type can be one of: https://github.com/moby/buildkit/blob/3d43066f2e814d4d10383ba871256245edf08a25/client/diskusage.go#L81-L88

We also have the until key that is used on client side to set KeepDuration for prune info request:

buildx/commands/prune.go

Lines 190 to 243 in 3f4bf82

func toBuildkitPruneInfo(f filters.Args) (*client.PruneInfo, error) {
var until time.Duration
untilValues := f.Get("until") // canonical
unusedForValues := f.Get("unused-for") // deprecated synonym for "until" filter
if len(untilValues) > 0 && len(unusedForValues) > 0 {
return nil, errors.Errorf("conflicting filters %q and %q", "until", "unused-for")
}
untilKey := "until"
if len(unusedForValues) > 0 {
untilKey = "unused-for"
}
untilValues = append(untilValues, unusedForValues...)
switch len(untilValues) {
case 0:
// nothing to do
case 1:
var err error
until, err = time.ParseDuration(untilValues[0])
if err != nil {
return nil, errors.Wrapf(err, "%q filter expects a duration (e.g., '24h')", untilKey)
}
default:
return nil, errors.Errorf("filters expect only one value")
}
filters := make([]string, 0, f.Len())
for _, filterKey := range f.Keys() {
if filterKey == untilKey {
continue
}
values := f.Get(filterKey)
switch len(values) {
case 0:
filters = append(filters, filterKey)
case 1:
if filterKey == "id" {
filters = append(filters, filterKey+"~="+values[0])
} else if strings.HasSuffix(filterKey, "!") || strings.HasSuffix(filterKey, "~") {
filters = append(filters, filterKey+"="+values[0])
} else {
filters = append(filters, filterKey+"=="+values[0])
}
default:
return nil, errors.Errorf("filters expect only one value")
}
}
return &client.PruneInfo{
KeepDuration: until,
Filter: []string{strings.Join(filters, ",")},
}, nil
}

We are using containerd module to parse filters: https://github.com/containerd/containerd/blob/7d8765d440e4991a7d005db19e7873651ce3551d/pkg/filters/parser.go#L26-L49

@crazy-max crazy-max added this to the v0.28.0 milestone Aug 28, 2025
@crazy-max crazy-max requested a review from tonistiigi August 28, 2025 13:45
@crazy-max crazy-max marked this pull request as ready for review August 28, 2025 13:45
@tonistiigi
Copy link
Member

@fenollp

@tonistiigi tonistiigi merged commit d873cae into docker:master Aug 29, 2025
140 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Ability to inspect specific cache mounts
2 participants