forked from toolshed/abra
refactor!: drop version, show versions in ps
See coop-cloud/organising#526 See coop-cloud/organising#502
This commit is contained in:
@ -30,7 +30,6 @@ var AppCommand = cli.Command{
|
||||
appServicesCommand,
|
||||
appUndeployCommand,
|
||||
appUpgradeCommand,
|
||||
appVersionCommand,
|
||||
appVolumeCommand,
|
||||
},
|
||||
}
|
||||
|
@ -50,23 +50,30 @@ var appPsCommand = cli.Command{
|
||||
log.Fatalf("%s is not deployed?", app.Name)
|
||||
}
|
||||
|
||||
chaosVersion := "false"
|
||||
statuses, err := appPkg.GetAppStatuses([]appPkg.App{app}, true)
|
||||
if statusMeta, ok := statuses[app.StackName()]; ok {
|
||||
if _, exists := statusMeta["chaos"]; !exists {
|
||||
isChaos, exists := statusMeta["chaos"]
|
||||
if exists && isChaos == "false" {
|
||||
if err := app.Recipe.EnsureVersion(deployedVersion); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
chaosVersion, err = app.Recipe.ChaosVersion()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showPSOutput(app, cl)
|
||||
showPSOutput(app, cl, deployedVersion, chaosVersion)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// showPSOutput renders ps output.
|
||||
func showPSOutput(app appPkg.App, cl *dockerClient.Client) {
|
||||
func showPSOutput(app appPkg.App, cl *dockerClient.Client, deployedVersion, chaosVersion string) {
|
||||
r := recipe.Get(app.Name)
|
||||
composeFiles, err := r.GetComposeFiles(app.Env)
|
||||
if err != nil {
|
||||
@ -101,6 +108,8 @@ func showPSOutput(app appPkg.App, cl *dockerClient.Client) {
|
||||
var containerStats map[string]string
|
||||
if len(containers) == 0 {
|
||||
containerStats = map[string]string{
|
||||
"version": deployedVersion,
|
||||
"chaos": chaosVersion,
|
||||
"service": service.Name,
|
||||
"image": "unknown",
|
||||
"created": "unknown",
|
||||
@ -111,6 +120,8 @@ func showPSOutput(app appPkg.App, cl *dockerClient.Client) {
|
||||
} else {
|
||||
container := containers[0]
|
||||
containerStats = map[string]string{
|
||||
"version": deployedVersion,
|
||||
"chaos": chaosVersion,
|
||||
"service": abraService.ContainerToServiceName(container.Names, app.StackName()),
|
||||
"image": formatter.RemoveSha(container.Image),
|
||||
"created": formatter.HumanDuration(container.Created),
|
||||
@ -123,6 +134,8 @@ func showPSOutput(app appPkg.App, cl *dockerClient.Client) {
|
||||
allContainerStats[containerStats["service"]] = containerStats
|
||||
|
||||
tablerow := []string{
|
||||
deployedVersion,
|
||||
chaosVersion,
|
||||
containerStats["service"],
|
||||
containerStats["image"],
|
||||
containerStats["created"],
|
||||
@ -145,10 +158,11 @@ func showPSOutput(app appPkg.App, cl *dockerClient.Client) {
|
||||
return
|
||||
}
|
||||
|
||||
tableCol := []string{"service", "image", "created", "status", "state", "ports"}
|
||||
tableCol := []string{"version", "chaos", "service", "image", "created", "status", "state", "ports"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
for _, row := range tablerows {
|
||||
table.Append(row)
|
||||
}
|
||||
table.SetAutoMergeCellsByColumnIndex([]int{0, 1})
|
||||
table.Render()
|
||||
}
|
||||
|
@ -1,117 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func sortServiceByName(versions [][]string) func(i, j int) bool {
|
||||
return func(i, j int) bool {
|
||||
// NOTE(d1): corresponds to the `tableCol` definition below
|
||||
if versions[i][1] == "app" {
|
||||
return true
|
||||
}
|
||||
return versions[i][1] < versions[j][1]
|
||||
}
|
||||
}
|
||||
|
||||
// getImagePath returns the image name
|
||||
func getImagePath(image string) (string, error) {
|
||||
img, err := reference.ParseNormalizedNamed(image)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
path := reference.Path(img)
|
||||
|
||||
path = formatter.StripTagMeta(path)
|
||||
|
||||
log.Debugf("parsed %s from %s", path, image)
|
||||
|
||||
return path, nil
|
||||
}
|
||||
|
||||
var appVersionCommand = cli.Command{
|
||||
Name: "version",
|
||||
Aliases: []string{"v"},
|
||||
ArgsUsage: "<domain>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.NoInputFlag,
|
||||
internal.OfflineFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Usage: "Show version info of a deployed app",
|
||||
BashComplete: autocomplete.AppNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
app := internal.ValidateApp(c)
|
||||
stackName := app.StackName()
|
||||
|
||||
cl, err := client.New(app.Server)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Debugf("checking whether %s is already deployed", stackName)
|
||||
|
||||
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !isDeployed {
|
||||
log.Fatalf("%s is not deployed?", app.Name)
|
||||
}
|
||||
|
||||
if deployedVersion == "unknown" {
|
||||
log.Fatalf("failed to determine version of deployed %s", app.Name)
|
||||
}
|
||||
|
||||
recipeMeta, err := recipe.GetRecipeMeta(app.Recipe.Name, internal.Offline)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
versionsMeta := make(map[string]recipe.ServiceMeta)
|
||||
for _, recipeVersion := range recipeMeta.Versions {
|
||||
if currentVersion, exists := recipeVersion[deployedVersion]; exists {
|
||||
versionsMeta = currentVersion
|
||||
}
|
||||
}
|
||||
|
||||
if len(versionsMeta) == 0 {
|
||||
log.Fatalf("could not retrieve deployed version (%s) from recipe catalogue?", deployedVersion)
|
||||
}
|
||||
|
||||
tableCol := []string{"version", "service", "image", "tag"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
|
||||
var versions [][]string
|
||||
for serviceName, versionMeta := range versionsMeta {
|
||||
versions = append(versions, []string{deployedVersion, serviceName, versionMeta.Image, versionMeta.Tag})
|
||||
}
|
||||
|
||||
sort.Slice(versions, sortServiceByName(versions))
|
||||
|
||||
for _, version := range versions {
|
||||
table.Append(version)
|
||||
}
|
||||
|
||||
table.SetAutoMergeCellsByColumnIndex([]int{0})
|
||||
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||
table.Render()
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user