Skip to content

Commit

Permalink
Prune dangling images and containers on a best-effort basis
Browse files Browse the repository at this point in the history
This shouldn't be a necessary step to running TGF
  • Loading branch information
Julien Duchesne committed May 6, 2019
1 parent e0d4441 commit fa13415
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 fa13415

Please sign in to comment.