feat: app services command
continuous-integration/drone/push Build was killed
Details
continuous-integration/drone/push Build was killed
Details
Closes coop-cloud/organising#372
This commit is contained in:
parent
d4a42d8378
commit
49865c6a97
|
@ -11,26 +11,27 @@ var AppCommand = cli.Command{
|
||||||
ArgsUsage: "<domain>",
|
ArgsUsage: "<domain>",
|
||||||
Description: "Functionality for managing the life cycle of your apps",
|
Description: "Functionality for managing the life cycle of your apps",
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
appNewCommand,
|
|
||||||
appConfigCommand,
|
|
||||||
appRestartCommand,
|
|
||||||
appDeployCommand,
|
|
||||||
appUpgradeCommand,
|
|
||||||
appUndeployCommand,
|
|
||||||
appRemoveCommand,
|
|
||||||
appCheckCommand,
|
|
||||||
appListCommand,
|
|
||||||
appPsCommand,
|
|
||||||
appLogsCommand,
|
|
||||||
appCpCommand,
|
|
||||||
appRunCommand,
|
|
||||||
appRollbackCommand,
|
|
||||||
appSecretCommand,
|
|
||||||
appVolumeCommand,
|
|
||||||
appVersionCommand,
|
|
||||||
appErrorsCommand,
|
|
||||||
appCmdCommand,
|
|
||||||
appBackupCommand,
|
appBackupCommand,
|
||||||
|
appCheckCommand,
|
||||||
|
appCmdCommand,
|
||||||
|
appConfigCommand,
|
||||||
|
appCpCommand,
|
||||||
|
appDeployCommand,
|
||||||
|
appErrorsCommand,
|
||||||
|
appListCommand,
|
||||||
|
appLogsCommand,
|
||||||
|
appNewCommand,
|
||||||
|
appPsCommand,
|
||||||
|
appRemoveCommand,
|
||||||
|
appRestartCommand,
|
||||||
appRestoreCommand,
|
appRestoreCommand,
|
||||||
|
appRollbackCommand,
|
||||||
|
appRunCommand,
|
||||||
|
appSecretCommand,
|
||||||
|
appServicesCommand,
|
||||||
|
appUndeployCommand,
|
||||||
|
appUpgradeCommand,
|
||||||
|
appVersionCommand,
|
||||||
|
appVolumeCommand,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/cli/internal"
|
||||||
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
|
"coopcloud.tech/abra/pkg/client"
|
||||||
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
|
"coopcloud.tech/abra/pkg/service"
|
||||||
|
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var appServicesCommand = cli.Command{
|
||||||
|
Name: "services",
|
||||||
|
Aliases: []string{"sr"},
|
||||||
|
Usage: "Display all services of an app",
|
||||||
|
ArgsUsage: "<domain>",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
internal.DebugFlag,
|
||||||
|
},
|
||||||
|
Before: internal.SubCommandBefore,
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
isDeployed, _, err := stack.IsDeployed(context.Background(), cl, app.StackName())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isDeployed {
|
||||||
|
logrus.Fatalf("%s is not deployed?", app.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
filters, err := app.Filters(true, true)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
containers, err := cl.ContainerList(context.Background(), types.ContainerListOptions{Filters: filters})
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tableCol := []string{"service name", "image"}
|
||||||
|
table := formatter.CreateTable(tableCol)
|
||||||
|
|
||||||
|
for _, container := range containers {
|
||||||
|
var containerNames []string
|
||||||
|
for _, containerName := range container.Names {
|
||||||
|
trimmed := strings.TrimPrefix(containerName, "/")
|
||||||
|
containerNames = append(containerNames, trimmed)
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceShortName := service.ContainerToServiceName(container.Names, app.StackName())
|
||||||
|
serviceLongName := fmt.Sprintf("%s_%s", app.StackName(), serviceShortName)
|
||||||
|
|
||||||
|
tableRow := []string{
|
||||||
|
serviceLongName,
|
||||||
|
formatter.RemoveSha(container.Image),
|
||||||
|
}
|
||||||
|
table.Append(tableRow)
|
||||||
|
}
|
||||||
|
|
||||||
|
table.Render()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
|
@ -45,9 +45,9 @@ type App struct {
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// StackName gets what the docker safe stack name is for the app. This should
|
// StackName gets whatever the docker safe (uses the right delimiting
|
||||||
// not not shown to the user, use a.Name for that. Give the output of this
|
// character, e.g. "_") stack name is for the app. In general, you don't want
|
||||||
// command to Docker only.
|
// to use this to show anything to end-users, you want use a.Name instead.
|
||||||
func (a App) StackName() string {
|
func (a App) StackName() string {
|
||||||
if _, exists := a.Env["STACK_NAME"]; exists {
|
if _, exists := a.Env["STACK_NAME"]; exists {
|
||||||
return a.Env["STACK_NAME"]
|
return a.Env["STACK_NAME"]
|
||||||
|
|
Loading…
Reference in New Issue