Update windows SpecOpts in tests
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
f436f4c828
commit
f66f0fb7a0
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
|
"github.com/containerd/containerd/containers"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
@ -25,7 +26,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func withLayers(context *cli.Context) containerd.SpecOpts {
|
func withLayers(context *cli.Context) containerd.SpecOpts {
|
||||||
return func(s *specs.Spec) error {
|
return func(ctx gocontext.Context, client *containerd.Client, c *containers.Container, s *specs.Spec) error {
|
||||||
l := context.StringSlice("layer")
|
l := context.StringSlice("layer")
|
||||||
if l == nil {
|
if l == nil {
|
||||||
return errors.Wrap(errdefs.ErrInvalidArgument, "base layers must be specified with `--layer`")
|
return errors.Wrap(errdefs.ErrInvalidArgument, "base layers must be specified with `--layer`")
|
||||||
@ -65,7 +66,7 @@ func handleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol
|
|||||||
|
|
||||||
func withTTY(terminal bool) containerd.SpecOpts {
|
func withTTY(terminal bool) containerd.SpecOpts {
|
||||||
if !terminal {
|
if !terminal {
|
||||||
return func(s *specs.Spec) error {
|
return func(ctx gocontext.Context, client *containerd.Client, c *containers.Container, s *specs.Spec) error {
|
||||||
s.Process.Terminal = false
|
s.Process.Terminal = false
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -85,8 +86,6 @@ func setHostNetworking() containerd.SpecOpts {
|
|||||||
|
|
||||||
func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
|
func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
|
||||||
|
|
||||||
// ref = context.Args().First()
|
// ref = context.Args().First()
|
||||||
id = context.Args().Get(1)
|
id = context.Args().Get(1)
|
||||||
args = context.Args()[2:]
|
args = context.Args()[2:]
|
||||||
@ -109,13 +108,8 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
|||||||
opts = append(opts, containerd.WithProcessArgs(args...))
|
opts = append(opts, containerd.WithProcessArgs(args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
spec, err := containerd.GenerateSpec(opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return client.NewContainer(ctx, id,
|
return client.NewContainer(ctx, id,
|
||||||
containerd.WithNewSpec(spec),
|
containerd.WithNewSpec(opts...),
|
||||||
containerd.WithContainerLabels(labels),
|
containerd.WithContainerLabels(labels),
|
||||||
containerd.WithRuntime(context.String("runtime")),
|
containerd.WithRuntime(context.String("runtime")),
|
||||||
// TODO(mlaventure): containerd.WithImage(image),
|
// TODO(mlaventure): containerd.WithImage(image),
|
||||||
|
@ -12,19 +12,8 @@ import (
|
|||||||
|
|
||||||
const newLine = "\r\n"
|
const newLine = "\r\n"
|
||||||
|
|
||||||
func generateSpec(ctx context.Context, client *Client, opts ...SpecOpts) (*specs.Spec, error) {
|
|
||||||
spec, err := GenerateSpec(ctx, client, opts...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
spec.Windows.LayerFolders = dockerLayerFolders
|
|
||||||
|
|
||||||
return spec, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func withExitStatus(es int) SpecOpts {
|
func withExitStatus(es int) SpecOpts {
|
||||||
return func(_ context.Context, _ *Client, s *specs.Spec) error {
|
return func(_ context.Context, _ *Client, _ *containers.Container, s *specs.Spec) error {
|
||||||
s.Process.Args = []string{"powershell", "-noprofile", "exit", strconv.Itoa(es)}
|
s.Process.Args = []string{"powershell", "-noprofile", "exit", strconv.Itoa(es)}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -51,8 +40,10 @@ func withExecArgs(s *specs.Process, args ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func withImageConfig(i Image) SpecOpts {
|
func withImageConfig(i Image) SpecOpts {
|
||||||
// TODO: when windows has a snapshotter remove the withImageConfig helper
|
return func(_ context.Context, _ *Client, _ *containers.Container, s *specs.Spec) error {
|
||||||
return withNoop
|
s.Windows.LayerFolders = dockerLayerFolders
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withNewSnapshot(id string, i Image) NewContainerOpts {
|
func withNewSnapshot(id string, i Image) NewContainerOpts {
|
||||||
@ -72,6 +63,6 @@ func withRemappedSnapshot(id string, i Image, u, g uint32) NewContainerOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func withNoop(_ context.Context, _ *Client, _ *specs.Spec) error {
|
func withNoop(_ context.Context, _ *Client, _ *containers.Container, _ *specs.Spec) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func WithImageConfig(i Image) SpecOpts {
|
func WithImageConfig(i Image) SpecOpts {
|
||||||
return func(ctx context.Context, client *Client, s *specs.Spec) error {
|
return func(ctx context.Context, client *Client, _ *containers.Container, s *specs.Spec) error {
|
||||||
var (
|
var (
|
||||||
image = i.(*image)
|
image = i.(*image)
|
||||||
store = client.ContentStore()
|
store = client.ContentStore()
|
||||||
@ -52,7 +52,7 @@ func WithImageConfig(i Image) SpecOpts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WithTTY(width, height int) SpecOpts {
|
func WithTTY(width, height int) SpecOpts {
|
||||||
return func(_ context.Context, _ *Client, s *specs.Spec) error {
|
return func(_ context.Context, _ *Client, _ *containers.Container, s *specs.Spec) error {
|
||||||
s.Process.Terminal = true
|
s.Process.Terminal = true
|
||||||
s.Process.ConsoleSize.Width = uint(width)
|
s.Process.ConsoleSize.Width = uint(width)
|
||||||
s.Process.ConsoleSize.Height = uint(height)
|
s.Process.ConsoleSize.Height = uint(height)
|
||||||
@ -60,7 +60,27 @@ func WithTTY(width, height int) SpecOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithNewSpec(spec *specs.Spec) NewContainerOpts {
|
func WithNewSpec(opts ...SpecOpts) NewContainerOpts {
|
||||||
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
|
s, err := createDefaultSpec()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, o := range opts {
|
||||||
|
if err := o(ctx, client, c, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
any, err := typeurl.MarshalAny(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Spec = any
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithSpec(spec *specs.Spec) NewContainerOpts {
|
||||||
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
return func(ctx context.Context, client *Client, c *containers.Container) error {
|
||||||
any, err := typeurl.MarshalAny(spec)
|
any, err := typeurl.MarshalAny(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user