mirror of
https://github.com/docker/compose.git
synced 2025-07-25 14:44:29 +02:00
introduce 'ps' command
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
564c369c3e
commit
da299f59e2
@ -23,6 +23,7 @@ func ComposeCommand(dockerCli command.Cli) *cobra.Command {
|
|||||||
UpCommand(dockerCli, opts),
|
UpCommand(dockerCli, opts),
|
||||||
DownCommand(dockerCli, opts),
|
DownCommand(dockerCli, opts),
|
||||||
LogsCommand(dockerCli, opts),
|
LogsCommand(dockerCli, opts),
|
||||||
|
PsCommand(dockerCli, opts),
|
||||||
)
|
)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -87,6 +88,26 @@ func UpCommand(dockerCli command.Cli, projectOpts *compose.ProjectOptions) *cobr
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PsCommand(dockerCli command.Cli, projectOpts *compose.ProjectOptions) *cobra.Command {
|
||||||
|
opts := upOptions{}
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "ps",
|
||||||
|
RunE: compose.WithProject(projectOpts, func(project *compose.Project, args []string) error {
|
||||||
|
clusteropts, err := docker.GetAwsContext(dockerCli)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
client, err := amazon.NewClient(clusteropts.Profile, clusteropts.Cluster, clusteropts.Region)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return client.ComposePs(context.Background(), project)
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
cmd.Flags().StringVar(&opts.loadBalancerArn, "load-balancer", "", "")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
type downOptions struct {
|
type downOptions struct {
|
||||||
DeleteCluster bool
|
DeleteCluster bool
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
package amazon
|
package amazon
|
||||||
|
|
||||||
import "context"
|
//go:generate mockgen -destination=./mock/api.go -package=mock . API
|
||||||
|
|
||||||
//go:generate mockgen -destination=./api_mock.go -self_package "github.com/docker/ecs-plugin/pkg/amazon" -package=amazon . API
|
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
downAPI
|
downAPI
|
||||||
upAPI
|
upAPI
|
||||||
logsAPI
|
logsAPI
|
||||||
secretsAPI
|
secretsAPI
|
||||||
GetTasks(ctx context.Context, cluster string, name string) ([]string, error)
|
psAPI
|
||||||
GetNetworkInterfaces(ctx context.Context, cluster string, arns ...string) ([]string, error)
|
|
||||||
GetPublicIPs(ctx context.Context, interfaces ...string) ([]string, error)
|
|
||||||
}
|
}
|
||||||
|
55
ecs/pkg/amazon/list.go
Normal file
55
ecs/pkg/amazon/list.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package amazon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/docker/ecs-plugin/pkg/compose"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *client) ComposePs(ctx context.Context, project *compose.Project) error {
|
||||||
|
cluster := c.Cluster
|
||||||
|
if cluster == "" {
|
||||||
|
cluster = project.Name
|
||||||
|
}
|
||||||
|
w := tabwriter.NewWriter(os.Stdout, 20, 2, 3, ' ', 0)
|
||||||
|
fmt.Fprintf(w, "Name\tState\tPorts\n")
|
||||||
|
for _, s := range project.Services {
|
||||||
|
tasks, err := c.api.GetTasks(ctx, cluster, s.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(tasks) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// TODO get more data from DescribeTask, including tasks status
|
||||||
|
networkInterfaces, err := c.api.GetNetworkInterfaces(ctx, cluster, tasks...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(networkInterfaces) == 0 {
|
||||||
|
fmt.Fprintf(w, "%s\t%s\t\n", s.Name, "Provisioning")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
publicIps, err := c.api.GetPublicIPs(ctx, networkInterfaces...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ports := []string{}
|
||||||
|
for _, p := range s.Ports {
|
||||||
|
ports = append(ports, fmt.Sprintf("%s:%d->%d/%s", strings.Join(publicIps, ","), p.Published, p.Target, p.Protocol))
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s\t%s\t%s\n", s.Name, "Up", strings.Join(ports, ", "))
|
||||||
|
}
|
||||||
|
w.Flush()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type psAPI interface {
|
||||||
|
GetTasks(ctx context.Context, cluster string, name string) ([]string, error)
|
||||||
|
GetNetworkInterfaces(ctx context.Context, cluster string, arns ...string) ([]string, error)
|
||||||
|
GetPublicIPs(ctx context.Context, interfaces ...string) ([]string, error)
|
||||||
|
}
|
@ -388,7 +388,9 @@ func (s sdk) GetPublicIPs(ctx context.Context, interfaces ...string) ([]string,
|
|||||||
}
|
}
|
||||||
publicIPs := []string{}
|
publicIPs := []string{}
|
||||||
for _, interf := range desc.NetworkInterfaces {
|
for _, interf := range desc.NetworkInterfaces {
|
||||||
publicIPs = append(publicIPs, *interf.Association.PublicIp)
|
if interf.Association != nil {
|
||||||
|
publicIPs = append(publicIPs, *interf.Association.PublicIp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return publicIPs, nil
|
return publicIPs, nil
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,5 @@ type API interface {
|
|||||||
InspectSecret(ctx context.Context, id string) (docker.Secret, error)
|
InspectSecret(ctx context.Context, id string) (docker.Secret, error)
|
||||||
ListSecrets(ctx context.Context) ([]docker.Secret, error)
|
ListSecrets(ctx context.Context) ([]docker.Secret, error)
|
||||||
DeleteSecret(ctx context.Context, id string, recover bool) error
|
DeleteSecret(ctx context.Context, id string, recover bool) error
|
||||||
|
ComposePs(background context.Context, project *Project) error
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user