Use unix-socket as communication channel
Signed-off-by: Alexander Morozov <lk4d4@docker.com> Signed-off-by: Michael Crosby <crosbymichael@gmail.com> Conflicts: ctr/container.go
This commit is contained in:
parent
e16dfc36a5
commit
ca4191ce41
6 changed files with 47 additions and 21 deletions
|
@ -4,10 +4,12 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/containerd/api/grpc/types"
|
||||
|
@ -18,8 +20,14 @@ import (
|
|||
)
|
||||
|
||||
// TODO: parse flags and pass opts
|
||||
func getClient() types.APIClient {
|
||||
conn, err := grpc.Dial("localhost:8888", grpc.WithInsecure())
|
||||
func getClient(ctx *cli.Context) types.APIClient {
|
||||
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
dialOpts = append(dialOpts,
|
||||
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
|
||||
return net.DialTimeout("unix", addr, timeout)
|
||||
},
|
||||
))
|
||||
conn, err := grpc.Dial(ctx.GlobalString("address"), dialOpts...)
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
|
@ -46,7 +54,7 @@ var ListCommand = cli.Command{
|
|||
}
|
||||
|
||||
func listContainers(context *cli.Context) {
|
||||
c := getClient()
|
||||
c := getClient(context)
|
||||
resp, err := c.State(netcontext.Background(), &types.StateRequest{})
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
|
@ -90,7 +98,7 @@ var StartCommand = cli.Command{
|
|||
if id == "" {
|
||||
fatal("container id cannot be empty", 1)
|
||||
}
|
||||
c := getClient()
|
||||
c := getClient(context)
|
||||
events, err := c.Events(netcontext.Background(), &types.EventsRequest{})
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
|
@ -223,7 +231,7 @@ var KillCommand = cli.Command{
|
|||
if id == "" {
|
||||
fatal("container id cannot be empty", 1)
|
||||
}
|
||||
c := getClient()
|
||||
c := getClient(context)
|
||||
if _, err := c.Signal(netcontext.Background(), &types.SignalRequest{
|
||||
Id: id,
|
||||
Pid: uint32(context.Int("pid")),
|
||||
|
@ -276,7 +284,7 @@ var ExecCommand = cli.Command{
|
|||
Gid: uint32(context.Int("gid")),
|
||||
},
|
||||
}
|
||||
c := getClient()
|
||||
c := getClient(context)
|
||||
if _, err := c.AddProcess(netcontext.Background(), p); err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
}
|
||||
|
@ -290,7 +298,7 @@ var StatsCommand = cli.Command{
|
|||
req := &types.StatsRequest{
|
||||
Id: context.Args().First(),
|
||||
}
|
||||
c := getClient()
|
||||
c := getClient(context)
|
||||
stream, err := c.GetStats(netcontext.Background(), req)
|
||||
if err != nil {
|
||||
fatal(err.Error(), 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue