Fix ctr build
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
723a72bdf8
commit
df9c09303c
1 changed files with 33 additions and 32 deletions
|
@ -2,9 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
gocontext "context"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/docker/containerd/api/execution"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +30,12 @@ type runConfig struct {
|
||||||
var runCommand = cli.Command{
|
var runCommand = cli.Command{
|
||||||
Name: "run",
|
Name: "run",
|
||||||
Usage: "run a container",
|
Usage: "run a container",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "bundle, b",
|
||||||
|
Usage: "path to the container's bundle",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var config runConfig
|
var config runConfig
|
||||||
if _, err := toml.DecodeFile(context.Args().First(), &config); err != nil {
|
if _, err := toml.DecodeFile(context.Args().First(), &config); err != nil {
|
||||||
|
@ -35,49 +43,42 @@ var runCommand = cli.Command{
|
||||||
}
|
}
|
||||||
id := context.Args().Get(1)
|
id := context.Args().Get(1)
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return fmt.Errorf("containerd must be provided")
|
return fmt.Errorf("container id must be provided")
|
||||||
}
|
}
|
||||||
client, err := getClient(context)
|
executionService, err := getExecutionService(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
clone, err := client.Images.Clone(config.Image)
|
containerService, err := getContainerService(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container, err := client.Containers.Create(CreateRequest{
|
cr, err := executionService.Create(gocontext.Background(), &execution.CreateContainerRequest{
|
||||||
Id: id,
|
ID: id,
|
||||||
Mounts: clone.Mounts,
|
BundlePath: context.String("bundle"),
|
||||||
Process: Process{
|
|
||||||
Args: config.Args,
|
|
||||||
Env: config.Env,
|
|
||||||
Cwd: config.Cwd,
|
|
||||||
Uid: config.Uid,
|
|
||||||
Gid: config.Gid,
|
|
||||||
Tty: config.Tty,
|
|
||||||
Stdin: os.Stdin.Name(),
|
|
||||||
Stdout: os.Stdout.Name(),
|
|
||||||
Stderr: os.Stderr.Name(),
|
|
||||||
},
|
|
||||||
Owner: "ctr",
|
|
||||||
})
|
})
|
||||||
defer client.Containers.Delete(container)
|
|
||||||
if err := client.Networks.Attach(config.Network, container); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := client.Containers.Start(container); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
go forwarSignals(client.Containers.SignalProcess, container.Process)
|
|
||||||
events, err := client.Containers.Events(container.Id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for event := range events {
|
if _, err := containerService.Start(gocontext.Background(), &execution.StartContainerRequest{
|
||||||
if event.Type == "exit" {
|
ID: cr.Container.ID,
|
||||||
os.Exit(event.Status)
|
}); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
// wait for it to die
|
||||||
|
if _, err := executionService.Delete(gocontext.Background(), &execution.DeleteContainerRequest{
|
||||||
|
ID: cr.Container.ID,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getExecutionService(context *cli.Context) (execution.ExecutionServiceClient, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getContainerService(context *cli.Context) (execution.ContainerServiceClient, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue