Skip to content

Commit

Permalink
Image prunning (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup authored May 28, 2020
1 parent fe3b10d commit ba88103
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Moby Ryuk

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

# Usage

Expand Down Expand Up @@ -33,4 +33,4 @@ This project helps you to remove containers/networks/volumes by given filter aft
2018/01/15 18:38:52 Deleting {"label":{"something":true}}
2018/01/15 18:38:52 Deleting {"label":{"something_else":true}}
2018/01/15 18:38:52 Deleting {"health":{"unhealthy":true},"label":{"testing=true":true}}
2018/01/15 18:38:52 Removed 1 container(s), 0 network(s), 0 volume(s)
2018/01/15 18:38:52 Removed 1 container(s), 0 network(s), 0 volume(s), 0 image(s)
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ TimeoutLoop:
deletedContainers := make(map[string]bool)
deletedNetworks := make(map[string]bool)
deletedVolumes := make(map[string]bool)
deletedImages := make(map[string]bool)

for param := range deathNote {
log.Printf("Deleting %s\n", param)
Expand Down Expand Up @@ -166,7 +167,20 @@ TimeoutLoop:
}
return shouldRetry, err
})

try.Do(func(attempt int) (bool, error) {
imagesPruneReport, err := cli.ImagesPrune(context.Background(), args)
for _, image := range imagesPruneReport.ImagesDeleted {
deletedImages[image.Deleted] = true
}
shouldRetry := attempt < 10
if err != nil && shouldRetry {
log.Printf("Images pruning has failed, retrying(%d/%d). The error was: %v", attempt, 10, err)
time.Sleep(1 * time.Second)
}
return shouldRetry, err
})
}

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

0 comments on commit ba88103

Please sign in to comment.