Skip to content

Commit

Permalink
Merge pull request #62 from coveo/best-effort-prune
Browse files Browse the repository at this point in the history
Prune dangling images and containers on a best-effort basis
  • Loading branch information
Julien Duchesne authored May 6, 2019
2 parents e0d4441 + fa13415 commit 6cd1ad2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 7 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,16 @@ func getImage(config *TGFConfig, noDockerBuild bool, refresh bool, useLocalImage
return
}

var pruneDangling = func(config *TGFConfig) {
func pruneDangling(config *TGFConfig) {
cli, ctx := getDockerClient()
danglingFilters := filters.NewArgs()
danglingFilters.Add("dangling", "true")
must(cli.ImagesPrune(ctx, danglingFilters))
must(cli.ContainersPrune(ctx, filters.Args{}))
if _, err := cli.ImagesPrune(ctx, danglingFilters); err != nil {
printError("Error pruning dangling images (Untagged): %v", err.Error())
}
if _, err := cli.ContainersPrune(ctx, filters.Args{}); err != nil {
printError("Error pruning unused containers: %v", err.Error())
}
}

func prune(config *TGFConfig, images ...string) {
Expand Down
2 changes: 0 additions & 2 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
func TestGetImage(t *testing.T) {
t.Parallel()

pruneDangling = func(*TGFConfig) {}

testImageName := "test-image" + strconv.Itoa(randInt())
testTag := "test" + strconv.Itoa(randInt())

Expand Down

0 comments on commit 6cd1ad2

Please sign in to comment.