@@ -87,13 +87,33 @@ type imageConfig struct {
8787 img ocispec.Image
8888}
8989
90+ type importConfig struct {
91+ unpack bool
92+ snapshotter string
93+ }
94+
95+ // ImportOption configures import behavior.
96+ type ImportOption func (* importConfig )
97+
98+ // WithUnpack is used to unpack image after import.
99+ func WithUnpack (snapshotter string ) ImportOption {
100+ return func (c * importConfig ) {
101+ c .unpack = true
102+ c .snapshotter = snapshotter
103+ }
104+ }
105+
90106// Import implements Docker Image Spec v1.1.
91107// An image MUST have `manifest.json`.
92108// `repositories` file in Docker Image Spec v1.0 is not supported (yet).
93109// Also, the current implementation assumes the implicit file name convention,
94110// which is not explicitly documented in the spec. (e.g. foobar/layer.tar)
95111// It returns a group of image references successfully loaded.
96- func Import (ctx context.Context , client * containerd.Client , reader io.Reader ) (_ []string , retErr error ) {
112+ func Import (ctx context.Context , client * containerd.Client , reader io.Reader , opts ... ImportOption ) (_ []string , retErr error ) {
113+ c := & importConfig {}
114+ for _ , o := range opts {
115+ o (c )
116+ }
97117 ctx , done , err := client .WithLease (ctx )
98118 if err != nil {
99119 return nil , err
@@ -209,6 +229,12 @@ func Import(ctx context.Context, client *containerd.Client, reader io.Reader) (_
209229 Name : ref ,
210230 Target : * desc ,
211231 }
232+ if c .unpack {
233+ img := containerd .NewImage (client , imgrec )
234+ if err := img .Unpack (ctx , c .snapshotter ); err != nil {
235+ return refs , errors .Wrapf (err , "unpack image %q" , ref )
236+ }
237+ }
212238 if _ , err := is .Create (ctx , imgrec ); err != nil {
213239 if ! errdefs .IsAlreadyExists (err ) {
214240 return refs , errors .Wrapf (err , "create image ref %+v" , imgrec )
0 commit comments