@@ -31,57 +31,80 @@ import (
3131// NewContainer creates a new container
3232func NewContainer (ctx gocontext.Context , client * containerd.Client , context * cli.Context ) (containerd.Container , error ) {
3333 var (
34- ref = context .Args ().First ()
35- id = context .Args ().Get (1 )
36- args = context .Args ()[2 :]
37- )
38-
39- image , err := client .GetImage (ctx , ref )
40- if err != nil {
41- return nil , err
42- }
43-
44- var (
34+ id string
4535 opts []oci.SpecOpts
4636 cOpts []containerd.NewContainerOpts
4737 spec containerd.NewContainerOpts
38+
39+ config = context .IsSet ("config" )
4840 )
4941
50- if context .IsSet ("config" ) {
42+ if config {
43+ id = context .Args ().First ()
5144 opts = append (opts , oci .WithSpecFromFile (context .String ("config" )))
5245 } else {
53- opts = append (opts , oci .WithDefaultSpec ())
54- }
55-
56- opts = append (opts , oci .WithImageConfig (image ))
57- opts = append (opts , oci .WithEnv (context .StringSlice ("env" )))
58- opts = append (opts , withMounts (context ))
59- if context .Bool ("tty" ) {
60- opts = append (opts , oci .WithTTY )
46+ var (
47+ ref = context .Args ().First ()
48+ args = context .Args ()[2 :]
49+ )
50+
51+ id = context .Args ().Get (1 )
52+ snapshotter := context .String ("snapshotter" )
53+ if snapshotter == "windows-lcow" {
54+ opts = append (opts , oci .WithDefaultSpecForPlatform ("linux/amd64" ))
55+ // Clear the rootfs section.
56+ opts = append (opts , oci .WithRootFSPath ("" ))
57+ } else {
58+ opts = append (opts , oci .WithDefaultSpec ())
59+ }
60+ opts = append (opts , oci .WithEnv (context .StringSlice ("env" )))
61+ opts = append (opts , withMounts (context ))
6162
62- con := console .Current ()
63- size , err := con .Size ()
63+ image , err := client .GetImage (ctx , ref )
6464 if err != nil {
65- logrus . WithError ( err ). Error ( "console size" )
65+ return nil , err
6666 }
67- opts = append (opts , oci .WithTTYSize (int (size .Width ), int (size .Height )))
68- }
67+ unpacked , err := image .IsUnpacked (ctx , snapshotter )
68+ if err != nil {
69+ return nil , err
70+ }
71+ if ! unpacked {
72+ if err := image .Unpack (ctx , snapshotter ); err != nil {
73+ return nil , err
74+ }
75+ }
76+ opts = append (opts , oci .WithImageConfig (image ))
77+ cOpts = append (cOpts , containerd .WithImage (image ))
78+ cOpts = append (cOpts , containerd .WithSnapshotter (snapshotter ))
79+ cOpts = append (cOpts , containerd .WithNewSnapshot (id , image ))
6980
70- if len (args ) > 0 {
71- opts = append (opts , oci .WithProcessArgs (args ... ))
72- }
73- if cwd := context .String ("cwd" ); cwd != "" {
74- opts = append (opts , oci .WithProcessCwd (cwd ))
81+ if len (args ) > 0 {
82+ opts = append (opts , oci .WithProcessArgs (args ... ))
83+ }
84+ if cwd := context .String ("cwd" ); cwd != "" {
85+ opts = append (opts , oci .WithProcessCwd (cwd ))
86+ }
87+ if context .Bool ("tty" ) {
88+ opts = append (opts , oci .WithTTY )
89+
90+ con := console .Current ()
91+ size , err := con .Size ()
92+ if err != nil {
93+ logrus .WithError (err ).Error ("console size" )
94+ }
95+ opts = append (opts , oci .WithTTYSize (int (size .Width ), int (size .Height )))
96+ }
97+ if context .Bool ("isolated" ) {
98+ opts = append (opts , oci .WithWindowsHyperV )
99+ }
75100 }
76101
102+ cOpts = append (cOpts , containerd .WithContainerLabels (commands .LabelArgs (context .StringSlice ("label" ))))
103+ cOpts = append (cOpts , containerd .WithRuntime (context .String ("runtime" ), nil ))
104+
77105 var s specs.Spec
78106 spec = containerd .WithSpec (& s , opts ... )
79107
80- cOpts = append (cOpts , containerd .WithContainerLabels (commands .LabelArgs (context .StringSlice ("label" ))))
81- cOpts = append (cOpts , containerd .WithImage (image ))
82- cOpts = append (cOpts , containerd .WithSnapshotter (context .String ("snapshotter" )))
83- cOpts = append (cOpts , containerd .WithNewSnapshot (id , image ))
84- cOpts = append (cOpts , containerd .WithRuntime (context .String ("runtime" ), nil ))
85108 cOpts = append (cOpts , spec )
86109
87110 return client .NewContainer (ctx , id , cOpts ... )
0 commit comments