forked from toolshed/abra
fix!: chaos consistency (deploy/undeploy/rollback/upgrade)
See coop-cloud/organising#559 --chaos for rollback/upgrade goes away.
This commit is contained in:
@ -27,7 +27,6 @@ var appUpgradeCommand = cli.Command{
|
||||
internal.DebugFlag,
|
||||
internal.NoInputFlag,
|
||||
internal.ForceFlag,
|
||||
internal.ChaosFlag,
|
||||
internal.NoDomainChecksFlag,
|
||||
internal.DontWaitConvergeFlag,
|
||||
internal.OfflineFlag,
|
||||
@ -35,11 +34,7 @@ var appUpgradeCommand = cli.Command{
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `
|
||||
Upgrade an app. You can use it to choose and roll out a new upgrade to an
|
||||
existing app.
|
||||
|
||||
This command specifically supports incrementing the version of running apps, as
|
||||
opposed to "abra app deploy <domain>" which will not change the version of a
|
||||
Upgrade an app. You can use it to choose and roll out a new upgrade to a
|
||||
deployed app.
|
||||
|
||||
You may pass "--force/-f" to upgrade to the same version again. This can be
|
||||
@ -47,21 +42,12 @@ useful if the container runtime has gotten into a weird state.
|
||||
|
||||
This action could be destructive, please ensure you have a copy of your app
|
||||
data beforehand.
|
||||
|
||||
Chaos mode ("--chaos") will deploy your local checkout of a recipe as-is,
|
||||
including unstaged changes and can be useful for live hacking and testing new
|
||||
recipes.
|
||||
`,
|
||||
BashComplete: autocomplete.AppNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
app := internal.ValidateApp(c)
|
||||
stackName := app.StackName()
|
||||
|
||||
specificVersion := c.Args().Get(1)
|
||||
if specificVersion != "" && internal.Chaos {
|
||||
log.Fatal("cannot use <version> and --chaos together")
|
||||
}
|
||||
|
||||
if err := app.Recipe.Ensure(internal.Chaos, internal.Offline); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -77,12 +63,12 @@ recipes.
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
|
||||
deployMeta, err := stack.IsDeployed(context.Background(), cl, stackName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !isDeployed {
|
||||
if !deployMeta.IsDeployed {
|
||||
log.Fatalf("%s is not deployed?", app.Name)
|
||||
}
|
||||
|
||||
@ -96,7 +82,7 @@ recipes.
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if len(versions) == 0 && !internal.Chaos {
|
||||
if len(versions) == 0 {
|
||||
log.Warn("no published versions in catalogue, trying local recipe repository")
|
||||
recipeVersions, err := app.Recipe.GetRecipeVersions(internal.Offline)
|
||||
if err != nil {
|
||||
@ -110,13 +96,14 @@ recipes.
|
||||
}
|
||||
|
||||
var availableUpgrades []string
|
||||
if deployedVersion == "unknown" {
|
||||
if deployMeta.Version == "unknown" {
|
||||
availableUpgrades = versions
|
||||
log.Warnf("failed to determine deployed version of %s", app.Name)
|
||||
}
|
||||
|
||||
specificVersion := c.Args().Get(1)
|
||||
if specificVersion != "" {
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployedVersion)
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -125,17 +112,21 @@ recipes.
|
||||
log.Fatal(err)
|
||||
}
|
||||
if parsedSpecificVersion.IsLessThan(parsedDeployedVersion) || parsedSpecificVersion.Equals(parsedDeployedVersion) {
|
||||
log.Fatalf("%s is not an upgrade for %s?", deployedVersion, specificVersion)
|
||||
log.Fatalf("%s is not an upgrade for %s?", deployMeta.Version, specificVersion)
|
||||
}
|
||||
availableUpgrades = append(availableUpgrades, specificVersion)
|
||||
}
|
||||
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployedVersion)
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if deployedVersion != "unknown" && !internal.Chaos && specificVersion == "" {
|
||||
if deployMeta.Version != "unknown" && specificVersion == "" {
|
||||
if deployMeta.IsChaos == "true" {
|
||||
log.Warn("attempting to upgrade a chaos deployment")
|
||||
}
|
||||
|
||||
for _, version := range versions {
|
||||
parsedVersion, err := tagcmp.Parse(version)
|
||||
if err != nil {
|
||||
@ -147,21 +138,27 @@ recipes.
|
||||
}
|
||||
|
||||
if len(availableUpgrades) == 0 && !internal.Force {
|
||||
log.Infof("no available upgrades, you're on latest (%s) ✌️", deployedVersion)
|
||||
log.Info("no available upgrades")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var chosenUpgrade string
|
||||
if len(availableUpgrades) > 0 && !internal.Chaos {
|
||||
if len(availableUpgrades) > 0 {
|
||||
if internal.Force || internal.NoInput || specificVersion != "" {
|
||||
chosenUpgrade = availableUpgrades[len(availableUpgrades)-1]
|
||||
log.Debugf("choosing %s as version to upgrade to", chosenUpgrade)
|
||||
} else {
|
||||
msg := fmt.Sprintf("please select an upgrade (version: %s):", deployMeta.Version)
|
||||
if deployMeta.IsChaos == "true" {
|
||||
msg = fmt.Sprintf("please select an upgrade (version: %s, chaosVersion: %s):", deployMeta.Version, deployMeta.ChaosVersion)
|
||||
}
|
||||
|
||||
prompt := &survey.Select{
|
||||
Message: fmt.Sprintf("Please select an upgrade (current version: %s):", deployedVersion),
|
||||
Message: msg,
|
||||
Options: internal.ReverseStringList(availableUpgrades),
|
||||
}
|
||||
|
||||
if err := survey.AskOne(prompt, &chosenUpgrade); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -169,8 +166,8 @@ recipes.
|
||||
}
|
||||
|
||||
if internal.Force && chosenUpgrade == "" {
|
||||
log.Warnf("%s is already upgraded to latest but continuing (--force/--chaos)", app.Name)
|
||||
chosenUpgrade = deployedVersion
|
||||
log.Warnf("%s is already upgraded to latest but continuing (--force)", app.Name)
|
||||
chosenUpgrade = deployMeta.Version
|
||||
}
|
||||
|
||||
// if release notes written after git tag published, read them before we
|
||||
@ -199,19 +196,9 @@ recipes.
|
||||
}
|
||||
}
|
||||
|
||||
if !internal.Chaos {
|
||||
if err := app.Recipe.EnsureVersion(chosenUpgrade); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if internal.Chaos {
|
||||
log.Warn("chaos mode engaged")
|
||||
var err error
|
||||
chosenUpgrade, err = app.Recipe.ChaosVersion()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Debugf("choosing %s as version to upgrade", chosenUpgrade)
|
||||
if err := app.Recipe.EnsureVersion(chosenUpgrade); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
|
||||
@ -226,6 +213,7 @@ recipes.
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
deployOpts := stack.Deploy{
|
||||
Composefiles: composeFiles,
|
||||
Namespace: stackName,
|
||||
@ -233,10 +221,12 @@ recipes.
|
||||
ResolveImage: stack.ResolveImageAlways,
|
||||
Detach: false,
|
||||
}
|
||||
|
||||
compose, err := appPkg.GetAppComposeConfig(app.Name, deployOpts, app.Env)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
appPkg.ExposeAllEnv(stackName, compose, app.Env)
|
||||
appPkg.SetRecipeLabel(compose, stackName, app.Recipe.Name)
|
||||
appPkg.SetChaosLabel(compose, stackName, internal.Chaos)
|
||||
@ -260,7 +250,12 @@ recipes.
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil {
|
||||
chaosVersion := deployMeta.IsChaos
|
||||
if deployMeta.IsChaos == "true" {
|
||||
chaosVersion = deployMeta.ChaosVersion
|
||||
}
|
||||
|
||||
if err := internal.NewVersionOverview(app, deployMeta.Version, chaosVersion, chosenUpgrade, releaseNotes); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user