Skip to content

Commit

Permalink
fix: image digest check may meet race condition
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Qi <[email protected]>
  • Loading branch information
jinqi7 committed Feb 22, 2024
1 parent e0fcc8b commit f264bd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 204 deletions.
194 changes: 0 additions & 194 deletions tests/release/pipelines/push_to_external_registry.go

This file was deleted.

29 changes: 19 additions & 10 deletions tests/release/quay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,34 @@ var (
quayClient = quay.NewQuayClient(&http.Client{Transport: &http.Transport{}}, quayToken, quayApiUrl)
)

// imageURL format example: quay.io/redhat-appstudio-qe/devfile-go-rhtap-uvv7:latest
func GetDigestWithTagInQuay(imageURL string) (string, error) {
urlParts := strings.Split(imageURL, ":")
// imageURL format example: quay.io/redhat-appstudio-qe/dcmetromap@sha256:386exxx
func DoesDigestExistInQuay(imageURL string) (bool, error) {
urlParts := strings.Split(imageURL, "@")
if len(urlParts) != 2 {
return "", fmt.Errorf("image URL %s has incorrect format", imageURL)
return false, fmt.Errorf("image URL %s has incorrect format", imageURL)
}

repoParts := strings.Split(urlParts[0], "/")
if len(repoParts) <= 2 {
return "", fmt.Errorf("image URL %s is not complete", imageURL)
return false, fmt.Errorf("image URL %s is not complete", imageURL)
}

repoName := strings.Join(repoParts[2:], "/")
tagList, _, err := quayClient.GetTagsFromPage(quayOrg, repoName, 0)
tagList, _, err := quayClient.GetTagsFromPage(repoParts[1], repoName, 0)
if err != nil {
return "", err
return false, err
}

digestParts := strings.Split(urlParts[1], ":")
if len(digestParts) != 2 {
return false, fmt.Errorf("image URL %s has incorrect format", imageURL)
}

for _, tag := range tagList {
if tag.Name == urlParts[1] {
return tag.ManifestDigest, nil
if tag.ManifestDigest == digestParts[1] {
return true, nil
}
}
return "", fmt.Errorf("no image is found")

return false, fmt.Errorf("no image is found")
}

0 comments on commit f264bd7

Please sign in to comment.