decentral1se
66aeeee768
All checks were successful
continuous-integration/drone/push Build is passing
Closes coop-cloud/organising#161.
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/client"
|
|
"coopcloud.tech/abra/pkg/config"
|
|
"github.com/docker/cli/cli/command/formatter"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var appPsCommand = &cli.Command{
|
|
Name: "ps",
|
|
Usage: "Check app status",
|
|
Aliases: []string{"p"},
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
|
|
ctx := context.Background()
|
|
cl, err := client.New(app.Server)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
filters := filters.NewArgs()
|
|
filters.Add("name", app.StackName())
|
|
|
|
containers, err := cl.ContainerList(ctx, types.ContainerListOptions{Filters: filters})
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
tableCol := []string{"id", "image", "command", "created", "status", "ports", "names"}
|
|
table := abraFormatter.CreateTable(tableCol)
|
|
|
|
for _, container := range containers {
|
|
tableRow := []string{
|
|
abraFormatter.ShortenID(container.ID),
|
|
abraFormatter.RemoveSha(container.Image),
|
|
abraFormatter.Truncate(container.Command),
|
|
abraFormatter.HumanDuration(container.Created),
|
|
container.Status,
|
|
formatter.DisplayablePorts(container.Ports),
|
|
strings.Join(container.Names, ", "),
|
|
}
|
|
table.Append(tableRow)
|
|
}
|
|
|
|
table.Render()
|
|
return nil
|
|
},
|
|
BashComplete: func(c *cli.Context) {
|
|
appNames, err := config.GetAppNames()
|
|
if err != nil {
|
|
logrus.Warn(err)
|
|
}
|
|
if c.NArg() > 0 {
|
|
return
|
|
}
|
|
for _, a := range appNames {
|
|
fmt.Println(a)
|
|
}
|
|
},
|
|
}
|