2021-08-02 01:10:41 +00:00
|
|
|
package app
|
|
|
|
|
2021-08-29 23:36:42 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
|
|
"coopcloud.tech/abra/client"
|
2021-09-01 11:08:42 +00:00
|
|
|
stack "coopcloud.tech/abra/client/stack"
|
2021-08-29 23:36:42 +00:00
|
|
|
"coopcloud.tech/abra/config"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
2021-08-02 01:10:41 +00:00
|
|
|
|
|
|
|
var appUndeployCommand = &cli.Command{
|
2021-09-04 23:34:56 +00:00
|
|
|
Name: "undeploy",
|
|
|
|
Aliases: []string{"u"},
|
|
|
|
Usage: "Undeploy an app",
|
|
|
|
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 {
|
|
|
|
appName := c.Args().First()
|
|
|
|
if appName == "" {
|
|
|
|
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided"))
|
|
|
|
}
|
|
|
|
|
|
|
|
appFiles, err := config.LoadAppFiles("")
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
appEnv, err := config.GetApp(appFiles, appName)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
host := appFiles[appName].Server
|
2021-09-04 22:41:31 +00:00
|
|
|
cl, err := client.New(host)
|
2021-08-29 23:36:42 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-09-04 19:08:14 +00:00
|
|
|
rmOpts := stack.Remove{Namespaces: []string{appEnv.StackName()}}
|
2021-09-01 11:08:42 +00:00
|
|
|
if err := stack.RunRemove(ctx, cl, rmOpts); err != nil {
|
2021-08-29 23:36:42 +00:00
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
2021-08-02 01:10:41 +00:00
|
|
|
}
|