Skip to content

Commit 54a125f

Browse files
committed
builder-next/prune: Handle "until" filter timestamps
Fixes `docker system prune --filter until=<timestamp>`. `docker system prune` claims to support "until" filter for timestamps, but it doesn't work because builder "until" filter only supports duration. Use the same filter parsing logic and then convert the timestamp to a relative "keep-duration" supported by buildkit. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 5745ba6 commit 54a125f

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

api/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8226,7 +8226,7 @@ paths:
82268226
82278227
Available filters:
82288228
8229-
- `until=<duration>`: duration relative to daemon's time, during which build cache was not used, in Go's duration format (e.g., '24h')
8229+
- `until=<timestamp>` remove cache older than `<timestamp>`. The `<timestamp>` can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed relative to the daemon's local time.
82308230
- `id=<id>`
82318231
- `parent=<id>`
82328232
- `type=<string>`

builder/builder-next/builder.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/containerd/containerd/remotes/docker"
1515
"github.com/docker/docker/api/types"
1616
"github.com/docker/docker/api/types/backend"
17+
timetypes "github.com/docker/docker/api/types/time"
1718
"github.com/docker/docker/builder"
1819
mobyexporter "github.com/docker/docker/builder/builder-next/exporter"
1920
"github.com/docker/docker/builder/builder-next/exporter/overrides"
@@ -626,11 +627,16 @@ func toBuildkitPruneInfo(opts types.BuildCachePruneOptions) (client.PruneInfo, e
626627
case 0:
627628
// nothing to do
628629
case 1:
629-
var err error
630-
until, err = time.ParseDuration(untilValues[0])
630+
ts, err := timetypes.GetTimestamp(untilValues[0], time.Now())
631631
if err != nil {
632-
return client.PruneInfo{}, errors.Wrapf(err, "%q filter expects a duration (e.g., '24h')", filterKey)
632+
return client.PruneInfo{}, errors.Wrapf(err, "%q filter expects a duration (e.g., '24h') or a timestamp", filterKey)
633633
}
634+
seconds, nanoseconds, err := timetypes.ParseTimestamps(ts, 0)
635+
if err != nil {
636+
return client.PruneInfo{}, errors.Wrapf(err, "failed to parse timestamp %s", ts)
637+
}
638+
639+
until = time.Since(time.Unix(seconds, nanoseconds))
634640
default:
635641
return client.PruneInfo{}, errMultipleFilterValues{}
636642
}

0 commit comments

Comments
 (0)