@@ -21,10 +21,12 @@ import (
2121 "fmt"
2222
2323 "github.com/containerd/containerd/content"
24+ "github.com/containerd/containerd/diff"
2425 "github.com/containerd/containerd/errdefs"
2526 "github.com/containerd/containerd/images"
2627 "github.com/containerd/containerd/platforms"
2728 "github.com/containerd/containerd/rootfs"
29+ "github.com/containerd/containerd/snapshots"
2830 "github.com/opencontainers/go-digest"
2931 "github.com/opencontainers/image-spec/identity"
3032 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -40,7 +42,7 @@ type Image interface {
4042 // Labels of the image
4143 Labels () map [string ]string
4244 // Unpack unpacks the image's content into a snapshot
43- Unpack (context.Context , string ) error
45+ Unpack (context.Context , string , ... UnpackOpt ) error
4446 // RootFS returns the unpacked diffids that make up images rootfs.
4547 RootFS (ctx context.Context ) ([]digest.Digest , error )
4648 // Size returns the total size of the image's packed resources.
@@ -130,13 +132,31 @@ func (i *image) IsUnpacked(ctx context.Context, snapshotterName string) (bool, e
130132 return false , nil
131133}
132134
133- func (i * image ) Unpack (ctx context.Context , snapshotterName string ) error {
135+ // UnpackConfig provides configuration for the unpack of an image
136+ type UnpackConfig struct {
137+ // ApplyOpts for applying a diff to a snapshotter
138+ ApplyOpts []diff.ApplyOpt
139+ // SnapshotOpts for configuring a snapshotter
140+ SnapshotOpts []snapshots.Opt
141+ }
142+
143+ // UnpackOpt provides configuration for unpack
144+ type UnpackOpt func (context.Context , * UnpackConfig ) error
145+
146+ func (i * image ) Unpack (ctx context.Context , snapshotterName string , opts ... UnpackOpt ) error {
134147 ctx , done , err := i .client .WithLease (ctx )
135148 if err != nil {
136149 return err
137150 }
138151 defer done (ctx )
139152
153+ var config UnpackConfig
154+ for _ , o := range opts {
155+ if err := o (ctx , & config ); err != nil {
156+ return err
157+ }
158+ }
159+
140160 layers , err := i .getLayers (ctx , i .platform )
141161 if err != nil {
142162 return err
@@ -158,7 +178,7 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
158178 return err
159179 }
160180 for _ , layer := range layers {
161- unpacked , err = rootfs .ApplyLayer (ctx , layer , chain , sn , a )
181+ unpacked , err = rootfs .ApplyLayerWithOpts (ctx , layer , chain , sn , a , config . SnapshotOpts , config . ApplyOpts )
162182 if err != nil {
163183 return err
164184 }
0 commit comments