mirror of
https://github.com/docker/compose.git
synced 2025-07-22 21:24:38 +02:00
Remove useless client grpc stuff
This commit is contained in:
parent
f4bde8cb89
commit
b2606b91f2
@ -31,7 +31,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"github.com/docker/api/client"
|
"github.com/docker/api/client"
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
@ -45,16 +44,12 @@ var ExampleCommand = cobra.Command{
|
|||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
|
|
||||||
// get our current context
|
c, err := client.New(ctx)
|
||||||
ctx = current(ctx)
|
|
||||||
|
|
||||||
client, err := connect(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "cannot connect to backend")
|
return errors.Wrap(err, "cannot connect to backend")
|
||||||
}
|
}
|
||||||
defer client.Close()
|
|
||||||
|
|
||||||
info, err := client.BackendInformation(ctx, &empty.Empty{})
|
info, err := c.BackendInformation(ctx, &empty.Empty{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "fetch backend information")
|
return errors.Wrap(err, "fetch backend information")
|
||||||
}
|
}
|
||||||
@ -64,37 +59,6 @@ var ExampleCommand = cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// mock information for getting context
|
|
||||||
// factor out this into a context store package
|
|
||||||
func current(ctx context.Context) context.Context {
|
|
||||||
// test backend address
|
|
||||||
return context.WithValue(ctx, backendAddressKey{}, "/tmp/backend.sock")
|
|
||||||
}
|
|
||||||
|
|
||||||
func connect(ctx context.Context) (*client.Client, error) {
|
|
||||||
address, err := BackendAddress(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "no backend address")
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := client.New(ctx)
|
|
||||||
if err != nil {
|
|
||||||
if err != context.DeadlineExceeded {
|
|
||||||
return nil, errors.Wrap(err, "connect to backend")
|
|
||||||
}
|
|
||||||
// the backend is not running so start it
|
|
||||||
cmd := exec.Command("backend-example", "--address", address)
|
|
||||||
go cmd.Wait()
|
|
||||||
|
|
||||||
if err := cmd.Start(); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "start backend")
|
|
||||||
}
|
|
||||||
cl, e := client.New(ctx)
|
|
||||||
return cl, e
|
|
||||||
}
|
|
||||||
return c, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type backendAddressKey struct{}
|
type backendAddressKey struct{}
|
||||||
|
|
||||||
func BackendAddress(ctx context.Context) (string, error) {
|
func BackendAddress(ctx context.Context) (string, error) {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
client2 "github.com/docker/api/client"
|
"github.com/docker/api/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -16,16 +16,12 @@ var PsCommand = cobra.Command{
|
|||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
|
|
||||||
// get our current context
|
c, err := client.New(ctx)
|
||||||
ctx = current(ctx)
|
|
||||||
|
|
||||||
client, err := client2.New(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "cannot connect to backend")
|
return errors.Wrap(err, "cannot connect to backend")
|
||||||
}
|
}
|
||||||
defer client.Close()
|
|
||||||
|
|
||||||
containers, err := client.ContainerService(ctx).List(ctx)
|
containers, err := c.ContainerService(ctx).List(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "fetch containers")
|
return errors.Wrap(err, "fetch containers")
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
"github.com/docker/api/backend"
|
"github.com/docker/api/backend"
|
||||||
v1 "github.com/docker/api/backend/v1"
|
v1 "github.com/docker/api/backend/v1"
|
||||||
"github.com/docker/api/containers"
|
"github.com/docker/api/containers"
|
||||||
@ -66,7 +64,6 @@ func New(ctx context.Context) (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
conn *grpc.ClientConn
|
|
||||||
v1.BackendClient
|
v1.BackendClient
|
||||||
backendType string
|
backendType string
|
||||||
cc containers.ContainerService
|
cc containers.ContainerService
|
||||||
@ -75,10 +72,3 @@ type Client struct {
|
|||||||
func (c *Client) ContainerService(ctx context.Context) containers.ContainerService {
|
func (c *Client) ContainerService(ctx context.Context) containers.ContainerService {
|
||||||
return c.cc
|
return c.cc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Close() error {
|
|
||||||
if c.conn != nil {
|
|
||||||
return c.conn.Close()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user