Skip to content

Commit

Permalink
retry removing error when skaffolf could not prune local images due t…
Browse files Browse the repository at this point in the history
…o other running containers
  • Loading branch information
tejal29 committed Feb 5, 2020
1 parent bd157cc commit 23fbd3a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/docker/docker/errdefs"
"io"
"sort"
"strings"
"sync"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/mount"
Expand All @@ -39,6 +41,11 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

const (
retrials = 5
sleepTime = 1 * time.Second
)

type ContainerRun struct {
Image string
User string
Expand Down Expand Up @@ -210,6 +217,7 @@ func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string
if imageID == "" {
// Maybe this version of Docker doesn't return the digest of the image
// that has been built.
logrus.Debugf("This version of docker does not return the digest.")
imageID, err = l.ImageID(ctx, ref)
if err != nil {
return "", errors.Wrap(err, "getting digest")
Expand Down Expand Up @@ -384,7 +392,17 @@ func (l *localDaemon) ImageInspectWithRaw(ctx context.Context, image string) (ty
}

func (l *localDaemon) ImageRemove(ctx context.Context, image string, opts types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
return l.apiClient.ImageRemove(ctx, image, opts)
for i := 0; i < retrials; i++ {
resp, err := l.apiClient.ImageRemove(ctx, image, opts)
if err == nil {
return resp, nil
}
if _, ok := err.(errdefs.ErrConflict); !ok {
return nil, err
}
time.Sleep(sleepTime)
}
return nil, fmt.Errorf("could not remove image for %d re-trails", retrials)
}

// GetBuildArgs gives the build args flags for docker build.
Expand Down

0 comments on commit 23fbd3a

Please sign in to comment.