docker: remove images no container or declaration uses, keeping the previous of each line (hq ADR 0251)
Images pulled by digest are not dangling, so the weekly prune never takes an old version and every machine keeps every image it ever ran. docker_prune_images takes them, keeps what the declaration names (asked of the controller; no answer, nothing removed) and the one before, and is a dry run unless asked with a why.
This commit is contained in:
@@ -198,6 +198,39 @@ func tools(c *Client) []stdio.Tool {
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "docker_prune_images",
|
||||
Description: "Remove the images no container and no declaration on this machine uses (novox/hq ADR 0251 §5). Kept: every image a " +
|
||||
"container uses, in any state; every image this machine's declaration names, now and as last sent, asked of the " +
|
||||
"controller (no answer, nothing removed); every image younger than older_than_days (default 7); and in each line of " +
|
||||
"images (one repository name, joined across names one image carries) the newest image besides those, so the previous " +
|
||||
"version stays for going back. Each image is answered with whether it is kept and why. Never forced; dangling images " +
|
||||
"are the weekly prune's. A dry run by default; dry_run false needs why. Replaces docker image prune -a and docker rmi. (a)",
|
||||
Input: map[string]any{
|
||||
"dry_run": map[string]any{"type": "boolean", "description": "list only (default true)"},
|
||||
"why": map[string]any{"type": "string", "description": "why: required when dry_run is false"},
|
||||
"older_than_days": map[string]any{"type": "integer", "description": "keep every image younger than this many days (default 7, 0 for none)"},
|
||||
"match": map[string]any{"type": "string", "description": "only images whose repository or name contains this"},
|
||||
"limit": map[string]any{"type": "integer", "description": "how many images to list (default 100, at most 2000); counts cover all"},
|
||||
},
|
||||
Run: func(args map[string]any) (any, error) {
|
||||
days := 7
|
||||
if v, ok := args["older_than_days"]; ok && v != nil {
|
||||
f, isNum := v.(float64)
|
||||
if !isNum || f != math.Trunc(f) || f < 0 || f > 3650 {
|
||||
return nil, fmt.Errorf("older_than_days must be a whole number from 0 to 3650")
|
||||
}
|
||||
days = int(f)
|
||||
}
|
||||
limit, err := bounded(args, "limit", 100, 2000)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
why, _ := args["why"].(string)
|
||||
return c.PruneImages(ctx, PruneImagesAsk{DryRun: flag(args, "dry_run", true), Why: why, OlderThanDays: days,
|
||||
Match: optional(args, "match"), Limit: limit})
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "docker_disk_usage",
|
||||
Description: "What the runtime takes on disk (docker system df -v): per kind — images, containers, volumes, build cache — the total, the active and the reclaimable, and the largest of each.",
|
||||
|
||||
Reference in New Issue
Block a user