Skip to content

Commit

Permalink
deltas: Us a single tag with an index instead of tag per delta
Browse files Browse the repository at this point in the history
Instead of using lots of tags with names like delta-${shortid} we
use a single tag `deltas` with a list of delta manifest, each
specifying a target manifest by a `com.redhat.deltaTarget` annotation.

This means deltas are a lot less visible with a single tag, and
it also means we can use the full target digest instead of a short id.

The only disadvantage is that updating the index could race between
multiple writers, losing the concurrent update.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
  • Loading branch information
alexlarsson committed Apr 23, 2020
1 parent faabfc6 commit 2d26699
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions docker/docker_image_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,32 +201,37 @@ func (s *dockerImageSource) fetchManifest(ctx context.Context, tagOrDigest strin
return manblob, simplifyContentType(res.Header.Get("Content-Type")), nil
}

func (s *dockerImageSource) getDeltaManifestTagName(ctx context.Context, instanceDigest *digest.Digest) (string, error) {
digest, err := s.manifestDigest(ctx, instanceDigest)
if err != nil {
return "", err
}

return "delta-" + digest.Encoded()[:12], nil
}

func (s *dockerImageSource) GetDeltaManifest(ctx context.Context, instanceDigest *digest.Digest) ([]byte, string, error) {
tagname, err := s.getDeltaManifestTagName(ctx, instanceDigest)
// Get the real manifest digest
srcManifestDigest, err := s.manifestDigest(ctx, instanceDigest)
if err != nil {
return nil, "", err
}

// Load the delta manifest index
ib, _, err := s.fetchManifest(ctx, "deltas")
// Don't return error if the manifest doesn't exist, only for internal errors
// Deltas are an optional optimization anyway
mb, mt, _ := s.fetchManifest(ctx, tagname)
return mb, mt, nil
if err == nil {
index, err := manifest.OCI1IndexFromManifest(ib)
if err != nil {
return nil, "", err
}

// Look up the delta manifest in the index by the real manifest digest
for _, manifest := range index.Manifests {
if manifest.Annotations["com.redhat.deltaTarget"] == srcManifestDigest.String() {
return s.fetchManifest(ctx, manifest.Digest.String())
}
}
}

// No delta
return nil, "", nil
}

func (s *dockerImageSource) GetDeltaManifestDestination(ctx context.Context, instanceDigest *digest.Digest) (types.ImageDestination, error) {
tagname, err := s.getDeltaManifestTagName(ctx, instanceDigest)
if err != nil {
return nil, err
}
deltaRef, err := reference.WithTag(s.ref.ref, tagname)
deltaRef, err := reference.WithTag(s.ref.ref, "deltas")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2d26699

Please sign in to comment.