Skip to content

Commit

Permalink
Ensure all layers are here when committing
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <[email protected]>
  • Loading branch information
apostasie committed Sep 18, 2024
1 parent 009096d commit 58a9dd3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/nerdctl/container/container_commit_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It will regularly succeed or fail, making random PR fail the Kube check.
func TestKubeCommitPush(t *testing.T) {
t.Parallel()

t.Skip("Test that confirm that #827 is still broken is too flaky")
// t.Skip("Test that confirm that #827 is still broken is too flaky")

base := testutil.NewBaseForKubernetes(t)
tID := testutil.Identifier(t)
Expand Down Expand Up @@ -73,8 +73,8 @@ func TestKubeCommitPush(t *testing.T) {
base.Cmd("commit", containerID, "registry.example.com/my-app:v1").AssertOK()
// See note above.
base.Cmd("push", "registry.example.com/my-app:v1").Assert(icmd.Expected{
ExitCode: 1,
Err: "failed to create a tmp single-platform image",
ExitCode: 0,
// Err: "failed to create a tmp single-platform image",
})
})
}
2 changes: 1 addition & 1 deletion pkg/cmd/container/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Commit(ctx context.Context, client *containerd.Client, rawRef string, req s
if found.MatchCount > 1 {
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
}
imageID, err := commit.Commit(ctx, client, found.Container, opts)
imageID, err := commit.Commit(ctx, client, found.Container, opts, options.GOptions)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/imgutil/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/containerd/log"
"github.com/containerd/platforms"

"github.com/containerd/nerdctl/v2/pkg/api/types"
imgutil "github.com/containerd/nerdctl/v2/pkg/imgutil"
"github.com/containerd/nerdctl/v2/pkg/labels"
)
Expand All @@ -65,7 +66,7 @@ var (
emptyDigest = digest.Digest("")
)

func Commit(ctx context.Context, client *containerd.Client, container containerd.Container, opts *Opts) (digest.Digest, error) {
func Commit(ctx context.Context, client *containerd.Client, container containerd.Container, opts *Opts, options types.GlobalCommandOptions) (digest.Digest, error) {
id := container.ID()
info, err := container.Info(ctx)
if err != nil {
Expand Down Expand Up @@ -96,6 +97,12 @@ func Commit(ctx context.Context, client *containerd.Client, container containerd
return emptyDigest, err
}

// Ensure all the layers are here: https://github.com/containerd/nerdctl/issues/3425
err = imgutil.EnsureAllContent(ctx, client, baseImg.Name(), "", options)
if err != nil {
return emptyDigest, err
}

if opts.Pause {
task, err := container.Task(ctx, cio.Load)
if err != nil {
Expand Down

0 comments on commit 58a9dd3

Please sign in to comment.