2021-08-02 01:10:41 +00:00
|
|
|
package app
|
|
|
|
|
2021-09-08 11:59:55 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-09-08 10:55:33 +00:00
|
|
|
"context"
|
|
|
|
|
2021-09-08 11:59:55 +00:00
|
|
|
"coopcloud.tech/abra/pkg/config"
|
2021-09-08 10:55:33 +00:00
|
|
|
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
|
|
appPkg "coopcloud.tech/abra/pkg/app"
|
|
|
|
"coopcloud.tech/abra/pkg/catalogue"
|
|
|
|
"coopcloud.tech/abra/pkg/client"
|
|
|
|
"github.com/sirupsen/logrus"
|
2021-09-08 11:59:55 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
2021-08-02 01:10:41 +00:00
|
|
|
|
|
|
|
var appRollbackCommand = &cli.Command{
|
|
|
|
Name: "rollback",
|
2021-09-04 23:34:56 +00:00
|
|
|
Usage: "Roll an app back to a previous version",
|
2021-09-08 10:55:33 +00:00
|
|
|
Aliases: []string{"r"},
|
2021-08-02 01:10:41 +00:00
|
|
|
ArgsUsage: "[<version>]",
|
2021-09-08 11:59:55 +00:00
|
|
|
BashComplete: func(c *cli.Context) {
|
|
|
|
appNames, err := config.GetAppNames()
|
|
|
|
if err != nil {
|
2021-09-08 10:55:33 +00:00
|
|
|
logrus.Warn(err)
|
2021-09-08 11:59:55 +00:00
|
|
|
}
|
|
|
|
if c.NArg() > 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, a := range appNames {
|
|
|
|
fmt.Println(a)
|
|
|
|
}
|
|
|
|
},
|
2021-09-08 10:55:33 +00:00
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
app := internal.ValidateApp(c)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
cl, err := client.New(app.Server)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
recipeMeta, err := catalogue.GetRecipeMeta(app.Type)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(recipeMeta.Versions) == 0 {
|
|
|
|
logrus.Fatalf("no catalogue versions available for '%s'", app.Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
deployedVersions, isDeployed, err := appPkg.DeployedVersions(ctx, cl, app)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
if !isDeployed {
|
|
|
|
logrus.Fatalf("'%s' is not deployed?", app.Name)
|
|
|
|
}
|
|
|
|
if _, exists := deployedVersions["app"]; !exists {
|
|
|
|
logrus.Fatalf("no versioned 'app' service for '%s', cannot determine version", app.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
version := c.Args().Get(1)
|
|
|
|
if version == "" {
|
|
|
|
// TODO:
|
|
|
|
// using deployedVersions["app"], get index+1 version from catalogue
|
|
|
|
// otherwise bail out saying there is nothing to rollback to
|
|
|
|
} else {
|
|
|
|
// TODO
|
|
|
|
// ensure this version is listed in the catalogue
|
|
|
|
// ensure this version is "older" (lower down in the list)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// display table of existing state and expected state and prompt
|
|
|
|
// run the deployment with this target version!
|
|
|
|
|
2021-09-10 22:54:02 +00:00
|
|
|
logrus.Fatal("command not implemented yet, coming soon TM")
|
|
|
|
|
2021-09-08 10:55:33 +00:00
|
|
|
return nil
|
|
|
|
},
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|