Skip to content

Commit

Permalink
Update for manifest-lists API changes in containers/image
Browse files Browse the repository at this point in the history
Update the blobcache implementation to match API changes to the image
library.

Signed-off-by: Nalin Dahyabhai <[email protected]>

Closes: containers#1902
Approved by: rhatdan
  • Loading branch information
nalind authored and caiges committed Nov 12, 2019
1 parent ebf8f71 commit 3b80cc3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion image.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func (i *containerImageSource) GetManifest(ctx context.Context, instanceDigest *
return i.manifest, i.manifestType, nil
}

func (i *containerImageSource) LayerInfosForCopy(ctx context.Context) ([]types.BlobInfo, error) {
func (i *containerImageSource) LayerInfosForCopy(ctx context.Context, instanceDigest *digest.Digest) ([]types.BlobInfo, error) {
return nil, nil
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/blobcache/blobcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,14 @@ func (s *blobCacheSource) GetSignatures(ctx context.Context, instanceDigest *dig
return s.source.GetSignatures(ctx, instanceDigest)
}

func (s *blobCacheSource) LayerInfosForCopy(ctx context.Context) ([]types.BlobInfo, error) {
signatures, err := s.source.GetSignatures(ctx, nil)
func (s *blobCacheSource) LayerInfosForCopy(ctx context.Context, instanceDigest *digest.Digest) ([]types.BlobInfo, error) {
signatures, err := s.source.GetSignatures(ctx, instanceDigest)
if err != nil {
return nil, errors.Wrapf(err, "error checking if image %q has signatures", transports.ImageName(s.reference))
}
canReplaceBlobs := !(len(signatures) > 0 && len(signatures[0]) > 0)

infos, err := s.source.LayerInfosForCopy(ctx)
infos, err := s.source.LayerInfosForCopy(ctx, instanceDigest)
if err != nil {
return nil, errors.Wrapf(err, "error getting layer infos for copying image %q through cache", transports.ImageName(s.reference))
}
Expand Down Expand Up @@ -515,7 +515,7 @@ func (d *blobCacheDestination) TryReusingBlob(ctx context.Context, info types.Bl
return false, types.BlobInfo{}, nil
}

func (d *blobCacheDestination) PutManifest(ctx context.Context, manifestBytes []byte) error {
func (d *blobCacheDestination) PutManifest(ctx context.Context, manifestBytes []byte, instanceDigest *digest.Digest) error {
manifestDigest, err := manifest.Digest(manifestBytes)
if err != nil {
logrus.Warnf("error digesting manifest %q: %v", string(manifestBytes), err)
Expand All @@ -525,13 +525,13 @@ func (d *blobCacheDestination) PutManifest(ctx context.Context, manifestBytes []
logrus.Warnf("error saving manifest as %q: %v", filename, err)
}
}
return d.destination.PutManifest(ctx, manifestBytes)
return d.destination.PutManifest(ctx, manifestBytes, instanceDigest)
}

func (d *blobCacheDestination) PutSignatures(ctx context.Context, signatures [][]byte) error {
return d.destination.PutSignatures(ctx, signatures)
func (d *blobCacheDestination) PutSignatures(ctx context.Context, signatures [][]byte, instanceDigest *digest.Digest) error {
return d.destination.PutSignatures(ctx, signatures, instanceDigest)
}

func (d *blobCacheDestination) Commit(ctx context.Context) error {
return d.destination.Commit(ctx)
func (d *blobCacheDestination) Commit(ctx context.Context, unparsedToplevel types.UnparsedImage) error {
return d.destination.Commit(ctx, unparsedToplevel)
}
28 changes: 21 additions & 7 deletions pkg/blobcache/blobcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"testing"

cp "github.com/containers/image/v5/copy"
"github.com/containers/image/v5/image"
"github.com/containers/image/v5/pkg/blobinfocache/none"
"github.com/containers/image/v5/signature"
"github.com/containers/image/v5/transports/alltransports"
Expand Down Expand Up @@ -67,6 +68,8 @@ func TestBlobCache(t *testing.T) {
}
}()

systemContext := types.SystemContext{}

for _, repeat := range []int{1, 10, 100, 1000, 10000} {
for _, desiredCompression := range []types.LayerCompression{types.PreserveOriginal, types.Compress, types.Decompress} {
for _, layerCompression := range []archive.Compression{archive.Uncompressed, archive.Gzip} {
Expand Down Expand Up @@ -100,12 +103,14 @@ func TestBlobCache(t *testing.T) {
SchemaVersion: 2,
},
Config: v1.Descriptor{
Digest: configInfo.Digest,
Size: configInfo.Size,
MediaType: v1.MediaTypeImageConfig,
Digest: configInfo.Digest,
Size: configInfo.Size,
},
Layers: []v1.Descriptor{{
Digest: blobInfo.Digest,
Size: blobInfo.Size,
MediaType: v1.MediaTypeImageLayer,
Digest: blobInfo.Digest,
Size: blobInfo.Size,
}},
}
manifestBytes, err := json.Marshal(&manifest)
Expand Down Expand Up @@ -139,11 +144,21 @@ func TestBlobCache(t *testing.T) {
if err != nil {
t.Fatalf("error writing config blob to source image: %v", err)
}
err = destImage.PutManifest(context.TODO(), manifestBytes)
srcImage, err := srcRef.NewImageSource(context.TODO(), &systemContext)
if err != nil {
t.Fatalf("error opening source image: %v", err)
}
defer func() {
err := srcImage.Close()
if err != nil {
t.Fatalf("error closing source image: %v", err)
}
}()
err = destImage.PutManifest(context.TODO(), manifestBytes, nil)
if err != nil {
t.Fatalf("error writing manifest to source image: %v", err)
}
err = destImage.Commit(context.TODO())
err = destImage.Commit(context.TODO(), image.UnparsedInstance(srcImage, nil))
if err != nil {
t.Fatalf("error committing source image: %v", err)
}
Expand Down Expand Up @@ -210,7 +225,6 @@ func TestBlobCache(t *testing.T) {
if err != nil {
t.Fatalf("error parsing destination image name %q: %v", destName, err)
}
systemContext := types.SystemContext{}
options := cp.Options{
SourceCtx: &systemContext,
DestinationCtx: &systemContext,
Expand Down

0 comments on commit 3b80cc3

Please sign in to comment.