2021-08-02 01:10:41 +00:00
|
|
|
package app
|
|
|
|
|
2021-08-29 23:36:42 +00:00
|
|
|
import (
|
2022-01-18 13:13:20 +00:00
|
|
|
"context"
|
|
|
|
|
2021-08-29 23:36:42 +00:00
|
|
|
"coopcloud.tech/abra/cli/internal"
|
2021-12-11 23:17:39 +00:00
|
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
2021-09-05 19:37:03 +00:00
|
|
|
"coopcloud.tech/abra/pkg/client"
|
2021-10-21 17:35:13 +00:00
|
|
|
stack "coopcloud.tech/abra/pkg/upstream/stack"
|
2021-08-29 23:36:42 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-01-18 13:13:20 +00:00
|
|
|
"github.com/urfave/cli"
|
2021-08-29 23:36:42 +00:00
|
|
|
)
|
2021-08-02 01:10:41 +00:00
|
|
|
|
2022-01-18 13:13:20 +00:00
|
|
|
var appUndeployCommand = cli.Command{
|
2021-09-04 23:34:56 +00:00
|
|
|
Name: "undeploy",
|
2021-12-27 15:12:29 +00:00
|
|
|
Aliases: []string{"un"},
|
2022-01-18 13:13:20 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
internal.DebugFlag,
|
|
|
|
internal.NoInputFlag,
|
|
|
|
},
|
|
|
|
Before: internal.SubCommandBefore,
|
|
|
|
Usage: "Undeploy an app",
|
2021-09-04 23:34:56 +00:00
|
|
|
Description: `
|
|
|
|
This does not destroy any of the application data. However, you should remain
|
|
|
|
vigilant, as your swarm installation will consider any previously attached
|
|
|
|
volumes as eligiblef or pruning once undeployed.
|
|
|
|
`,
|
2021-08-29 23:36:42 +00:00
|
|
|
Action: func(c *cli.Context) error {
|
2021-09-05 21:17:35 +00:00
|
|
|
app := internal.ValidateApp(c)
|
2021-10-21 13:10:43 +00:00
|
|
|
stackName := app.StackName()
|
2021-08-29 23:36:42 +00:00
|
|
|
|
2021-09-05 21:17:35 +00:00
|
|
|
cl, err := client.New(app.Server)
|
2021-08-29 23:36:42 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-12-25 01:03:09 +00:00
|
|
|
logrus.Debugf("checking whether %s is already deployed", stackName)
|
2021-10-21 13:10:43 +00:00
|
|
|
|
2022-01-18 13:13:20 +00:00
|
|
|
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
|
2021-10-21 13:10:43 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isDeployed {
|
2022-01-01 16:22:19 +00:00
|
|
|
logrus.Fatalf("%s is not deployed?", app.Name)
|
2021-10-21 13:10:43 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 08:20:40 +00:00
|
|
|
if err := internal.DeployOverview(app, deployedVersion, "continue with undeploy?"); err != nil {
|
2021-10-21 13:10:43 +00:00
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-09-05 21:17:35 +00:00
|
|
|
rmOpts := stack.Remove{Namespaces: []string{app.StackName()}}
|
2022-01-18 13:13:20 +00:00
|
|
|
if err := stack.RunRemove(context.Background(), cl, rmOpts); err != nil {
|
2021-08-29 23:36:42 +00:00
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
2021-12-11 23:17:39 +00:00
|
|
|
BashComplete: autocomplete.AppNameComplete,
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|