diff --git a/image.go b/image.go index 8eaf3d264..53b5e2486 100644 --- a/image.go +++ b/image.go @@ -32,6 +32,8 @@ type Image interface { Config(ctx context.Context) (ocispec.Descriptor, error) // IsUnpacked returns whether or not an image is unpacked. IsUnpacked(context.Context, string) (bool, error) + // ContentStore provides a content store which contains image blob data + ContentStore() content.Store } var _ = (Image)(&image{}) @@ -166,3 +168,7 @@ func (i *image) getLayers(ctx context.Context, platform string) ([]rootfs.Layer, } return layers, nil } + +func (i *image) ContentStore() content.Store { + return i.client.ContentStore() +} diff --git a/oci/client.go b/oci/client.go index bac2aa9c4..7b7283867 100644 --- a/oci/client.go +++ b/oci/client.go @@ -11,11 +11,12 @@ import ( // Client interface used by SpecOpt type Client interface { SnapshotService(snapshotterName string) snapshot.Snapshotter - ContentStore() content.Store } // Image interface used by some SpecOpt to query image configuration type Image interface { // Config descriptor for the image. Config(ctx context.Context) (ocispec.Descriptor, error) + // ContentStore provides a content store which contains image blob data + ContentStore() content.Store } diff --git a/oci/spec_opts_unix.go b/oci/spec_opts_unix.go index e24ef5f6e..5ca2f0f0a 100644 --- a/oci/spec_opts_unix.go +++ b/oci/spec_opts_unix.go @@ -67,12 +67,6 @@ func WithLinuxNamespace(ns specs.LinuxNamespace) SpecOpts { // WithImageConfig configures the spec to from the configuration of an Image func WithImageConfig(image Image) SpecOpts { return func(ctx context.Context, client Client, c *containers.Container, s *specs.Spec) error { - store := client.ContentStore() - // TODO: needs review. Previous this passed in a store, now it's using - // a store that is part of the client. This makes the assumption that - // the client store is the same as the one wrapped by `image`. - // Is this assumption safe? Should the interface be changed to accept - // a store instead of wrapping one? ic, err := image.Config(ctx) if err != nil { return err @@ -83,7 +77,7 @@ func WithImageConfig(image Image) SpecOpts { ) switch ic.MediaType { case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config: - p, err := content.ReadBlob(ctx, store, ic.Digest) + p, err := content.ReadBlob(ctx, image.ContentStore(), ic.Digest) if err != nil { return err } diff --git a/oci/spec_opts_windows.go b/oci/spec_opts_windows.go index 5d43bca64..3605f8e48 100644 --- a/oci/spec_opts_windows.go +++ b/oci/spec_opts_windows.go @@ -17,7 +17,6 @@ import ( // WithImageConfig configures the spec to from the configuration of an Image func WithImageConfig(image Image) SpecOpts { return func(ctx context.Context, client Client, _ *containers.Container, s *specs.Spec) error { - store := client.ContentStore() ic, err := image.Config(ctx) if err != nil { return err @@ -28,7 +27,7 @@ func WithImageConfig(image Image) SpecOpts { ) switch ic.MediaType { case v1.MediaTypeImageConfig, images.MediaTypeDockerSchema2Config: - p, err := content.ReadBlob(ctx, store, ic.Digest) + p, err := content.ReadBlob(ctx, image.ContentStore(), ic.Digest) if err != nil { return err }