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"
|
"github.com/docker/docker/api/types/filters"
|
||||||
dockerclient "github.com/docker/docker/client"
|
dockerclient "github.com/docker/docker/client"
|
||||||
|
|
||||||
// "github.com/docker/cli/cli/command/stack/swarm"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -34,6 +33,13 @@ var majorFlag = &cli.BoolFlag{
|
|||||||
Destination: &majorUpdate,
|
Destination: &majorUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var updateAll bool
|
||||||
|
var allFlag = &cli.BoolFlag{
|
||||||
|
Name: "all, a",
|
||||||
|
Usage: "Update all deployed apps",
|
||||||
|
Destination: &updateAll,
|
||||||
|
}
|
||||||
|
|
||||||
// Check for available upgrades
|
// Check for available upgrades
|
||||||
var Notify = cli.Command{
|
var Notify = cli.Command{
|
||||||
Name: "notify",
|
Name: "notify",
|
||||||
@ -51,8 +57,6 @@ var Notify = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
// can't import this lib:
|
|
||||||
// stacks := swarm.GetStacks(cl)
|
|
||||||
stacks, err := stack.GetStacks(cl)
|
stacks, err := stack.GetStacks(cl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
@ -68,70 +72,48 @@ var Notify = cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upgrade a specific app
|
// Upgrade apps
|
||||||
var UpgradeApp = cli.Command{
|
var UpgradeApp = cli.Command{
|
||||||
Name: "appupgrade",
|
Name: "upgrade",
|
||||||
Aliases: []string{"a"},
|
Aliases: []string{"u"},
|
||||||
Usage: "Upgrade an app",
|
Usage: "Upgrade apps",
|
||||||
ArgsUsage: "<stack_name> <recipe>",
|
ArgsUsage: "<stack_name> <recipe>",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
internal.ForceFlag,
|
internal.ChaosFlag,
|
||||||
majorFlag,
|
majorFlag,
|
||||||
|
allFlag,
|
||||||
},
|
},
|
||||||
Before: internal.SubCommandBefore,
|
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.`,
|
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 {
|
Action: func(c *cli.Context) error {
|
||||||
stackName := c.Args().Get(0)
|
|
||||||
recipeName := c.Args().Get(1)
|
|
||||||
cl, err := client.New("default")
|
cl, err := client.New("default")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
upgradeVersion := getLatestUpgrade(cl, stackName, recipeName)
|
|
||||||
if upgradeVersion != "" {
|
|
||||||
upgrade(cl, stackName, recipeName, upgradeVersion)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upgrade all apps
|
if !updateAll {
|
||||||
var UpgradeAll = cli.Command{
|
stackName := c.Args().Get(0)
|
||||||
Name: "upgrade",
|
recipeName := c.Args().Get(1)
|
||||||
Aliases: []string{"u"},
|
err = tryUpgrade(cl, stackName, recipeName)
|
||||||
Usage: "Upgrade all apps",
|
if err != nil {
|
||||||
Flags: []cli.Flag{
|
logrus.Fatal(err)
|
||||||
internal.DebugFlag,
|
}
|
||||||
internal.ForceFlag,
|
} else {
|
||||||
majorFlag,
|
stacks, err := stack.GetStacks(cl)
|
||||||
},
|
if err != nil {
|
||||||
Before: internal.SubCommandBefore,
|
logrus.Fatal(err)
|
||||||
Description: `Upgrade all deployed apps`,
|
}
|
||||||
Action: func(c *cli.Context) error {
|
for _, stackInfo := range stacks {
|
||||||
|
stackName := stackInfo.Name
|
||||||
cl, err := client.New("default")
|
recipeName, err := getLabel(cl, stackName, "recipe")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
// can't import this lib:
|
err = tryUpgrade(cl, stackName, recipeName)
|
||||||
// stacks := swarm.GetStacks(cl)
|
if err != nil {
|
||||||
stacks, err := stack.GetStacks(cl)
|
logrus.Fatal(err)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
logrus.Debugf("Don't update %s due to missing recipe name, disabled updates or chaos deployment", stackName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user