feat: proxy download image
This commit is contained in:
@ -19,7 +19,7 @@ import (
|
||||
|
||||
type memManifest struct {
|
||||
sync.RWMutex
|
||||
m map[string]map[string]*model.Manifest
|
||||
m map[string]map[string]*model.RepoSimpleManifest
|
||||
}
|
||||
|
||||
func (m *memManifest) Referrers(ctx context.Context, repo string, target string) (*model.IndexManifest, *rerr.RepositoryError) {
|
||||
@ -81,7 +81,7 @@ func (m *memManifest) Referrers(ctx context.Context, repo string, target string)
|
||||
return im, nil
|
||||
}
|
||||
|
||||
func (m *memManifest) Tags(ctx context.Context, repo string, limit int, last int) (*model.Tag, *rerr.RepositoryError) {
|
||||
func (m *memManifest) Tags(ctx context.Context, repo string, limit int, last int, keyword string) (*model.Tag, *rerr.RepositoryError) {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
|
||||
@ -96,10 +96,20 @@ func (m *memManifest) Tags(ctx context.Context, repo string, limit int, last int
|
||||
|
||||
var tags []string
|
||||
for tag := range c {
|
||||
if !strings.Contains(tag, "sha256:") {
|
||||
if strings.Contains(tag, "sha256:") {
|
||||
continue
|
||||
}
|
||||
|
||||
if keyword == "" {
|
||||
tags = append(tags, tag)
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(tag, keyword) {
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(tags)
|
||||
|
||||
// https://github.com/opencontainers/distribution-spec/blob/b505e9cc53ec499edbd9c1be32298388921bb705/detail.md#tags-paginated
|
||||
@ -134,7 +144,7 @@ func (m *memManifest) Tags(ctx context.Context, repo string, limit int, last int
|
||||
return tagsToList, nil
|
||||
}
|
||||
|
||||
func (m *memManifest) Catelog(ctx context.Context, limit, last int) (*model.Catalog, *rerr.RepositoryError) {
|
||||
func (m *memManifest) Catalog(ctx context.Context, limit, last int, keyword string) (*model.Catalog, *rerr.RepositoryError) {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
|
||||
@ -146,23 +156,24 @@ func (m *memManifest) Catelog(ctx context.Context, limit, last int) (*model.Cata
|
||||
if countRepos >= limit {
|
||||
break
|
||||
}
|
||||
|
||||
if keyword != "" && !strings.Contains(key, keyword) {
|
||||
continue
|
||||
}
|
||||
|
||||
countRepos++
|
||||
|
||||
repos = append(repos, key)
|
||||
}
|
||||
|
||||
repositoriesToList := &model.Catalog{
|
||||
Repos: repos,
|
||||
Repositories: repos,
|
||||
}
|
||||
|
||||
return repositoriesToList, nil
|
||||
}
|
||||
|
||||
func (m *memManifest) Put(ctx context.Context, repo string, target string, digest string, mf *model.Manifest) *rerr.RepositoryError {
|
||||
// If the manifest
|
||||
// list's constituent manifests are already uploaded.
|
||||
// This isn't strictly required by the registry API, but some
|
||||
// registries require this.
|
||||
func (m *memManifest) Put(ctx context.Context, repo string, target string, digest string, mf *model.RepoSimpleManifest) *rerr.RepositoryError {
|
||||
if types.MediaType(mf.ContentType).IsIndex() {
|
||||
if err := func() *rerr.RepositoryError {
|
||||
m.RLock()
|
||||
@ -205,7 +216,7 @@ func (m *memManifest) Put(ctx context.Context, repo string, target string, diges
|
||||
defer m.Unlock()
|
||||
|
||||
if _, ok := m.m[repo]; !ok {
|
||||
m.m[repo] = make(map[string]*model.Manifest, 2)
|
||||
m.m[repo] = make(map[string]*model.RepoSimpleManifest, 2)
|
||||
}
|
||||
|
||||
// Allow future references by target (tag) and immutable digest.
|
||||
@ -274,5 +285,5 @@ func (m *memManifest) Get(ctx context.Context, repo string, target string) (io.R
|
||||
}
|
||||
|
||||
func NewManifestMemHandler() interfaces.ManifestHandler {
|
||||
return &memManifest{m: make(map[string]map[string]*model.Manifest)}
|
||||
return &memManifest{m: make(map[string]map[string]*model.RepoSimpleManifest)}
|
||||
}
|
||||
|
Reference in New Issue
Block a user