forked from coop-cloud/abra
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
"coopcloud.tech/abra/pkg/client"
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var appErrorsCommand = &cli.Command{
|
|
Name: "errors",
|
|
Usage: "List errors for a deployed app",
|
|
Description: `
|
|
This command will list errors for a deployed app. This is a best-effort
|
|
implementation and an attempt to gather a number of tips & tricks for finding
|
|
errors together into one convenient command. When an app is failing to deploy
|
|
or having issues, it could be a lot of things. This command is best accompanied
|
|
by "abra app logs <app>".
|
|
`,
|
|
Aliases: []string{"e"},
|
|
Flags: []cli.Flag{},
|
|
BashComplete: autocomplete.AppNameComplete,
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
|
|
cl, err := client.New(app.Server)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
filters := filters.NewArgs()
|
|
filters.Add("name", app.StackName())
|
|
|
|
containers, err := cl.ContainerList(c.Context, types.ContainerListOptions{Filters: filters})
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
// tableCol := []string{"status", "error", "healthcheck", "healthcheck logs"}
|
|
// table := abraFormatter.CreateTable(tableCol)
|
|
|
|
for _, container := range containers {
|
|
fmt.Println("service: ", strings.Join(container.Names, ""))
|
|
|
|
containerState, err := cl.ContainerInspect(c.Context, container.ID)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
fmt.Println("restarted no. times: ", containerState.RestartCount)
|
|
fmt.Println("status: ", containerState.State.Status)
|
|
fmt.Println("oom killed: ", containerState.State.OOMKilled)
|
|
fmt.Println("error: ", containerState.State.Error)
|
|
|
|
if containerState.State.Health != nil {
|
|
fmt.Println("healthcheck status: ", containerState.State.Health.Status)
|
|
fmt.Println("failed no. times: ", containerState.State.Health.FailingStreak)
|
|
for _, log := range containerState.State.Health.Log {
|
|
fmt.Println("output: ", log.Output)
|
|
}
|
|
}
|
|
|
|
fmt.Println("---")
|
|
|
|
// table.Append([]string{containerState.State.Status, containerState.State.Error, healthCheckState, healthCheckLogs})
|
|
|
|
}
|
|
|
|
// table.Render()
|
|
|
|
return nil
|
|
},
|
|
}
|