102 lines
2.5 KiB
Go
102 lines
2.5 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
"coopcloud.tech/abra/pkg/client"
|
|
"coopcloud.tech/abra/pkg/formatter"
|
|
"coopcloud.tech/abra/pkg/recipe"
|
|
"coopcloud.tech/abra/pkg/upstream/stack"
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
// 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)
|
|
|
|
logrus.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,
|
|
},
|
|
Before: internal.SubCommandBefore,
|
|
Usage: "Show app versions",
|
|
Description: `
|
|
This command shows all information about versioning related to a deployed app.
|
|
This includes the individual image names, tags and digests. But also the Co-op
|
|
Cloud recipe version.
|
|
`,
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
stackName := app.StackName()
|
|
|
|
cl, err := client.New(app.Server)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
logrus.Debugf("checking whether %s is already deployed", stackName)
|
|
|
|
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
if deployedVersion == "unknown" {
|
|
logrus.Fatalf("failed to determine version of deployed %s", app.Name)
|
|
}
|
|
|
|
if !isDeployed {
|
|
logrus.Fatalf("%s is not deployed?", app.Name)
|
|
}
|
|
|
|
recipeMeta, err := recipe.GetRecipeMeta(app.Recipe)
|
|
if err != nil {
|
|
logrus.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 {
|
|
logrus.Fatalf("could not retrieve deployed version (%s) from recipe catalogue?", deployedVersion)
|
|
}
|
|
|
|
tableCol := []string{"version", "service", "image", "digest"}
|
|
table := formatter.CreateTable(tableCol)
|
|
table.SetAutoMergeCellsByColumnIndex([]int{0})
|
|
|
|
for serviceName, versionMeta := range versionsMeta {
|
|
table.Append([]string{deployedVersion, serviceName, versionMeta.Image, versionMeta.Digest})
|
|
}
|
|
|
|
table.Render()
|
|
|
|
return nil
|
|
},
|
|
BashComplete: autocomplete.AppNameComplete,
|
|
}
|