Skip to content

Commit

Permalink
image can be set to a local ID, that isn't a valid docker ref
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof authored and glours committed Jan 9, 2025
1 parent a351585 commit fa39503
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/compose/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions pkg/e2e/fixtures/simple-composefile/id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
test:
image: ${ID:?ID variable must be set}
15 changes: 15 additions & 0 deletions pkg/e2e/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit fa39503

Please sign in to comment.