2021-08-02 01:10:41 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2021-09-07 14:57:39 +00:00
|
|
|
"fmt"
|
2021-08-02 01:10:41 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
2021-09-05 19:37:03 +00:00
|
|
|
"coopcloud.tech/abra/pkg/client"
|
2021-09-07 14:57:39 +00:00
|
|
|
"coopcloud.tech/abra/pkg/config"
|
2021-08-02 01:10:41 +00:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
|
|
|
"github.com/docker/docker/api/types"
|
2021-08-28 14:00:16 +00:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2021-08-02 01:10:41 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var appPsCommand = &cli.Command{
|
2021-09-04 23:34:56 +00:00
|
|
|
Name: "ps",
|
|
|
|
Usage: "Check app status",
|
|
|
|
Aliases: []string{"p"},
|
2021-08-02 01:10:41 +00:00
|
|
|
Action: func(c *cli.Context) error {
|
2021-09-05 21:17:35 +00:00
|
|
|
app := internal.ValidateApp(c)
|
2021-08-28 14:00:16 +00:00
|
|
|
|
2021-09-05 21:17:35 +00:00
|
|
|
cl, err := client.New(app.Server)
|
2021-08-28 14:00:16 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|
2021-08-28 14:00:16 +00:00
|
|
|
|
|
|
|
filters := filters.NewArgs()
|
2021-10-11 23:14:14 +00:00
|
|
|
filters.Add("name", app.StackName())
|
2021-08-28 14:00:16 +00:00
|
|
|
|
2021-09-16 10:17:56 +00:00
|
|
|
containers, err := cl.ContainerList(c.Context, types.ContainerListOptions{Filters: filters})
|
2021-08-02 01:10:41 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
2021-08-28 14:00:16 +00:00
|
|
|
|
2021-09-10 22:54:02 +00:00
|
|
|
tableCol := []string{"id", "image", "command", "created", "status", "ports", "names"}
|
2021-08-28 14:00:16 +00:00
|
|
|
table := abraFormatter.CreateTable(tableCol)
|
|
|
|
|
2021-08-02 01:10:41 +00:00
|
|
|
for _, container := range containers {
|
2021-08-28 14:00:16 +00:00
|
|
|
tableRow := []string{
|
2021-08-02 01:10:41 +00:00
|
|
|
abraFormatter.ShortenID(container.ID),
|
|
|
|
abraFormatter.RemoveSha(container.Image),
|
|
|
|
abraFormatter.Truncate(container.Command),
|
|
|
|
abraFormatter.HumanDuration(container.Created),
|
|
|
|
container.Status,
|
|
|
|
formatter.DisplayablePorts(container.Ports),
|
2021-09-10 22:54:02 +00:00
|
|
|
strings.Join(container.Names, ", "),
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|
2021-08-28 14:00:16 +00:00
|
|
|
table.Append(tableRow)
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|
2021-08-28 14:00:16 +00:00
|
|
|
|
2021-08-02 01:10:41 +00:00
|
|
|
table.Render()
|
|
|
|
return nil
|
|
|
|
},
|
2021-09-07 14:57:39 +00:00
|
|
|
BashComplete: func(c *cli.Context) {
|
2021-09-08 11:43:55 +00:00
|
|
|
appNames, err := config.GetAppNames()
|
2021-09-07 14:57:39 +00:00
|
|
|
if err != nil {
|
2021-09-16 06:45:38 +00:00
|
|
|
logrus.Warn(err)
|
2021-09-07 14:57:39 +00:00
|
|
|
}
|
|
|
|
if c.NArg() > 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, a := range appNames {
|
|
|
|
fmt.Println(a)
|
|
|
|
}
|
|
|
|
},
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|