From fa395034692b71d066da3593058c819186782f88 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 8 Jan 2025 18:13:53 +0100 Subject: [PATCH] image can be set to a local ID, that isn't a valid docker ref Signed-off-by: Nicolas De Loof --- pkg/compose/images.go | 12 ++++++------ pkg/e2e/fixtures/simple-composefile/id.yaml | 3 +++ pkg/e2e/up_test.go | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 pkg/e2e/fixtures/simple-composefile/id.yaml diff --git a/pkg/compose/images.go b/pkg/compose/images.go index 91c3e718e..a85a18288 100644 --- a/pkg/compose/images.go +++ b/pkg/compose/images.go @@ -94,12 +94,12 @@ func (s *composeService) getImageSummaries(ctx context.Context, repoTags []strin tag := "" repository := "" ref, err := reference.ParseDockerRef(repoTag) - if err != nil { - return err - } - repository = reference.FamiliarName(ref) - if tagged, ok := ref.(reference.Tagged); ok { - tag = tagged.Tag() + if err == nil { + // ParseDockerRef will reject a local image ID + repository = reference.FamiliarName(ref) + if tagged, ok := ref.(reference.Tagged); ok { + tag = tagged.Tag() + } } l.Lock() summary[repoTag] = api.ImageSummary{ diff --git a/pkg/e2e/fixtures/simple-composefile/id.yaml b/pkg/e2e/fixtures/simple-composefile/id.yaml new file mode 100644 index 000000000..67ac13f73 --- /dev/null +++ b/pkg/e2e/fixtures/simple-composefile/id.yaml @@ -0,0 +1,3 @@ +services: + test: + image: ${ID:?ID variable must be set} diff --git a/pkg/e2e/up_test.go b/pkg/e2e/up_test.go index 4d7202c14..6a927f0aa 100644 --- a/pkg/e2e/up_test.go +++ b/pkg/e2e/up_test.go @@ -191,3 +191,18 @@ func TestUpProfile(t *testing.T) { assert.Assert(t, strings.Contains(res.Combined(), `Container foo_c Created`), res.Combined()) assert.Assert(t, !strings.Contains(res.Combined(), `Container bar_c Created`), res.Combined()) } + +func TestUpImageID(t *testing.T) { + c := NewCLI(t) + const projectName = "compose-e2e-up-image-id" + + digest := strings.TrimSpace(c.RunDockerCmd(t, "image", "inspect", "alpine", "-f", "{{ .ID }}").Stdout()) + _, id, _ := strings.Cut(digest, ":") + + t.Cleanup(func() { + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "-v") + }) + + c = NewCLI(t, WithEnv(fmt.Sprintf("ID=%s", id))) + c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-composefile/id.yaml", "--project-name", projectName, "up") +}