summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiaan van Stijn <thaJeztah@users.noreply.github.com>2023-04-28 19:52:55 +0200
committerGitHub <noreply@github.com>2023-04-28 19:52:55 +0200
commit3cad7f99e0c7c7e8e1af1d76a7ba30e8eee3b28f (patch)
treeac3f58426c4e4d578099b55448b9828f8ae9b434
parent04f21d86cf016015af16caeb94338948cc4da7a5 (diff)
parent44a65876088aba451939a4f2bbc05c7845811cc3 (diff)
downloaddocker-3cad7f99e0c7c7e8e1af1d76a7ba30e8eee3b28f.tar.gz
Merge pull request #45431 from laurazard/remove-dangling-pull
c8d: delete dangling image on pull
-rw-r--r--daemon/containerd/image_pull.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/daemon/containerd/image_pull.go b/daemon/containerd/image_pull.go
index 506e0bb135..160d47cc2f 100644
--- a/daemon/containerd/image_pull.go
+++ b/daemon/containerd/image_pull.go
@@ -5,6 +5,7 @@ import (
"io"
"github.com/containerd/containerd"
+ cerrdefs "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/pkg/snapshotters"
"github.com/containerd/containerd/platforms"
@@ -14,6 +15,7 @@ import (
"github.com/docker/docker/pkg/streamformatter"
"github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go/v1"
+ "github.com/sirupsen/logrus"
)
// PullImage initiates a pull operation. image is the repository name to pull, and
@@ -68,6 +70,23 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
infoHandler := snapshotters.AppendInfoHandlerWrapper(ref.String())
opts = append(opts, containerd.WithImageHandlerWrapper(infoHandler))
- _, err = i.client.Pull(ctx, ref.String(), opts...)
- return err
+ img, err := i.client.Pull(ctx, ref.String(), opts...)
+ if err != nil {
+ return err
+ }
+
+ logger := logrus.WithFields(logrus.Fields{
+ "digest": img.Target().Digest,
+ "remote": ref.String(),
+ })
+ logger.Info("image pulled")
+
+ // The pull succeeded, so try to remove any dangling image we have for this target
+ err = i.client.ImageService().Delete(context.Background(), danglingImageName(img.Target().Digest))
+ if err != nil && !cerrdefs.IsNotFound(err) {
+ // Image pull succeeded, but cleaning up the dangling image failed. Ignore the
+ // error to not mark the pull as failed.
+ logger.WithError(err).Warn("unexpected error while removing outdated dangling image reference")
+ }
+ return nil
}