2016-11-30 00:52:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-06 00:36:15 +00:00
|
|
|
|
|
|
|
gocontext "context"
|
2016-11-30 00:52:04 +00:00
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
2016-12-06 00:36:15 +00:00
|
|
|
"github.com/docker/containerd/api/execution"
|
2016-11-30 00:52:04 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
type runConfig struct {
|
|
|
|
Image string `toml:"image"`
|
|
|
|
Process struct {
|
|
|
|
Args []string `toml:"args"`
|
|
|
|
Env []string `toml:"env"`
|
|
|
|
Cwd string `toml:"cwd"`
|
|
|
|
Uid int `toml:"uid"`
|
|
|
|
Gid int `toml:"gid"`
|
|
|
|
Tty bool `toml:"tty"`
|
|
|
|
} `toml:"process"`
|
|
|
|
Network struct {
|
|
|
|
Type string `toml:"type"`
|
|
|
|
IP string `toml:"ip"`
|
|
|
|
Gateway string `toml:"gateway"`
|
|
|
|
} `toml:"network"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var runCommand = cli.Command{
|
|
|
|
Name: "run",
|
|
|
|
Usage: "run a container",
|
2016-12-06 00:36:15 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "bundle, b",
|
|
|
|
Usage: "path to the container's bundle",
|
|
|
|
},
|
|
|
|
},
|
2016-11-30 00:52:04 +00:00
|
|
|
Action: func(context *cli.Context) error {
|
|
|
|
var config runConfig
|
|
|
|
if _, err := toml.DecodeFile(context.Args().First(), &config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
id := context.Args().Get(1)
|
|
|
|
if id == "" {
|
2016-12-06 00:36:15 +00:00
|
|
|
return fmt.Errorf("container id must be provided")
|
2016-11-30 00:52:04 +00:00
|
|
|
}
|
2016-12-06 00:36:15 +00:00
|
|
|
executionService, err := getExecutionService(context)
|
2016-11-30 00:52:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-06 00:36:15 +00:00
|
|
|
containerService, err := getContainerService(context)
|
2016-11-30 00:52:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-06 00:36:15 +00:00
|
|
|
cr, err := executionService.Create(gocontext.Background(), &execution.CreateContainerRequest{
|
|
|
|
ID: id,
|
|
|
|
BundlePath: context.String("bundle"),
|
2016-11-30 00:52:04 +00:00
|
|
|
})
|
2016-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
2016-11-30 00:52:04 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-12-06 00:36:15 +00:00
|
|
|
if _, err := containerService.Start(gocontext.Background(), &execution.StartContainerRequest{
|
|
|
|
ID: cr.Container.ID,
|
|
|
|
}); err != nil {
|
2016-11-30 00:52:04 +00:00
|
|
|
return err
|
|
|
|
}
|
2016-12-06 00:36:15 +00:00
|
|
|
// wait for it to die
|
|
|
|
if _, err := executionService.Delete(gocontext.Background(), &execution.DeleteContainerRequest{
|
|
|
|
ID: cr.Container.ID,
|
|
|
|
}); err != nil {
|
2016-11-30 00:52:04 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2016-12-06 00:36:15 +00:00
|
|
|
|
|
|
|
func getExecutionService(context *cli.Context) (execution.ExecutionServiceClient, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getContainerService(context *cli.Context) (execution.ContainerServiceClient, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|