@@ -48,6 +48,14 @@ type Layer struct {
4848// Layers are applied in order they are given, making the first layer the
4949// bottom-most layer in the layer chain.
5050func ApplyLayers (ctx context.Context , layers []Layer , sn snapshots.Snapshotter , a diff.Applier ) (digest.Digest , error ) {
51+ return ApplyLayersWithOpts (ctx , layers , sn , a , nil )
52+ }
53+
54+ // ApplyLayersWithOpts applies all the layers using the given snapshotter, applier, and apply opts.
55+ // The returned result is a chain id digest representing all the applied layers.
56+ // Layers are applied in order they are given, making the first layer the
57+ // bottom-most layer in the layer chain.
58+ func ApplyLayersWithOpts (ctx context.Context , layers []Layer , sn snapshots.Snapshotter , a diff.Applier , applyOpts []diff.ApplyOpt ) (digest.Digest , error ) {
5159 chain := make ([]digest.Digest , len (layers ))
5260 for i , layer := range layers {
5361 chain [i ] = layer .Diff .Digest
@@ -63,7 +71,7 @@ func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter,
6371 return "" , errors .Wrapf (err , "failed to stat snapshot %s" , chainID )
6472 }
6573
66- if err := applyLayers (ctx , layers , chain , sn , a ); err != nil && ! errdefs .IsAlreadyExists (err ) {
74+ if err := applyLayers (ctx , layers , chain , sn , a , nil , applyOpts ); err != nil && ! errdefs .IsAlreadyExists (err ) {
6775 return "" , err
6876 }
6977 }
@@ -75,6 +83,13 @@ func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter,
7583// using the provided snapshotter and applier. If the layer was unpacked true
7684// is returned, if the layer already exists false is returned.
7785func ApplyLayer (ctx context.Context , layer Layer , chain []digest.Digest , sn snapshots.Snapshotter , a diff.Applier , opts ... snapshots.Opt ) (bool , error ) {
86+ return ApplyLayerWithOpts (ctx , layer , chain , sn , a , opts , nil )
87+ }
88+
89+ // ApplyLayerWithOpts applies a single layer on top of the given provided layer chain,
90+ // using the provided snapshotter, applier, and apply opts. If the layer was unpacked true
91+ // is returned, if the layer already exists false is returned.
92+ func ApplyLayerWithOpts (ctx context.Context , layer Layer , chain []digest.Digest , sn snapshots.Snapshotter , a diff.Applier , opts []snapshots.Opt , applyOpts []diff.ApplyOpt ) (bool , error ) {
7893 var (
7994 chainID = identity .ChainID (append (chain , layer .Diff .Digest )).String ()
8095 applied bool
@@ -84,7 +99,7 @@ func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snap
8499 return false , errors .Wrapf (err , "failed to stat snapshot %s" , chainID )
85100 }
86101
87- if err := applyLayers (ctx , []Layer {layer }, append (chain , layer .Diff .Digest ), sn , a , opts ... ); err != nil {
102+ if err := applyLayers (ctx , []Layer {layer }, append (chain , layer .Diff .Digest ), sn , a , opts , applyOpts ); err != nil {
88103 if ! errdefs .IsAlreadyExists (err ) {
89104 return false , err
90105 }
@@ -93,9 +108,10 @@ func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snap
93108 }
94109 }
95110 return applied , nil
111+
96112}
97113
98- func applyLayers (ctx context.Context , layers []Layer , chain []digest.Digest , sn snapshots.Snapshotter , a diff.Applier , opts ... snapshots.Opt ) error {
114+ func applyLayers (ctx context.Context , layers []Layer , chain []digest.Digest , sn snapshots.Snapshotter , a diff.Applier , opts [] snapshots.Opt , applyOpts []diff. ApplyOpt ) error {
99115 var (
100116 parent = identity .ChainID (chain [:len (chain )- 1 ])
101117 chainID = identity .ChainID (chain )
@@ -113,7 +129,7 @@ func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn
113129 mounts , err = sn .Prepare (ctx , key , parent .String (), opts ... )
114130 if err != nil {
115131 if errdefs .IsNotFound (err ) && len (layers ) > 1 {
116- if err := applyLayers (ctx , layers [:len (layers )- 1 ], chain [:len (chain )- 1 ], sn , a ); err != nil {
132+ if err := applyLayers (ctx , layers [:len (layers )- 1 ], chain [:len (chain )- 1 ], sn , a , nil , applyOpts ); err != nil {
117133 if ! errdefs .IsAlreadyExists (err ) {
118134 return err
119135 }
@@ -144,7 +160,7 @@ func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn
144160 }
145161 }()
146162
147- diff , err = a .Apply (ctx , layer .Blob , mounts )
163+ diff , err = a .Apply (ctx , layer .Blob , mounts , applyOpts ... )
148164 if err != nil {
149165 err = errors .Wrapf (err , "failed to extract layer %s" , layer .Diff .Digest )
150166 return err
0 commit comments