Skip to content

Commit da79830

Browse files
committed
dockerutil.HasImage enhancements
1 parent 01e5b61 commit da79830

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pkg/docker/dockerutil/dockerutil.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,33 @@ func HasImage(dclient *dockerapi.Client, imageRef string) error {
8181
return ErrNotFound
8282
}
8383

84-
return nil
84+
for _, img := range imageList {
85+
if strings.HasPrefix(img.ID, "sha") {
86+
parts := strings.Split(img.ID, ":")
87+
if len(parts) == 2 && parts[1] == imageRef {
88+
return nil
89+
}
90+
} else {
91+
if img.ID == imageRef {
92+
return nil
93+
}
94+
}
95+
96+
for _, tag := range img.RepoTags {
97+
if tag == imageRef {
98+
return nil
99+
}
100+
101+
if !strings.Contains(imageRef, ":") {
102+
target := fmt.Sprintf("%s:latest", imageRef)
103+
if tag == target {
104+
return nil
105+
}
106+
}
107+
}
108+
}
109+
110+
return ErrNotFound
85111
}
86112

87113
func ListImages(dclient *dockerapi.Client, imageNameFilter string) (map[string]BasicImageProps, error) {

0 commit comments

Comments
 (0)