forked from TrueCloudLab/distribution
Fires a new Mount event when blobs are cross-repo mounted
Adds an optional "fromRepository" field to the event target Signed-off-by: Brian Bland <brian.bland@docker.com>
This commit is contained in:
parent
3a35a2d953
commit
613cfc861d
4 changed files with 31 additions and 0 deletions
|
@ -72,6 +72,15 @@ func (b *bridge) BlobPulled(repo string, desc distribution.Descriptor) error {
|
|||
return b.createBlobEventAndWrite(EventActionPull, repo, desc)
|
||||
}
|
||||
|
||||
func (b *bridge) BlobMounted(repo string, desc distribution.Descriptor, fromRepo string) error {
|
||||
event, err := b.createBlobEvent(EventActionMount, repo, desc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
event.Target.FromRepository = fromRepo
|
||||
return b.sink.Write(*event)
|
||||
}
|
||||
|
||||
func (b *bridge) BlobDeleted(repo string, desc distribution.Descriptor) error {
|
||||
return b.createBlobEventAndWrite(EventActionDelete, repo, desc)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
const (
|
||||
EventActionPull = "pull"
|
||||
EventActionPush = "push"
|
||||
EventActionMount = "mount"
|
||||
EventActionDelete = "delete"
|
||||
)
|
||||
|
||||
|
@ -61,6 +62,10 @@ type Event struct {
|
|||
// Repository identifies the named repository.
|
||||
Repository string `json:"repository,omitempty"`
|
||||
|
||||
// FromRepository identifies the named repository which a blob was mounted
|
||||
// from if appropriate.
|
||||
FromRepository string `json:"fromRepository,omitempty"`
|
||||
|
||||
// URL provides a direct link to the content.
|
||||
URL string `json:"url,omitempty"`
|
||||
} `json:"target,omitempty"`
|
||||
|
|
|
@ -24,6 +24,7 @@ type ManifestListener interface {
|
|||
type BlobListener interface {
|
||||
BlobPushed(repo string, desc distribution.Descriptor) error
|
||||
BlobPulled(repo string, desc distribution.Descriptor) error
|
||||
BlobMounted(repo string, desc distribution.Descriptor, fromRepo string) error
|
||||
|
||||
// TODO(stevvooe): Please note that delete support is still a little shaky
|
||||
// and we'll need to propagate these in the future.
|
||||
|
@ -169,6 +170,17 @@ func (bsl *blobServiceListener) Resume(ctx context.Context, id string) (distribu
|
|||
return bsl.decorateWriter(wr), err
|
||||
}
|
||||
|
||||
func (bsl *blobServiceListener) Mount(ctx context.Context, sourceRepo string, dgst digest.Digest) (distribution.Descriptor, error) {
|
||||
desc, err := bsl.BlobStore.Mount(ctx, sourceRepo, dgst)
|
||||
if err == nil {
|
||||
if err := bsl.parent.listener.BlobMounted(bsl.parent.Repository.Name(), desc, sourceRepo); err != nil {
|
||||
context.GetLogger(ctx).Errorf("error dispatching layer mount to listener: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return desc, err
|
||||
}
|
||||
|
||||
func (bsl *blobServiceListener) decorateWriter(wr distribution.BlobWriter) distribution.BlobWriter {
|
||||
return &blobWriterListener{
|
||||
BlobWriter: wr,
|
||||
|
|
|
@ -81,6 +81,11 @@ func (tl *testListener) BlobPulled(repo string, desc distribution.Descriptor) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) BlobMounted(repo string, desc distribution.Descriptor, fromRepo string) error {
|
||||
tl.ops["layer:mount"]++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tl *testListener) BlobDeleted(repo string, desc distribution.Descriptor) error {
|
||||
tl.ops["layer:delete"]++
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue