extract upgrade requirement checkings

This commit is contained in:
Moritz 2023-02-07 18:15:41 +01:00
parent d9423cd8aa
commit 17f0e35cdc
1 changed files with 34 additions and 1 deletions

View File

@ -333,6 +333,40 @@ func createDeployConfig(recipeName string, stackName string, env config.AppEnv)
config.SetUpdateLabel(compose, stackName, env)
return compose, deployOpts, nil
}
// tryUpgrade performs the upgrade if all the requirements are fulfilled
func tryUpgrade(cl *dockerclient.Client, stackName string, recipeName string) error {
if recipeName == "" {
logrus.Debugf("Don't update %s due to missing recipe name", stackName)
return nil
}
chaos, err := getBoolLabel(cl, stackName, "chaos")
if err != nil {
return err
}
if chaos && !internal.Chaos {
logrus.Debugf("Don't update %s due to chaos deployment.", stackName)
return nil
}
updatesEnabled, err := getBoolLabel(cl, stackName, "autoupdate")
if err != nil {
return err
}
if !updatesEnabled {
logrus.Debugf("Don't update %s due to disabling auto updates or missing ENABLE_AUTOUPDATE env.", stackName)
return nil
}
upgradeVersion, err := getLatestUpgrade(cl, stackName, recipeName)
if err != nil {
return err
}
if upgradeVersion == "" {
logrus.Debugf("Don't update %s due to no new version.", stackName)
return nil
}
err = upgrade(cl, stackName, recipeName, upgradeVersion)
return err
}
// upgrade performs all necessary steps to upgrade an app
@ -381,7 +415,6 @@ func newAbraApp(version, commit string) *cli.App {
Commands: []cli.Command{
Notify,
UpgradeApp,
UpgradeAll,
},
}