MCPcopy Create free account
hub / github.com/devspace-sh/devspace / CompareImageNames

Function CompareImageNames

pkg/devspace/imageselector/image_selector.go:79–113  ·  view source on GitHub ↗
(selector string, image2 string)

Source from the content-addressed store, hash-verified

77}
78
79func CompareImageNames(selector string, image2 string) bool {
80 image1 := selector
81
82 // we replace possible # with a's here to avoid an parsing error
83 // since the tag is stripped anyways it doesn't really matter if we lose
84 // information where the # were
85 tagStrippedImage1, _, err := dockerfile.GetStrippedDockerImageName(strings.ReplaceAll(image1, "#", "a"))
86 if err != nil {
87 tagStrippedImage1 = image1
88 }
89 tagStrippedImage2, _, err := dockerfile.GetStrippedDockerImageName(image2)
90 if err != nil {
91 tagStrippedImage2 = image2
92 }
93
94 if tagStrippedImage1 != image1 {
95 // In the case that the tag is latest and we find an image that has no tag
96 if tagStrippedImage1+":latest" == image1 && tagStrippedImage2 == image2 {
97 return true
98 }
99
100 // if the tag consists of a # we build a regex
101 if strings.Contains(image1, "#") {
102 regex := "^" + strings.ReplaceAll(image1, "#", "[a-zA-Z]") + "$"
103 exp, err := regexp.Compile(regex)
104 if err == nil {
105 return exp.MatchString(image2)
106 }
107 }
108
109 return image1 == image2
110 }
111
112 return tagStrippedImage1 == tagStrippedImage2
113}

Callers 2

matchesImageSelectorFunction · 0.92
byImageNameFunction · 0.92

Calls 1

Tested by

no test coverage detected