forked from coop-cloud/abra
merge UpgradeApp and UpgradeAll using --all flag
This commit is contained in:
parent
a58c60da61
commit
401357f7ad
@ -20,7 +20,6 @@ import (
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
dockerclient "github.com/docker/docker/client"
|
||||
|
||||
// "github.com/docker/cli/cli/command/stack/swarm"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -34,6 +33,13 @@ var majorFlag = &cli.BoolFlag{
|
||||
Destination: &majorUpdate,
|
||||
}
|
||||
|
||||
var updateAll bool
|
||||
var allFlag = &cli.BoolFlag{
|
||||
Name: "all, a",
|
||||
Usage: "Update all deployed apps",
|
||||
Destination: &updateAll,
|
||||
}
|
||||
|
||||
// Check for available upgrades
|
||||
var Notify = cli.Command{
|
||||
Name: "notify",
|
||||
@ -51,8 +57,6 @@ var Notify = cli.Command{
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
// can't import this lib:
|
||||
// stacks := swarm.GetStacks(cl)
|
||||
stacks, err := stack.GetStacks(cl)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
@ -68,70 +72,48 @@ var Notify = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
// Upgrade a specific app
|
||||
// Upgrade apps
|
||||
var UpgradeApp = cli.Command{
|
||||
Name: "appupgrade",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "Upgrade an app",
|
||||
Name: "upgrade",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Upgrade apps",
|
||||
ArgsUsage: "<stack_name> <recipe>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.ForceFlag,
|
||||
internal.ChaosFlag,
|
||||
majorFlag,
|
||||
allFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `Upgrade an app by specifying its stack name and recipe. By passing --all instead every deployed app is upgraded. For each apps with enabled auto updates the deployed version is compared with the current recipe catalogue version. If a new patch/minor version is available the app is upgraded. To include major versions use the --major flag. Don't do that, it will probably break things. Only apps that are not deployed with --chaos are upgraded, to update chaos deployments use the --chaos flag. Use it with care.`,
|
||||
Action: func(c *cli.Context) error {
|
||||
stackName := c.Args().Get(0)
|
||||
recipeName := c.Args().Get(1)
|
||||
cl, err := client.New("default")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
upgradeVersion := getLatestUpgrade(cl, stackName, recipeName)
|
||||
if upgradeVersion != "" {
|
||||
upgrade(cl, stackName, recipeName, upgradeVersion)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// Upgrade all apps
|
||||
var UpgradeAll = cli.Command{
|
||||
Name: "upgrade",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Upgrade all apps",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.ForceFlag,
|
||||
majorFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `Upgrade all deployed apps`,
|
||||
Action: func(c *cli.Context) error {
|
||||
|
||||
cl, err := client.New("default")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
// can't import this lib:
|
||||
// stacks := swarm.GetStacks(cl)
|
||||
stacks, err := stack.GetStacks(cl)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
for _, stackInfo := range stacks {
|
||||
stackName := stackInfo.Name
|
||||
recipeName := getLabel(cl, stackName, "recipe")
|
||||
chaos := getBoolLabel(cl, stackName, "chaos")
|
||||
updatesEnabled := getBoolLabel(cl, stackName, "autoupdate")
|
||||
if recipeName != "" && updatesEnabled && (!chaos || internal.Force) {
|
||||
upgradeVersion := getLatestUpgrade(cl, stackName, recipeName)
|
||||
if upgradeVersion != "" {
|
||||
upgrade(cl, stackName, recipeName, upgradeVersion)
|
||||
if !updateAll {
|
||||
stackName := c.Args().Get(0)
|
||||
recipeName := c.Args().Get(1)
|
||||
err = tryUpgrade(cl, stackName, recipeName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
stacks, err := stack.GetStacks(cl)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
for _, stackInfo := range stacks {
|
||||
stackName := stackInfo.Name
|
||||
recipeName, err := getLabel(cl, stackName, "recipe")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
err = tryUpgrade(cl, stackName, recipeName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
logrus.Debugf("Don't update %s due to missing recipe name, disabled updates or chaos deployment", stackName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user