From 2d266990badd4155380b6dfaf4ec29c558a3e713 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 23 Apr 2020 14:56:18 +0200 Subject: [PATCH] deltas: Us a single tag with an index instead of tag per delta 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 --- docker/docker_image_src.go | 39 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/docker/docker_image_src.go b/docker/docker_image_src.go index 68995deb43..21a77ce311 100644 --- a/docker/docker_image_src.go +++ b/docker/docker_image_src.go @@ -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 }