@@ -22,6 +22,7 @@ import (
22
22
23
23
containerd "github.com/containerd/containerd/v2/client"
24
24
"github.com/containerd/errdefs"
25
+ "github.com/containerd/log"
25
26
26
27
"github.com/containerd/nerdctl/v2/pkg/api/types"
27
28
"github.com/containerd/nerdctl/v2/pkg/idutil/imagewalker"
@@ -31,7 +32,7 @@ import (
31
32
func Tag (ctx context.Context , client * containerd.Client , options types.ImageTagOptions ) error {
32
33
imageService := client .ImageService ()
33
34
var srcName string
34
- imagewalker := & imagewalker.ImageWalker {
35
+ walker := & imagewalker.ImageWalker {
35
36
Client : client ,
36
37
OnFound : func (ctx context.Context , found imagewalker.Found ) error {
37
38
if srcName == "" {
@@ -40,7 +41,7 @@ func Tag(ctx context.Context, client *containerd.Client, options types.ImageTagO
40
41
return nil
41
42
},
42
43
}
43
- matchCount , err := imagewalker .Walk (ctx , options .Source )
44
+ matchCount , err := walker .Walk (ctx , options .Source )
44
45
if err != nil {
45
46
return err
46
47
}
@@ -59,17 +60,25 @@ func Tag(ctx context.Context, client *containerd.Client, options types.ImageTagO
59
60
}
60
61
defer done (ctx )
61
62
62
- image , err := imageService .Get (ctx , srcName )
63
+ // Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3425
64
+ err = EnsureAllContent (ctx , client , srcName , options .GOptions )
65
+ if err != nil {
66
+ log .G (ctx ).Warn ("Unable to fetch missing layers before committing. " +
67
+ "If you try to save or push this image, it might fail. See https://github.com/containerd/nerdctl/issues/3439." )
68
+ }
69
+
70
+ img , err := imageService .Get (ctx , srcName )
63
71
if err != nil {
64
72
return err
65
73
}
66
- image .Name = target .String ()
67
- if _ , err = imageService .Create (ctx , image ); err != nil {
74
+
75
+ img .Name = target .String ()
76
+ if _ , err = imageService .Create (ctx , img ); err != nil {
68
77
if errdefs .IsAlreadyExists (err ) {
69
- if err = imageService .Delete (ctx , image .Name ); err != nil {
78
+ if err = imageService .Delete (ctx , img .Name ); err != nil {
70
79
return err
71
80
}
72
- if _ , err = imageService .Create (ctx , image ); err != nil {
81
+ if _ , err = imageService .Create (ctx , img ); err != nil {
73
82
return err
74
83
}
75
84
} else {
0 commit comments