Skip to content

Commit 1e52bf5

Browse files
committed
EnsureAllContent on tag
Signed-off-by: apostasie <[email protected]>
1 parent 8e10d87 commit 1e52bf5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pkg/cmd/image/tag.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
containerd "github.com/containerd/containerd/v2/client"
2424
"github.com/containerd/errdefs"
25+
"github.com/containerd/log"
2526

2627
"github.com/containerd/nerdctl/v2/pkg/api/types"
2728
"github.com/containerd/nerdctl/v2/pkg/idutil/imagewalker"
@@ -31,7 +32,7 @@ import (
3132
func Tag(ctx context.Context, client *containerd.Client, options types.ImageTagOptions) error {
3233
imageService := client.ImageService()
3334
var srcName string
34-
imagewalker := &imagewalker.ImageWalker{
35+
walker := &imagewalker.ImageWalker{
3536
Client: client,
3637
OnFound: func(ctx context.Context, found imagewalker.Found) error {
3738
if srcName == "" {
@@ -40,7 +41,7 @@ func Tag(ctx context.Context, client *containerd.Client, options types.ImageTagO
4041
return nil
4142
},
4243
}
43-
matchCount, err := imagewalker.Walk(ctx, options.Source)
44+
matchCount, err := walker.Walk(ctx, options.Source)
4445
if err != nil {
4546
return err
4647
}
@@ -59,17 +60,25 @@ func Tag(ctx context.Context, client *containerd.Client, options types.ImageTagO
5960
}
6061
defer done(ctx)
6162

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)
6371
if err != nil {
6472
return err
6573
}
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 {
6877
if errdefs.IsAlreadyExists(err) {
69-
if err = imageService.Delete(ctx, image.Name); err != nil {
78+
if err = imageService.Delete(ctx, img.Name); err != nil {
7079
return err
7180
}
72-
if _, err = imageService.Create(ctx, image); err != nil {
81+
if _, err = imageService.Create(ctx, img); err != nil {
7382
return err
7483
}
7584
} else {

0 commit comments

Comments
 (0)