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:
Brian Bland 2016-01-06 15:57:35 -08:00
parent 3a35a2d953
commit 613cfc861d
4 changed files with 31 additions and 0 deletions

View File

@ -72,6 +72,15 @@ func (b *bridge) BlobPulled(repo string, desc distribution.Descriptor) error {
return b.createBlobEventAndWrite(EventActionPull, repo, desc) 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 { func (b *bridge) BlobDeleted(repo string, desc distribution.Descriptor) error {
return b.createBlobEventAndWrite(EventActionDelete, repo, desc) return b.createBlobEventAndWrite(EventActionDelete, repo, desc)
} }

View File

@ -11,6 +11,7 @@ import (
const ( const (
EventActionPull = "pull" EventActionPull = "pull"
EventActionPush = "push" EventActionPush = "push"
EventActionMount = "mount"
EventActionDelete = "delete" EventActionDelete = "delete"
) )
@ -61,6 +62,10 @@ type Event struct {
// Repository identifies the named repository. // Repository identifies the named repository.
Repository string `json:"repository,omitempty"` 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 provides a direct link to the content.
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
} `json:"target,omitempty"` } `json:"target,omitempty"`

View File

@ -24,6 +24,7 @@ type ManifestListener interface {
type BlobListener interface { type BlobListener interface {
BlobPushed(repo string, desc distribution.Descriptor) error BlobPushed(repo string, desc distribution.Descriptor) error
BlobPulled(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 // TODO(stevvooe): Please note that delete support is still a little shaky
// and we'll need to propagate these in the future. // 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 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 { func (bsl *blobServiceListener) decorateWriter(wr distribution.BlobWriter) distribution.BlobWriter {
return &blobWriterListener{ return &blobWriterListener{
BlobWriter: wr, BlobWriter: wr,

View File

@ -81,6 +81,11 @@ func (tl *testListener) BlobPulled(repo string, desc distribution.Descriptor) er
return nil 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 { func (tl *testListener) BlobDeleted(repo string, desc distribution.Descriptor) error {
tl.ops["layer:delete"]++ tl.ops["layer:delete"]++
return nil return nil