Add unpack opts
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
26b90619e2
commit
3fded74bc7
7
diff.go
7
diff.go
@ -48,13 +48,14 @@ type diffRemote struct {
|
|||||||
func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (ocispec.Descriptor, error) {
|
func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts []mount.Mount, opts ...diff.ApplyOpt) (ocispec.Descriptor, error) {
|
||||||
var config diff.ApplyConfig
|
var config diff.ApplyConfig
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
if err := opt(&config); err != nil {
|
if err := opt(ctx, desc, &config); err != nil {
|
||||||
return ocispec.Descriptor{}, err
|
return ocispec.Descriptor{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req := &diffapi.ApplyRequest{
|
req := &diffapi.ApplyRequest{
|
||||||
Diff: fromDescriptor(desc),
|
Diff: fromDescriptor(desc),
|
||||||
Mounts: fromMounts(mounts),
|
Mounts: fromMounts(mounts),
|
||||||
|
Payloads: config.ProcessorPayloads,
|
||||||
}
|
}
|
||||||
resp, err := r.client.Apply(ctx, req)
|
resp, err := r.client.Apply(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,7 +65,7 @@ func (s *fsApplier) Apply(ctx context.Context, desc ocispec.Descriptor, mounts [
|
|||||||
|
|
||||||
var config diff.ApplyConfig
|
var config diff.ApplyConfig
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&config); err != nil {
|
if err := o(ctx, desc, &config); err != nil {
|
||||||
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
|
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ type ApplyConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ApplyOpt is used to configure an Apply operation
|
// ApplyOpt is used to configure an Apply operation
|
||||||
type ApplyOpt func(*ApplyConfig) error
|
type ApplyOpt func(context.Context, ocispec.Descriptor, *ApplyConfig) error
|
||||||
|
|
||||||
// Applier allows applying diffs between mounts
|
// Applier allows applying diffs between mounts
|
||||||
type Applier interface {
|
type Applier interface {
|
||||||
@ -100,7 +100,7 @@ func WithLabels(labels map[string]string) Opt {
|
|||||||
|
|
||||||
// WithPayloads sets the apply processor payloads to the config
|
// WithPayloads sets the apply processor payloads to the config
|
||||||
func WithPayloads(payloads map[string]*types.Any) ApplyOpt {
|
func WithPayloads(payloads map[string]*types.Any) ApplyOpt {
|
||||||
return func(c *ApplyConfig) error {
|
return func(_ context.Context, _ ocispec.Descriptor, c *ApplyConfig) error {
|
||||||
c.ProcessorPayloads = payloads
|
c.ProcessorPayloads = payloads
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func (s windowsLcowDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mou
|
|||||||
|
|
||||||
var config diff.ApplyConfig
|
var config diff.ApplyConfig
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&config); err != nil {
|
if err := o(ctx, desc, &config); err != nil {
|
||||||
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
|
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func (s windowsDiff) Apply(ctx context.Context, desc ocispec.Descriptor, mounts
|
|||||||
|
|
||||||
var config diff.ApplyConfig
|
var config diff.ApplyConfig
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&config); err != nil {
|
if err := o(ctx, desc, &config); err != nil {
|
||||||
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
|
return emptyDesc, errors.Wrap(err, "failed to apply config opt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
image.go
26
image.go
@ -21,10 +21,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
|
"github.com/containerd/containerd/diff"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/containerd/containerd/rootfs"
|
"github.com/containerd/containerd/rootfs"
|
||||||
|
"github.com/containerd/containerd/snapshots"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/opencontainers/image-spec/identity"
|
"github.com/opencontainers/image-spec/identity"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
@ -40,7 +42,7 @@ type Image interface {
|
|||||||
// Labels of the image
|
// Labels of the image
|
||||||
Labels() map[string]string
|
Labels() map[string]string
|
||||||
// Unpack unpacks the image's content into a snapshot
|
// Unpack unpacks the image's content into a snapshot
|
||||||
Unpack(context.Context, string) error
|
Unpack(context.Context, string, ...UnpackOpt) error
|
||||||
// RootFS returns the unpacked diffids that make up images rootfs.
|
// RootFS returns the unpacked diffids that make up images rootfs.
|
||||||
RootFS(ctx context.Context) ([]digest.Digest, error)
|
RootFS(ctx context.Context) ([]digest.Digest, error)
|
||||||
// Size returns the total size of the image's packed resources.
|
// 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
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
|
// UnpackConfig provides configuration for the unpack of an image
|
||||||
|
type UnpackConfig struct {
|
||||||
|
// ApplyOpts for applying a diff to a snapshotter
|
||||||
|
ApplyOpts []diff.ApplyOpt
|
||||||
|
// SnapshotOpts for configuring a snapshotter
|
||||||
|
SnapshotOpts []snapshots.Opt
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnpackOpt provides configuration for unpack
|
||||||
|
type UnpackOpt func(context.Context, *UnpackConfig) error
|
||||||
|
|
||||||
|
func (i *image) Unpack(ctx context.Context, snapshotterName string, opts ...UnpackOpt) error {
|
||||||
ctx, done, err := i.client.WithLease(ctx)
|
ctx, done, err := i.client.WithLease(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer done(ctx)
|
defer done(ctx)
|
||||||
|
|
||||||
|
var config UnpackConfig
|
||||||
|
for _, o := range opts {
|
||||||
|
if err := o(ctx, &config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
layers, err := i.getLayers(ctx, i.platform)
|
layers, err := i.getLayers(ctx, i.platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -158,7 +178,7 @@ func (i *image) Unpack(ctx context.Context, snapshotterName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, layer := range layers {
|
for _, layer := range layers {
|
||||||
unpacked, err = rootfs.ApplyLayer(ctx, layer, chain, sn, a)
|
unpacked, err = rootfs.ApplyLayerWithOpts(ctx, layer, chain, sn, a, config.SnapshotOpts, config.ApplyOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user