@@ -19,18 +19,14 @@ package imgutil
1919
2020import (
2121 "context"
22- "fmt"
2322 "io"
2423 "strings"
2524
2625 "github.com/AkihiroSuda/nerdctl/pkg/contentutil"
2726 "github.com/containerd/containerd"
28- "github.com/containerd/containerd/images"
29- "github.com/containerd/containerd/platforms"
3027 refdocker "github.com/containerd/containerd/reference/docker"
3128 "github.com/containerd/containerd/remotes/docker"
3229 "github.com/containerd/stargz-snapshotter/fs/source"
33- ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3430 "github.com/pkg/errors"
3531 "github.com/sirupsen/logrus"
3632)
@@ -84,42 +80,25 @@ func EnsureImage(ctx context.Context, client *containerd.Client, stdout io.Write
8480 resolver := docker .NewResolver (resovlerOpts )
8581
8682 var containerdImage containerd.Image
83+ config := & contentutil.PullConfig {
84+ Resolver : resolver ,
85+ ProgressOutput : stdout ,
86+ RemoteOpts : []containerd.RemoteOpt {
87+ containerd .WithPullUnpack ,
88+ containerd .WithPullSnapshotter (snapshotter ),
89+ },
90+ }
8791 sgz := isStargz (snapshotter )
8892 if sgz {
89- h := images .HandlerFunc (func (ctx context.Context , desc ocispec.Descriptor ) ([]ocispec.Descriptor , error ) {
90- if desc .MediaType != images .MediaTypeDockerSchema1Manifest {
91- fmt .Fprintf (stdout , "fetching %v... %v\n " , desc .Digest .String ()[:15 ], desc .MediaType )
92- }
93- return nil , nil
94- })
9593 // TODO: support "skip-content-verify"
96- opts := []containerd.RemoteOpt {
97- containerd .WithResolver (resolver ),
98- containerd .WithImageHandler (h ),
99- containerd .WithSchema1Conversion ,
100- containerd .WithPullUnpack ,
101- containerd .WithPullSnapshotter (snapshotter ),
94+ config .RemoteOpts = append (
95+ config .RemoteOpts ,
10296 containerd .WithImageHandlerWrapper (source .AppendDefaultLabelsHandlerWrapper (ref , 10 * 1024 * 1024 )),
103- }
104- containerdImage , err = client .Pull (ctx , ref , opts ... )
105- if err != nil {
106- return nil , err
107- }
108- } else {
109- config := & contentutil.FetchConfig {
110- Resolver : resolver ,
111- ProgressOutput : stdout ,
112- PlatformMatcher : platforms .Default (),
113- }
114-
115- img , err := contentutil .Fetch (ctx , client , ref , config )
116- if err != nil {
117- return nil , err
118- }
119- containerdImage = containerd .NewImageWithPlatform (client , img , config .PlatformMatcher )
120- if err := containerdImage .Unpack (ctx , snapshotter ); err != nil {
121- return nil , err
122- }
97+ )
98+ }
99+ containerdImage , err = contentutil .Pull (ctx , client , ref , config )
100+ if err != nil {
101+ return nil , err
123102 }
124103 res := & EnsuredImage {
125104 Ref : ref ,
0 commit comments