Pass apply opts through rootfs/* code
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
e1489f93c3
commit
26b90619e2
@ -48,6 +48,14 @@ type Layer struct {
|
|||||||
// Layers are applied in order they are given, making the first layer the
|
// Layers are applied in order they are given, making the first layer the
|
||||||
// bottom-most layer in the layer chain.
|
// bottom-most layer in the layer chain.
|
||||||
func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter, a diff.Applier) (digest.Digest, error) {
|
func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter, a diff.Applier) (digest.Digest, error) {
|
||||||
|
return ApplyLayersWithOpts(ctx, layers, sn, a, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyLayersWithOpts applies all the layers using the given snapshotter, applier, and apply opts.
|
||||||
|
// The returned result is a chain id digest representing all the applied layers.
|
||||||
|
// Layers are applied in order they are given, making the first layer the
|
||||||
|
// bottom-most layer in the layer chain.
|
||||||
|
func ApplyLayersWithOpts(ctx context.Context, layers []Layer, sn snapshots.Snapshotter, a diff.Applier, applyOpts []diff.ApplyOpt) (digest.Digest, error) {
|
||||||
chain := make([]digest.Digest, len(layers))
|
chain := make([]digest.Digest, len(layers))
|
||||||
for i, layer := range layers {
|
for i, layer := range layers {
|
||||||
chain[i] = layer.Diff.Digest
|
chain[i] = layer.Diff.Digest
|
||||||
@ -63,7 +71,7 @@ func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter,
|
|||||||
return "", errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
return "", errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := applyLayers(ctx, layers, chain, sn, a); err != nil && !errdefs.IsAlreadyExists(err) {
|
if err := applyLayers(ctx, layers, chain, sn, a, nil, applyOpts); err != nil && !errdefs.IsAlreadyExists(err) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,6 +83,13 @@ func ApplyLayers(ctx context.Context, layers []Layer, sn snapshots.Snapshotter,
|
|||||||
// using the provided snapshotter and applier. If the layer was unpacked true
|
// using the provided snapshotter and applier. If the layer was unpacked true
|
||||||
// is returned, if the layer already exists false is returned.
|
// is returned, if the layer already exists false is returned.
|
||||||
func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts ...snapshots.Opt) (bool, error) {
|
func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts ...snapshots.Opt) (bool, error) {
|
||||||
|
return ApplyLayerWithOpts(ctx, layer, chain, sn, a, opts, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyLayerWithOpts applies a single layer on top of the given provided layer chain,
|
||||||
|
// using the provided snapshotter, applier, and apply opts. If the layer was unpacked true
|
||||||
|
// is returned, if the layer already exists false is returned.
|
||||||
|
func ApplyLayerWithOpts(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts []snapshots.Opt, applyOpts []diff.ApplyOpt) (bool, error) {
|
||||||
var (
|
var (
|
||||||
chainID = identity.ChainID(append(chain, layer.Diff.Digest)).String()
|
chainID = identity.ChainID(append(chain, layer.Diff.Digest)).String()
|
||||||
applied bool
|
applied bool
|
||||||
@ -84,7 +99,7 @@ func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snap
|
|||||||
return false, errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
return false, errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := applyLayers(ctx, []Layer{layer}, append(chain, layer.Diff.Digest), sn, a, opts...); err != nil {
|
if err := applyLayers(ctx, []Layer{layer}, append(chain, layer.Diff.Digest), sn, a, opts, applyOpts); err != nil {
|
||||||
if !errdefs.IsAlreadyExists(err) {
|
if !errdefs.IsAlreadyExists(err) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -93,9 +108,10 @@ func ApplyLayer(ctx context.Context, layer Layer, chain []digest.Digest, sn snap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return applied, nil
|
return applied, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts ...snapshots.Opt) error {
|
func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts []snapshots.Opt, applyOpts []diff.ApplyOpt) error {
|
||||||
var (
|
var (
|
||||||
parent = identity.ChainID(chain[:len(chain)-1])
|
parent = identity.ChainID(chain[:len(chain)-1])
|
||||||
chainID = identity.ChainID(chain)
|
chainID = identity.ChainID(chain)
|
||||||
@ -113,7 +129,7 @@ func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn
|
|||||||
mounts, err = sn.Prepare(ctx, key, parent.String(), opts...)
|
mounts, err = sn.Prepare(ctx, key, parent.String(), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errdefs.IsNotFound(err) && len(layers) > 1 {
|
if errdefs.IsNotFound(err) && len(layers) > 1 {
|
||||||
if err := applyLayers(ctx, layers[:len(layers)-1], chain[:len(chain)-1], sn, a); err != nil {
|
if err := applyLayers(ctx, layers[:len(layers)-1], chain[:len(chain)-1], sn, a, nil, applyOpts); err != nil {
|
||||||
if !errdefs.IsAlreadyExists(err) {
|
if !errdefs.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -144,7 +160,7 @@ func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
diff, err = a.Apply(ctx, layer.Blob, mounts)
|
diff, err = a.Apply(ctx, layer.Blob, mounts, applyOpts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrapf(err, "failed to extract layer %s", layer.Diff.Digest)
|
err = errors.Wrapf(err, "failed to extract layer %s", layer.Diff.Digest)
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user