-
Notifications
You must be signed in to change notification settings - Fork 0
Add --limit-space and --top flags for size-based cleanup prioritization #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
6f4ca61
0d7261b
f965636
a490aad
9a8bb85
fae7a1e
ed4605f
d3f2849
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ function summarizeCounts(resources: ResourceType[], totalItems: number): string | |
| } | ||
|
|
||
| async function run(): Promise<number> { | ||
| const { options, olderThanMs } = parseArgs(process.argv); | ||
| const { options, olderThanMs, limitSpaceBytes } = parseArgs(process.argv); | ||
| setColorEnabled(!options.noColor); | ||
|
|
||
| const dockerCheck = await checkDocker(); | ||
|
|
@@ -64,7 +64,9 @@ async function run(): Promise<number> { | |
| includeNetworks: resources.includes("networks"), | ||
| includeCache: resources.includes("cache"), | ||
| includeAllImages, | ||
| olderThanMs | ||
| olderThanMs, | ||
| top: options.top, | ||
| limitSpaceBytes | ||
| }); | ||
|
Comment on lines
+67
to
70
|
||
| scanSpinner?.succeed("Scan complete"); | ||
|
|
||
|
|
@@ -140,12 +142,45 @@ async function run(): Promise<number> { | |
| cache: 0 | ||
| } as Record<ResourceType, number>); | ||
|
|
||
| // Extract selected IDs when size filters are active | ||
| const hasSizeFilters = options.top !== undefined || limitSpaceBytes !== undefined; | ||
| let selectedIds = undefined; | ||
| let estimatedBytes = undefined; | ||
|
|
||
| if (hasSizeFilters) { | ||
| selectedIds = scanResult.summaries.reduce((acc, summary) => { | ||
| // Only collect IDs for resource types that have them (not cache) | ||
| if (summary.type !== "cache") { | ||
| acc[summary.type] = summary.items.map(item => item.id); | ||
| } | ||
| return acc; | ||
| }, { | ||
| containers: [], | ||
| images: [], | ||
| volumes: [], | ||
| networks: [] | ||
| } as import("./types").SelectedResources); | ||
|
|
||
| estimatedBytes = scanResult.summaries.reduce((acc, summary) => { | ||
| acc[summary.type] = summary.reclaimableBytes || 0; | ||
| return acc; | ||
| }, { | ||
| containers: 0, | ||
| images: 0, | ||
| volumes: 0, | ||
| networks: 0, | ||
| cache: 0 | ||
| } as Record<ResourceType, number>); | ||
| } | ||
|
|
||
| const cleanResult = await cleanResources({ | ||
| resources, | ||
| olderThanMs, | ||
| dryRun: options.dryRun, | ||
| includeAllImages, | ||
| expectedCounts | ||
| expectedCounts, | ||
| selectedIds, | ||
| estimatedBytes | ||
| }); | ||
| cleanSpinner?.succeed("Cleanup completed"); | ||
|
|
||
|
|
||
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.
Consider clarifying in the README that when using --top or --limit-space with multiple resource types (e.g., --containers --images --top 10), the filter applies independently to each resource type. For example, --top 10 with both containers and images would select up to 10 containers AND up to 10 images (20 items total), not 10 items across all types.
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.
Added clarification in commit ed4605f. The README now explains that when using --top or --limit-space with multiple resource types, the filter applies independently to each type (e.g., --top 10 with containers and images selects 10 of each, not 10 total).