From 03a6626e285575a86cd8bfa19edbfa1b821bfd4c Mon Sep 17 00:00:00 2001 From: Alexis Couvreur Date: Sat, 29 Mar 2025 22:12:47 -0400 Subject: [PATCH 1/2] fix(dind): use docker image load Loading images with docker image import does not preserve metatdata such as entrypoint, cmd, labels and tags. This makes the loaded image unusable as is. This replaces the command with docker image load which fully preserves the metadata. --- modules/dind/dind.go | 4 ++-- modules/dind/dind_test.go | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/dind/dind.go b/modules/dind/dind.go index 4a52d335a3..26e9778f3a 100644 --- a/modules/dind/dind.go +++ b/modules/dind/dind.go @@ -91,7 +91,7 @@ func (c *Container) LoadImage(ctx context.Context, image string) (err error) { err = errors.Join(err, os.Remove(imagesTar.Name())) }() - if err = provider.SaveImages(context.Background(), imagesTar.Name(), image); err != nil { + if err = provider.SaveImages(ctx, imagesTar.Name(), image); err != nil { return fmt.Errorf("save images: %w", err) } @@ -100,7 +100,7 @@ func (c *Container) LoadImage(ctx context.Context, image string) (err error) { return fmt.Errorf("copy image to container: %w", err) } - if _, _, err = c.Container.Exec(ctx, []string{"docker", "image", "import", containerPath, image}); err != nil { + if _, _, err = c.Container.Exec(ctx, []string{"docker", "image", "load", "-i", containerPath}); err != nil { return fmt.Errorf("import image: %w", err) } diff --git a/modules/dind/dind_test.go b/modules/dind/dind_test.go index a0154a4e62..de5ad2944f 100644 --- a/modules/dind/dind_test.go +++ b/modules/dind/dind_test.go @@ -2,7 +2,6 @@ package dind_test import ( "context" - "slices" "testing" "time" @@ -42,16 +41,21 @@ func Test_LoadImages(t *testing.T) { }) t.Run("success", func(t *testing.T) { - err := dindContainer.LoadImage(ctx, "nginx") + err := dindContainer.LoadImage(ctx, "nginx:1.27") require.NoError(t, err) images, err := cli.ImageList(ctx, image.ListOptions{}) require.NoError(t, err) - found := slices.ContainsFunc(images, func(img image.Summary) bool { - return len(img.RepoTags) > 0 && img.RepoTags[0] == "nginx:latest" - }) + if len(images) == 0 || len(images) > 1 { + t.Fatalf("got %d images, expected 1", len(images)) + } - require.True(t, found) + img, err := cli.ImageInspect(ctx, images[0].ID) + require.NoError(t, err) + + require.Equal(t, "nginx:1.27", img.RepoTags[0]) + require.Equal(t, []string{"/docker-entrypoint.sh"}, []string(img.Config.Entrypoint)) + require.Equal(t, []string{"nginx", "-g", "daemon off;"}, []string(img.Config.Cmd)) }) } From d1b1fd4648c01e9769c4e7cb3650c1529b7663be Mon Sep 17 00:00:00 2001 From: Alexis Couvreur Date: Mon, 31 Mar 2025 19:25:07 -0400 Subject: [PATCH 2/2] fix pull image --- modules/dind/dind_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/dind/dind_test.go b/modules/dind/dind_test.go index de5ad2944f..1b7ff2b929 100644 --- a/modules/dind/dind_test.go +++ b/modules/dind/dind_test.go @@ -32,7 +32,7 @@ func Test_LoadImages(t *testing.T) { require.NoError(t, err) // ensure nginx image is available locally - err = provider.PullImage(ctx, "nginx") + err = provider.PullImage(ctx, "nginx:1.27") require.NoError(t, err) t.Run("not-available", func(t *testing.T) {