Skip to content

Commit

Permalink
Repair --no-prune-children
Browse files Browse the repository at this point in the history
Fixes #2442

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Jul 10, 2019
1 parent 53c8122 commit fd4dc05
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
4 changes: 3 additions & 1 deletion pkg/skaffold/build/local/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Builder struct {
localCluster bool
pushImages bool
prune bool
pruneChildren bool
skipTests bool
kubeContext string
builtImages []string
Expand Down Expand Up @@ -81,6 +82,7 @@ func NewBuilder(runCtx *runcontext.RunContext) (*Builder, error) {
pushImages: pushImages,
skipTests: runCtx.Opts.SkipTests,
prune: runCtx.Opts.Prune(),
pruneChildren: !runCtx.Opts.NoPruneChildren,
insecureRegistries: runCtx.InsecureRegistries,
}, nil
}
Expand All @@ -101,5 +103,5 @@ func (b *Builder) Labels() map[string]string {

// Prune uses the docker API client to remove all images built with Skaffold
func (b *Builder) Prune(ctx context.Context, out io.Writer) error {
return docker.Prune(ctx, out, b.builtImages, b.localDocker)
return b.localDocker.Prune(ctx, out, b.builtImages, b.pruneChildren)
}
23 changes: 23 additions & 0 deletions pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type LocalDaemon interface {
RepoDigest(ctx context.Context, ref string) (string, error)
ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
ImageExists(ctx context.Context, ref string) bool
Prune(ctx context.Context, out io.Writer, images []string, pruneChildren bool) error
}

type localDaemon struct {
Expand Down Expand Up @@ -410,3 +411,25 @@ func EvaluateBuildArgs(args map[string]*string) (map[string]*string, error) {

return evaluated, nil
}

func (l *localDaemon) Prune(ctx context.Context, out io.Writer, images []string, pruneChildren bool) error {
for _, id := range images {
resp, err := l.ImageRemove(ctx, id, types.ImageRemoveOptions{
Force: true,
PruneChildren: pruneChildren,
})
if err != nil {
return errors.Wrap(err, "pruning images")
}
for _, r := range resp {
if r.Deleted != "" {
fmt.Fprintf(out, "deleted image %s\n", r.Deleted)
}
if r.Untagged != "" {
fmt.Fprintf(out, "untagged image %s\n", r.Untagged)
}
}
}

return nil
}
35 changes: 0 additions & 35 deletions pkg/skaffold/docker/image_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,13 @@ package docker

import (
"context"
"fmt"
"io"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/docker/docker/api/types"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

var (
opts = &config.SkaffoldOptions{}
)

func Prune(ctx context.Context, out io.Writer, images []string, client LocalDaemon) error {
pruneChildren := true

if opts.NoPruneChildren {
pruneChildren = false
}

for _, id := range images {
resp, err := client.ImageRemove(ctx, id, types.ImageRemoveOptions{
Force: true,
PruneChildren: pruneChildren,
})
if err != nil {
return errors.Wrap(err, "pruning images")
}
for _, r := range resp {
if r.Deleted != "" {
fmt.Fprintf(out, "deleted image %s\n", r.Deleted)
}
if r.Untagged != "" {
fmt.Fprintf(out, "untagged image %s\n", r.Untagged)
}
}
}
return nil
}

func RetrieveWorkingDir(tagged string, insecureRegistries map[string]bool) (string, error) {
var cf *v1.ConfigFile
var err error
Expand Down

0 comments on commit fd4dc05

Please sign in to comment.