WIP: Messy code that is mostly just testing
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This is me trying to print all services in a stack. Struggling to isolate stack and tasks which is needed for swarm
This commit is contained in:
parent
6c748922b4
commit
2134f57dd0
46
cli/app.go
46
cli/app.go
|
@ -1,8 +1,16 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
|
"github.com/docker/cli/cli/command/idresolver"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/client"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/schultz-is/passgen"
|
"github.com/schultz-is/passgen"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
@ -60,6 +68,44 @@ var appLogsCommand = &cli.Command{
|
||||||
|
|
||||||
var appPsCommand = &cli.Command{
|
var appPsCommand = &cli.Command{
|
||||||
Name: "ps",
|
Name: "ps",
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
ctx := context.Background()
|
||||||
|
fmt.Println(Context)
|
||||||
|
cl := client.NewClientWithContext(Context)
|
||||||
|
tasks, err := cl.TaskList(ctx, types.TaskListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, task := range tasks {
|
||||||
|
resolver := idresolver.New(cl, false)
|
||||||
|
serviceName, err := resolver.Resolve(ctx, swarm.Service{}, task.ServiceID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("%#v\n", serviceName)
|
||||||
|
}
|
||||||
|
containers, err := cl.ContainerList(ctx, types.ContainerListOptions{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
table := createTable([]string{"ID", "Image", "Command", "Created", "Status", "Ports", "Names"})
|
||||||
|
var conTable [][]string
|
||||||
|
for _, container := range containers {
|
||||||
|
conRow := []string{
|
||||||
|
shortenID(container.ID),
|
||||||
|
removeSha(container.Image),
|
||||||
|
truncate(container.Command),
|
||||||
|
humanDuration(container.Created),
|
||||||
|
container.Status,
|
||||||
|
formatter.DisplayablePorts(container.Ports),
|
||||||
|
strings.Join(container.Names, ","),
|
||||||
|
}
|
||||||
|
conTable = append(conTable, conRow)
|
||||||
|
}
|
||||||
|
table.AppendBulk(conTable)
|
||||||
|
table.Render()
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
var appRemoveCommand = &cli.Command{
|
var appRemoveCommand = &cli.Command{
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
|
|
Loading…
Reference in New Issue