Skip to content

Commit

Permalink
manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zheng <zhengliang0901@gmail.com>
  • Loading branch information
microyahoo committed Apr 18, 2024
1 parent bd38006 commit 42eb58f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/registry/config-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ storage:
accesskey: testy
secretkey: testy
region: us-west-1
regionendpoint: http://10.9.8.73:80
regionendpoint: http://10.9.8.95:80
# forcepathstyle: true
# accelerate: false
bucket: test2
bucket: test
# encrypt: true
# chunksize: 5242880
multipartcopychunksize: 33554432
Expand Down
11 changes: 9 additions & 2 deletions registry/handlers/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"mime"
"net/http"
"strings"
"time"

"github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/internal/dcontext"
Expand Down Expand Up @@ -123,7 +124,7 @@ func (imh *manifestHandler) GetManifest(w http.ResponseWriter, r *http.Request)
}
return
}
imh.Digest = desc.Digest
imh.Digest = desc.Digest // 设置 digst
}

if etagMatch(r, imh.Digest.String()) {
Expand Down Expand Up @@ -455,7 +456,9 @@ func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Reques
return
}

err = manifests.Delete(imh, imh.Digest)
now := time.Now()
err = manifests.Delete(imh, imh.Digest) // 删除 <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/link
dcontext.GetLogger(imh).Infof("DeleteImageTag with digest %s with time: %s", imh.Digest, time.Since(now))
if err != nil {
switch err {
case digest.ErrDigestUnsupported:
Expand All @@ -475,18 +478,22 @@ func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Reques
}

tagService := imh.Repository.Tags(imh)
now = time.Now()
referencedTags, err := tagService.Lookup(imh, distribution.Descriptor{Digest: imh.Digest})
dcontext.GetLogger(imh).Infof("DeleteImageTag with lookup digest %s with time: %s", imh.Digest, time.Since(now))
if err != nil {
imh.Errors = append(imh.Errors, err)
return
}

now = time.Now()
for _, tag := range referencedTags {
if err := tagService.Untag(imh, tag); err != nil {
imh.Errors = append(imh.Errors, err)
return
}
}
dcontext.GetLogger(imh).Infof("DeleteImageTag with untag digest %s with time: %s", imh.Digest, time.Since(now))

w.WriteHeader(http.StatusAccepted)
}
2 changes: 1 addition & 1 deletion registry/storage/linkedblobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ type linkedBlobStatter struct {
var _ distribution.BlobDescriptorService = &linkedBlobStatter{}

func (lbs *linkedBlobStatter) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) {
blobLinkPath, err := lbs.linkPath(lbs.repository.Named().Name(), dgst)
blobLinkPath, err := lbs.linkPath(lbs.repository.Named().Name(), dgst) // <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/link
if err != nil {
return distribution.Descriptor{}, err
}
Expand Down
12 changes: 6 additions & 6 deletions registry/storage/tagstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ type tagStore struct {

// All returns all tags
func (ts *tagStore) All(ctx context.Context) ([]string, error) {
pathSpec, err := pathFor(manifestTagsPathSpec{
pathSpec, err := pathFor(manifestTagsPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/
name: ts.repository.Named().Name(),
})
if err != nil {
return nil, err
}

entries, err := ts.blobStore.driver.List(ctx, pathSpec)
entries, err := ts.blobStore.driver.List(ctx, pathSpec) // 以 s3 为例,列出 <root>/v2/repositories/<name>/_manifests/tags/ 目录下的所有 entries
if err != nil {
switch err := err.(type) {
case storagedriver.PathNotFoundError:
Expand Down Expand Up @@ -78,15 +78,15 @@ func (ts *tagStore) Tag(ctx context.Context, tag string, desc distribution.Descr

// resolve the current revision for name and tag.
func (ts *tagStore) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
currentPath, err := pathFor(manifestTagCurrentPathSpec{
currentPath, err := pathFor(manifestTagCurrentPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/<tag>/current/link
name: ts.repository.Named().Name(),
tag: tag,
})
if err != nil {
return distribution.Descriptor{}, err
}

revision, err := ts.blobStore.readlink(ctx, currentPath)
revision, err := ts.blobStore.readlink(ctx, currentPath) // 从 link 文件或对象中读取对应的 revision
if err != nil {
switch err.(type) {
case storagedriver.PathNotFoundError:
Expand All @@ -101,7 +101,7 @@ func (ts *tagStore) Get(ctx context.Context, tag string) (distribution.Descripto

// Untag removes the tag association
func (ts *tagStore) Untag(ctx context.Context, tag string) error {
tagPath, err := pathFor(manifestTagPathSpec{
tagPath, err := pathFor(manifestTagPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/<tag>/
name: ts.repository.Named().Name(),
tag: tag,
})
Expand Down Expand Up @@ -152,7 +152,7 @@ func (ts *tagStore) Lookup(ctx context.Context, desc distribution.Descriptor) ([
tag: tag,
}

tagLinkPath, _ := pathFor(tagLinkPathSpec)
tagLinkPath, _ := pathFor(tagLinkPathSpec) // <root>/v2/repositories/<name>/_manifests/tags/<tag>/current/link
tagDigest, err := ts.blobStore.readlink(ctx, tagLinkPath)
if err != nil {
switch err.(type) {
Expand Down

0 comments on commit 42eb58f

Please sign in to comment.