2015-07-29 18:12:01 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/distribution"
|
|
|
|
"github.com/docker/distribution/context"
|
|
|
|
"github.com/docker/distribution/digest"
|
|
|
|
"github.com/docker/distribution/registry/proxy/scheduler"
|
|
|
|
)
|
|
|
|
|
|
|
|
// todo(richardscothern): from cache control header or config
|
|
|
|
const repositoryTTL = time.Duration(24 * 7 * time.Hour)
|
|
|
|
|
|
|
|
type proxyManifestStore struct {
|
|
|
|
ctx context.Context
|
|
|
|
localManifests distribution.ManifestService
|
|
|
|
remoteManifests distribution.ManifestService
|
|
|
|
repositoryName string
|
|
|
|
scheduler *scheduler.TTLExpirationScheduler
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ distribution.ManifestService = &proxyManifestStore{}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
func (pms proxyManifestStore) Exists(ctx context.Context, dgst digest.Digest) (bool, error) {
|
|
|
|
exists, err := pms.localManifests.Exists(ctx, dgst)
|
2015-07-29 18:12:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if exists {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
return pms.remoteManifests.Exists(ctx, dgst)
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
func (pms proxyManifestStore) Get(ctx context.Context, dgst digest.Digest, options ...distribution.ManifestServiceOption) (distribution.Manifest, error) {
|
|
|
|
// At this point `dgst` was either specified explicitly, or returned by the
|
|
|
|
// tagstore with the most recent association.
|
|
|
|
var fromRemote bool
|
|
|
|
manifest, err := pms.localManifests.Get(ctx, dgst, options...)
|
2015-07-29 18:12:01 +00:00
|
|
|
if err != nil {
|
2015-08-21 04:50:15 +00:00
|
|
|
manifest, err = pms.remoteManifests.Get(ctx, dgst, options...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fromRemote = true
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
_, payload, err := manifest.Payload()
|
2015-07-29 18:12:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
proxyMetrics.ManifestPush(uint64(len(payload)))
|
|
|
|
if fromRemote {
|
|
|
|
proxyMetrics.ManifestPull(uint64(len(payload)))
|
2015-07-29 18:12:01 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
_, err = pms.localManifests.Put(ctx, manifest)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-07-29 18:12:01 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
// Schedule the repo for removal
|
|
|
|
pms.scheduler.AddManifest(pms.repositoryName, repositoryTTL)
|
2015-07-29 18:12:01 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
// Ensure the manifest blob is cleaned up
|
|
|
|
pms.scheduler.AddBlob(dgst.String(), repositoryTTL)
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
return manifest, err
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
func (pms proxyManifestStore) Put(ctx context.Context, manifest distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) {
|
|
|
|
var d digest.Digest
|
|
|
|
return d, distribution.ErrUnsupported
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
func (pms proxyManifestStore) Delete(ctx context.Context, dgst digest.Digest) error {
|
2015-08-11 18:00:30 +00:00
|
|
|
return distribution.ErrUnsupported
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
/*func (pms proxyManifestStore) Enumerate(ctx context.Context, manifests []distribution.Manifest, last distribution.Manifest) (n int, err error) {
|
|
|
|
return 0, distribution.ErrUnsupported
|
2015-07-29 18:12:01 +00:00
|
|
|
}
|
2015-08-21 04:50:15 +00:00
|
|
|
*/
|