Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OCI images #717

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tag pagination
  • Loading branch information
sjdaws committed Apr 11, 2023
commit ed45f87f3568fde439f0ea03f40b38524b006895
18 changes: 14 additions & 4 deletions registry/docker/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"regexp"
"strings"
)

var ErrNoMorePages = errors.New("no more pages")
Expand All @@ -29,11 +30,11 @@ func getNextLink(resp *http.Response) (string, error) {
return "", ErrNoMorePages
}

// getPaginatedJSON accepts a string and a pointer, and returns the
// getPaginatedJson accepts a string and a pointer, and returns the
// next page URL while updating pointed-to variable with a parsed JSON
// value. When there are no more pages it returns `ErrNoMorePages`.
func (registry *Registry) getPaginatedJSON(url string, response interface{}) (string, error) {
resp, err := registry.Client.Get(registry.url(url))
func (r *Registry) getPaginatedJSON(url string, response interface{}) (string, error) {
resp, err := r.Client.Get(url)
if err != nil {
return "", err
}
Expand All @@ -44,5 +45,14 @@ func (registry *Registry) getPaginatedJSON(url string, response interface{}) (st
if err != nil {
return "", err
}
return getNextLink(resp)
next, err := getNextLink(resp)
if err != nil {
return "", err
}

if !strings.HasPrefix(next, r.URL) {
next = r.URL + next
}

return next, nil
}
10 changes: 5 additions & 5 deletions registry/docker/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import (
)

// ManifestDigest - get manifest digest
func (registry *Registry) ManifestDigest(repository, reference string) (digest.Digest, error) {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.head url=%s repository=%s reference=%s", url, repository, reference)
func (r *Registry) ManifestDigest(repository, reference string) (digest.Digest, error) {
url := r.url("/v2/%s/manifests/%s", repository, reference)
r.Logf("registry.manifest.head url=%s repository=%s reference=%s", url, repository, reference)

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
}

req.Header.Set("Accept", manifestv2.MediaTypeManifest)
resp, err := registry.Client.Do(req)
resp, err := r.Client.Do(req)
if err != nil {
// Try OCI headers if error relates to OCI
if strings.Contains(err.Error(), "OCI index found, but accept header does not support OCI indexes") {
req.Header.Set("Accept", oci.MediaTypeImageIndex)
resp, err = registry.Client.Do(req)
resp, err = r.Client.Do(req)
}
if err != nil {
return "", err
Expand Down
4 changes: 0 additions & 4 deletions registry/docker/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ type tagsResponse struct {

func (r *Registry) url(pathTemplate string, args ...interface{}) string {
pathSuffix := fmt.Sprintf(pathTemplate, args...)
if strings.HasPrefix(pathSuffix, r.URL) {
return pathSuffix
}

url := fmt.Sprintf("%s%s", r.URL, pathSuffix)

return url
Expand Down
8 changes: 4 additions & 4 deletions registry/docker/tags.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package docker

func (registry *Registry) Tags(repository string) (tags []string, err error) {
url := registry.url("/v2/%s/tags/list", repository)
func (r *Registry) Tags(repository string) (tags []string, err error) {
url := r.url("/v2/%s/tags/list", repository)

var response tagsResponse
for {
registry.Logf("registry.tags url=%s repository=%s", url, repository)
url, err = registry.getPaginatedJSON(url, &response)
r.Logf("registry.tags url=%s repository=%s", url, repository)
url, err = r.getPaginatedJSON(url, &response)
switch err {
case ErrNoMorePages:
tags = append(tags, response.Tags...)
Expand Down