1 //go:build windows 2 3 package main 4 5 import ( 6 "github.com/Microsoft/hcsshim/internal/appargs" 7 "github.com/urfave/cli" 8 ) 9 10 var createRunFlags = []cli.Flag{ 11 cli.StringFlag{ 12 Name: "bundle, b", 13 Value: "", 14 Usage: `path to the root of the bundle directory, defaults to the current directory`, 15 }, 16 cli.StringFlag{ 17 Name: "pid-file", 18 Value: "", 19 Usage: "specify the file to write the process id to", 20 }, 21 cli.StringFlag{ 22 Name: "shim-log", 23 Value: "", 24 Usage: `path to the log file or named pipe (e.g. \\.\pipe\ProtectedPrefix\Administrators\runhcs-<container-id>-shim-log) for the launched shim process`, 25 }, 26 cli.StringFlag{ 27 Name: "vm-log", 28 Value: "", 29 Usage: `path to the log file or named pipe (e.g. \\.\pipe\ProtectedPrefix\Administrators\runhcs-<container-id>-vm-log) for the launched VM shim process`, 30 }, 31 cli.StringFlag{ 32 Name: "vm-console", 33 Value: "", 34 Usage: `path to the pipe for the VM's console (e.g. \\.\pipe\debugpipe)`, 35 }, 36 cli.StringFlag{ 37 Name: "host", 38 Value: "", 39 Usage: "host container whose VM this container should run in", 40 }, 41 } 42 43 var createCommand = cli.Command{ 44 Name: "create", 45 Usage: "create a container", 46 ArgsUsage: `<container-id> 47 48 Where "<container-id>" is your name for the instance of the container that you 49 are starting. The name you provide for the container instance must be unique on 50 your host.`, 51 Description: `The create command creates an instance of a container for a bundle. The bundle 52 is a directory with a specification file named "` + specConfig + `" and a root 53 filesystem. 54 55 The specification file includes an args parameter. The args parameter is used 56 to specify command(s) that get run when the container is started. To change the 57 command(s) that get executed on start, edit the args parameter of the spec. See 58 "runc spec --help" for more explanation.`, 59 Flags: createRunFlags, 60 Before: appargs.Validate(argID), 61 Action: func(context *cli.Context) error { 62 cfg, err := containerConfigFromContext(context) 63 if err != nil { 64 return err 65 } 66 _, err = createContainer(cfg) 67 if err != nil { 68 return err 69 } 70 return nil 71 }, 72 } 73 74 func containerConfigFromContext(context *cli.Context) (*containerConfig, error) { 75 id := context.Args().First() 76 pidFile, err := absPathOrEmpty(context.String("pid-file")) 77 if err != nil { 78 return nil, err 79 } 80 shimLog, err := absPathOrEmpty(context.String("shim-log")) 81 if err != nil { 82 return nil, err 83 } 84 vmLog, err := absPathOrEmpty(context.String("vm-log")) 85 if err != nil { 86 return nil, err 87 } 88 spec, err := setupSpec(context) 89 if err != nil { 90 return nil, err 91 } 92 return &containerConfig{ 93 ID: id, 94 Owner: context.GlobalString("owner"), 95 PidFile: pidFile, 96 ShimLogFile: shimLog, 97 VMLogFile: vmLog, 98 VMConsolePipe: context.String("vm-console"), 99 Spec: spec, 100 HostID: context.String("host"), 101 }, nil 102 } 103