WIP: Messy code that is mostly just testing
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:
Roxie Gibson 2021-07-17 09:30:56 +01:00
parent 6c748922b4
commit 2134f57dd0
Signed by untrusted user: roxxers
GPG Key ID: 5D0140EDEE123F4D
1 changed files with 46 additions and 0 deletions

View File

@ -1,8 +1,16 @@
package cli
import (
"context"
"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/urfave/cli/v2"
)
@ -60,6 +68,44 @@ var appLogsCommand = &cli.Command{
var appPsCommand = &cli.Command{
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{
Name: "remove",