Skip to content

Commit ba88103

Browse files
authored
Image prunning (#13)
1 parent fe3b10d commit ba88103

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Moby Ryuk
22

3-
This project helps you to remove containers/networks/volumes by given filter after specified delay.
3+
This project helps you to remove containers/networks/volumes/images by given filter after specified delay.
44

55
# Usage
66

@@ -33,4 +33,4 @@ This project helps you to remove containers/networks/volumes by given filter aft
3333
2018/01/15 18:38:52 Deleting {"label":{"something":true}}
3434
2018/01/15 18:38:52 Deleting {"label":{"something_else":true}}
3535
2018/01/15 18:38:52 Deleting {"health":{"unhealthy":true},"label":{"testing=true":true}}
36-
2018/01/15 18:38:52 Removed 1 container(s), 0 network(s), 0 volume(s)
36+
2018/01/15 18:38:52 Removed 1 container(s), 0 network(s), 0 volume(s), 0 image(s)

main.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ TimeoutLoop:
122122
deletedContainers := make(map[string]bool)
123123
deletedNetworks := make(map[string]bool)
124124
deletedVolumes := make(map[string]bool)
125+
deletedImages := make(map[string]bool)
125126

126127
for param := range deathNote {
127128
log.Printf("Deleting %s\n", param)
@@ -166,7 +167,20 @@ TimeoutLoop:
166167
}
167168
return shouldRetry, err
168169
})
170+
171+
try.Do(func(attempt int) (bool, error) {
172+
imagesPruneReport, err := cli.ImagesPrune(context.Background(), args)
173+
for _, image := range imagesPruneReport.ImagesDeleted {
174+
deletedImages[image.Deleted] = true
175+
}
176+
shouldRetry := attempt < 10
177+
if err != nil && shouldRetry {
178+
log.Printf("Images pruning has failed, retrying(%d/%d). The error was: %v", attempt, 10, err)
179+
time.Sleep(1 * time.Second)
180+
}
181+
return shouldRetry, err
182+
})
169183
}
170184

171-
log.Printf("Removed %d container(s), %d network(s), %d volume(s)", len(deletedContainers), len(deletedNetworks), len(deletedVolumes))
185+
log.Printf("Removed %d container(s), %d network(s), %d volume(s) %d image(s)", len(deletedContainers), len(deletedNetworks), len(deletedVolumes), len(deletedImages))
172186
}

0 commit comments

Comments
 (0)