forked from toolshed/abra
		
	| @ -1,7 +1,7 @@ | ||||
| package app | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"errors" | ||||
|  | ||||
| 	"coopcloud.tech/abra/pkg/app" | ||||
| 	appPkg "coopcloud.tech/abra/pkg/app" | ||||
| @ -9,6 +9,7 @@ import ( | ||||
| 	"coopcloud.tech/abra/pkg/config" | ||||
| 	"coopcloud.tech/abra/pkg/envfile" | ||||
| 	"coopcloud.tech/abra/pkg/formatter" | ||||
| 	"coopcloud.tech/abra/pkg/i18n" | ||||
| 	"coopcloud.tech/abra/pkg/lint" | ||||
| 	stack "coopcloud.tech/abra/pkg/upstream/stack" | ||||
| 	"coopcloud.tech/tagcmp" | ||||
| @ -21,10 +22,10 @@ import ( | ||||
| ) | ||||
|  | ||||
| var AppRollbackCommand = &cobra.Command{ | ||||
| 	Use:     "rollback <domain> [version] [flags]", | ||||
| 	Aliases: []string{"rl"}, | ||||
| 	Short:   "Roll an app back to a previous version", | ||||
| 	Long: `This command rolls an app back to a previous version. | ||||
| 	Use:     i18n.G("rollback <domain> [version] [flags]"), | ||||
| 	Aliases: []string{i18n.G("rl")}, | ||||
| 	Short:   i18n.G("Roll an app back to a previous version"), | ||||
| 	Long: i18n.G(`This command rolls an app back to a previous version. | ||||
|  | ||||
| Unlike "abra app deploy", chaos operations are not supported here. Only recipe | ||||
| versions are supported values for "[version]". | ||||
| @ -37,12 +38,12 @@ are available. The live deployment version is the "source of truth" in this | ||||
| case. The stored .env version is not consulted. | ||||
|  | ||||
| A downgrade can be destructive, please ensure you have a copy of your app data | ||||
| beforehand. See "abra app backup" for more.`, | ||||
| 	Example: ` # standard rollback | ||||
| beforehand. See "abra app backup" for more.`), | ||||
| 	Example: i18n.G(` # standard rollback | ||||
|   abra app rollback 1312.net | ||||
|  | ||||
|   # rollback to specific version | ||||
|   abra app rollback 1312.net 2.0.0+1.2.3`, | ||||
|   abra app rollback 1312.net 2.0.0+1.2.3`), | ||||
| 	Args: cobra.RangeArgs(1, 2), | ||||
| 	ValidArgsFunction: func( | ||||
| 		cmd *cobra.Command, | ||||
| @ -54,8 +55,7 @@ beforehand. See "abra app backup" for more.`, | ||||
| 		case 1: | ||||
| 			app, err := appPkg.Get(args[0]) | ||||
| 			if err != nil { | ||||
| 				errMsg := fmt.Sprintf("autocomplete failed: %s", err) | ||||
| 				return []string{errMsg}, cobra.ShellCompDirectiveError | ||||
| 				return []string{i18n.G("autocomplete failed: %s", err)}, cobra.ShellCompDirectiveError | ||||
| 			} | ||||
| 			return autocomplete.RecipeVersionComplete(app.Recipe.Name) | ||||
| 		default: | ||||
| @ -117,7 +117,7 @@ beforehand. See "abra app backup" for more.`, | ||||
| 			} | ||||
|  | ||||
| 			if !downgradeAvailable { | ||||
| 				log.Info("no available downgrades") | ||||
| 				log.Info(i18n.G("no available downgrades")) | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| @ -139,10 +139,10 @@ beforehand. See "abra app backup" for more.`, | ||||
| 		} | ||||
|  | ||||
| 		if chosenDowngrade == "" { | ||||
| 			log.Fatal("unknown deployed version, unable to downgrade") | ||||
| 			log.Fatal(i18n.G("unknown deployed version, unable to downgrade")) | ||||
| 		} | ||||
|  | ||||
| 		log.Debugf("choosing %s as version to rollback", chosenDowngrade) | ||||
| 		log.Debug(i18n.G("choosing %s as version to rollback", chosenDowngrade)) | ||||
|  | ||||
| 		if _, err := app.Recipe.EnsureVersion(chosenDowngrade); err != nil { | ||||
| 			log.Fatal(err) | ||||
| @ -199,7 +199,7 @@ beforehand. See "abra app backup" for more.`, | ||||
| 			log.Fatal(err) | ||||
| 		} | ||||
|  | ||||
| 		log.Debugf("set waiting timeout to %d second(s)", stack.WaitTimeout) | ||||
| 		log.Debug(i18n.G("set waiting timeout to %d second(s)", stack.WaitTimeout)) | ||||
|  | ||||
| 		serviceNames, err := appPkg.GetAppServiceNames(app.Name) | ||||
| 		if err != nil { | ||||
| @ -224,7 +224,7 @@ beforehand. See "abra app backup" for more.`, | ||||
| 		} | ||||
|  | ||||
| 		if err := app.WriteRecipeVersion(chosenDowngrade, false); err != nil { | ||||
| 			log.Fatalf("writing recipe version failed: %s", err) | ||||
| 			log.Fatal(i18n.G("writing recipe version failed: %s", err)) | ||||
| 		} | ||||
| 	}, | ||||
| } | ||||
| @ -235,12 +235,12 @@ func chooseDowngrade( | ||||
| 	deployMeta stack.DeployMeta, | ||||
| 	chosenDowngrade *string, | ||||
| ) error { | ||||
| 	msg := fmt.Sprintf("please select a downgrade (version: %s):", deployMeta.Version) | ||||
| 	msg := i18n.G("please select a downgrade (version: %s):", deployMeta.Version) | ||||
|  | ||||
| 	if deployMeta.IsChaos { | ||||
| 		chaosVersion := formatter.BoldDirtyDefault(deployMeta.ChaosVersion) | ||||
|  | ||||
| 		msg = fmt.Sprintf( | ||||
| 		msg = i18n.G( | ||||
| 			"please select a downgrade (version: %s, chaos: %s):", | ||||
| 			deployMeta.Version, | ||||
| 			chaosVersion, | ||||
| @ -267,21 +267,21 @@ func validateDowngradeVersionArg( | ||||
| ) error { | ||||
| 	parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("current deployment '%s' is not a known version for %s", deployMeta.Version, app.Recipe.Name) | ||||
| 		return errors.New(i18n.G("current deployment '%s' is not a known version for %s", deployMeta.Version, app.Recipe.Name)) | ||||
| 	} | ||||
|  | ||||
| 	parsedSpecificVersion, err := tagcmp.Parse(specificVersion) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("'%s' is not a known version for %s", specificVersion, app.Recipe.Name) | ||||
| 		return errors.New(i18n.G("'%s' is not a known version for %s", specificVersion, app.Recipe.Name)) | ||||
| 	} | ||||
|  | ||||
| 	if parsedSpecificVersion.IsGreaterThan(parsedDeployedVersion) && | ||||
| 		!parsedSpecificVersion.Equals(parsedDeployedVersion) { | ||||
| 		return fmt.Errorf("%s is not a downgrade for %s?", deployMeta.Version, specificVersion) | ||||
| 		return errors.New(i18n.G("%s is not a downgrade for %s?", deployMeta.Version, specificVersion)) | ||||
| 	} | ||||
|  | ||||
| 	if parsedSpecificVersion.Equals(parsedDeployedVersion) && !internal.Force { | ||||
| 		return fmt.Errorf("%s is not a downgrade for %s?", deployMeta.Version, specificVersion) | ||||
| 		return errors.New(i18n.G("%s is not a downgrade for %s?", deployMeta.Version, specificVersion)) | ||||
| 	} | ||||
|  | ||||
| 	return nil | ||||
| @ -320,24 +320,25 @@ func ensureDowngradesAvailable( | ||||
| func init() { | ||||
| 	AppRollbackCommand.Flags().BoolVarP( | ||||
| 		&internal.Force, | ||||
| 		"force", | ||||
| 		"f", | ||||
| 		i18n.G("force"), | ||||
| 		i18n.G("f"), | ||||
| 		false, | ||||
| 		"perform action without further prompt", | ||||
| 		i18n.G("perform action without further prompt"), | ||||
| 	) | ||||
|  | ||||
| 	AppRollbackCommand.Flags().BoolVarP( | ||||
| 		&internal.NoDomainChecks, | ||||
| 		"no-domain-checks", | ||||
| 		"D", | ||||
| 		i18n.G("no-domain-checks"), | ||||
| 		i18n.G("D"), | ||||
| 		false, | ||||
| 		"disable public DNS checks", | ||||
| 		i18n.G("disable public DNS checks"), | ||||
| 	) | ||||
|  | ||||
| 	AppRollbackCommand.Flags().BoolVarP( | ||||
| 		&internal.DontWaitConverge, "no-converge-checks", | ||||
| 		"c", | ||||
| 		&internal.DontWaitConverge, | ||||
| 		i18n.G("no-converge-checks"), | ||||
| 		i18n.G("c"), | ||||
| 		false, | ||||
| 		"disable converge logic checks", | ||||
| 		i18n.G("disable converge logic checks"), | ||||
| 	) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user