mirror of https://github.com/docker/compose.git
Move the context server into own package
It had notthing to do in the cli package
This commit is contained in:
parent
b8658b3f54
commit
cb14c05e74
|
@ -5,14 +5,12 @@ import (
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/api/context/store"
|
|
||||||
containersv1 "github.com/docker/api/protos/containers/v1"
|
containersv1 "github.com/docker/api/protos/containers/v1"
|
||||||
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
||||||
"github.com/docker/api/server"
|
"github.com/docker/api/server"
|
||||||
"github.com/docker/api/server/proxy"
|
"github.com/docker/api/server/proxy"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type serveOpts struct {
|
type serveOpts struct {
|
||||||
|
@ -47,9 +45,10 @@ func runServe(ctx context.Context, opts serveOpts) error {
|
||||||
defer listener.Close()
|
defer listener.Close()
|
||||||
|
|
||||||
p := proxy.NewContainerAPI()
|
p := proxy.NewContainerAPI()
|
||||||
|
contextsService := server.NewContexts()
|
||||||
|
|
||||||
containersv1.RegisterContainersServer(s, p)
|
containersv1.RegisterContainersServer(s, p)
|
||||||
contextsv1.RegisterContextsServer(s, &cliServer{})
|
contextsv1.RegisterContextsServer(s, contextsService)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
@ -62,23 +61,3 @@ func runServe(ctx context.Context, opts serveOpts) error {
|
||||||
// start the GRPC server to serve on the listener
|
// start the GRPC server to serve on the listener
|
||||||
return s.Serve(listener)
|
return s.Serve(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cliServer struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cs *cliServer) List(ctx context.Context, request *contextsv1.ListRequest) (*contextsv1.ListResponse, error) {
|
|
||||||
s := store.ContextStore(ctx)
|
|
||||||
contexts, err := s.List()
|
|
||||||
if err != nil {
|
|
||||||
logrus.Error(err)
|
|
||||||
return &contextsv1.ListResponse{}, err
|
|
||||||
}
|
|
||||||
result := &contextsv1.ListResponse{}
|
|
||||||
for _, c := range contexts {
|
|
||||||
result.Contexts = append(result.Contexts, &contextsv1.Context{
|
|
||||||
Name: c.Name,
|
|
||||||
ContextType: c.Type,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/docker/api/context/store"
|
||||||
|
contextsv1 "github.com/docker/api/protos/contexts/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type cliServer struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContexts returns a contexts server
|
||||||
|
func NewContexts() contextsv1.ContextsServer {
|
||||||
|
return &cliServer{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *cliServer) List(ctx context.Context, request *contextsv1.ListRequest) (*contextsv1.ListResponse, error) {
|
||||||
|
s := store.ContextStore(ctx)
|
||||||
|
contexts, err := s.List()
|
||||||
|
if err != nil {
|
||||||
|
return &contextsv1.ListResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &contextsv1.ListResponse{}
|
||||||
|
|
||||||
|
for _, c := range contexts {
|
||||||
|
result.Contexts = append(result.Contexts, &contextsv1.Context{
|
||||||
|
Name: c.Name,
|
||||||
|
ContextType: c.Type,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
Loading…
Reference in New Issue