WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
See #483
This commit is contained in:
@ -2,6 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -13,6 +14,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"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
@ -24,10 +26,10 @@ import (
|
||||
)
|
||||
|
||||
var AppUpgradeCommand = &cobra.Command{
|
||||
Use: "upgrade <domain> [version] [flags]",
|
||||
Aliases: []string{"up"},
|
||||
Short: "Upgrade an app",
|
||||
Long: `Upgrade an app.
|
||||
Use: i18n.G("upgrade <domain> [version] [flags]"),
|
||||
Aliases: []string{i18n.G("up")},
|
||||
Short: i18n.G("Upgrade an app"),
|
||||
Long: i18n.G(`Upgrade an app.
|
||||
|
||||
Unlike "abra app deploy", chaos operations are not supported here. Only recipe
|
||||
versions are supported values for "[version]".
|
||||
@ -40,7 +42,7 @@ are available. The live deployment version is the "source of truth" in this
|
||||
case. The stored .env version is not consulted.
|
||||
|
||||
An upgrade can be destructive, please ensure you have a copy of your app data
|
||||
beforehand. See "abra app backup" for more.`,
|
||||
beforehand. See "abra app backup" for more.`),
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
@ -53,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:
|
||||
@ -123,7 +124,7 @@ beforehand. See "abra app backup" for more.`,
|
||||
}
|
||||
|
||||
if !upgradeAvailable {
|
||||
log.Info("no available upgrades")
|
||||
log.Info(i18n.G("no available upgrades"))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -145,10 +146,10 @@ beforehand. See "abra app backup" for more.`,
|
||||
}
|
||||
|
||||
if chosenUpgrade == "" {
|
||||
log.Fatal("unknown deployed version, unable to upgrade")
|
||||
log.Fatal(i18n.G("unknown deployed version, unable to upgrade"))
|
||||
}
|
||||
|
||||
log.Debugf("choosing %s as version to upgrade", chosenUpgrade)
|
||||
log.Debug(i18n.G("choosing %s as version to upgrade", chosenUpgrade))
|
||||
|
||||
// Get the release notes before checking out the new version in the
|
||||
// recipe. This enables us to get release notes, that were added after
|
||||
@ -204,7 +205,7 @@ beforehand. See "abra app backup" for more.`,
|
||||
for _, envVar := range envVars {
|
||||
if !envVar.Present {
|
||||
upgradeWarnMessages = append(upgradeWarnMessages,
|
||||
fmt.Sprintf("%s missing from %s.env", envVar.Name, app.Domain),
|
||||
i18n.G("%s missing from %s.env", envVar.Name, app.Domain),
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -236,7 +237,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 {
|
||||
@ -262,15 +263,15 @@ beforehand. See "abra app backup" for more.`,
|
||||
|
||||
postDeployCmds, ok := app.Env["POST_UPGRADE_CMDS"]
|
||||
if ok && !internal.DontWaitConverge {
|
||||
log.Debugf("run the following post-deploy commands: %s", postDeployCmds)
|
||||
log.Debug(i18n.G("run the following post-deploy commands: %s", postDeployCmds))
|
||||
|
||||
if err := internal.PostCmds(cl, app, postDeployCmds); err != nil {
|
||||
log.Fatalf("attempting to run post deploy commands, saw: %s", err)
|
||||
log.Fatal(i18n.G("attempting to run post deploy commands, saw: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
if err := app.WriteRecipeVersion(chosenUpgrade, false); err != nil {
|
||||
log.Fatalf("writing recipe version failed: %s", err)
|
||||
log.Fatal(i18n.G("writing recipe version failed: %s", err))
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -281,12 +282,12 @@ func chooseUpgrade(
|
||||
deployMeta stack.DeployMeta,
|
||||
chosenUpgrade *string,
|
||||
) error {
|
||||
msg := fmt.Sprintf("please select an upgrade (version: %s):", deployMeta.Version)
|
||||
msg := i18n.G("please select an upgrade (version: %s):", deployMeta.Version)
|
||||
|
||||
if deployMeta.IsChaos {
|
||||
chaosVersion := formatter.BoldDirtyDefault(deployMeta.ChaosVersion)
|
||||
|
||||
msg = fmt.Sprintf(
|
||||
msg = i18n.G(
|
||||
"please select an upgrade (version: %s, chaos: %s):",
|
||||
deployMeta.Version,
|
||||
chaosVersion,
|
||||
@ -314,18 +315,18 @@ func getReleaseNotes(
|
||||
) error {
|
||||
parsedChosenUpgrade, err := tagcmp.Parse(chosenUpgrade)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing chosen upgrade version failed: %s", err)
|
||||
return errors.New(i18n.G("parsing chosen upgrade version failed: %s", err))
|
||||
}
|
||||
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing deployment version failed: %s", err)
|
||||
return errors.New(i18n.G("parsing deployment version failed: %s", err))
|
||||
}
|
||||
|
||||
for _, version := range internal.SortVersionsDesc(versions) {
|
||||
parsedVersion, err := tagcmp.Parse(version)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing recipe version failed: %s", err)
|
||||
return errors.New(i18n.G("parsing recipe version failed: %s", err))
|
||||
}
|
||||
|
||||
if parsedVersion.IsGreaterThan(parsedDeployedVersion) &&
|
||||
@ -358,13 +359,13 @@ func ensureUpgradesAvailable(
|
||||
) (bool, error) {
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("parsing deployed version failed: %s", err)
|
||||
return false, errors.New(i18n.G("parsing deployed version failed: %s", err))
|
||||
}
|
||||
|
||||
for _, version := range versions {
|
||||
parsedVersion, err := tagcmp.Parse(version)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("parsing recipe version failed: %s", err)
|
||||
return false, errors.New(i18n.G("parsing recipe version failed: %s", err))
|
||||
}
|
||||
|
||||
if parsedVersion.IsGreaterThan(parsedDeployedVersion) &&
|
||||
@ -388,21 +389,21 @@ func validateUpgradeVersionArg(
|
||||
) error {
|
||||
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))
|
||||
}
|
||||
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s' is not a known version", deployMeta.Version)
|
||||
return errors.New(i18n.G("'%s' is not a known version", deployMeta.Version))
|
||||
}
|
||||
|
||||
if parsedSpecificVersion.IsLessThan(parsedDeployedVersion) &&
|
||||
!parsedSpecificVersion.Equals(parsedDeployedVersion) {
|
||||
return fmt.Errorf("%s is not an upgrade for %s?", deployMeta.Version, specificVersion)
|
||||
return errors.New(i18n.G("%s is not an upgrade for %s?", deployMeta.Version, specificVersion))
|
||||
}
|
||||
|
||||
if parsedSpecificVersion.Equals(parsedDeployedVersion) && !internal.Force {
|
||||
return fmt.Errorf("%s is not an upgrade for %s?", deployMeta.Version, specificVersion)
|
||||
return errors.New(i18n.G("%s is not an upgrade for %s?", deployMeta.Version, specificVersion))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -411,7 +412,7 @@ func validateUpgradeVersionArg(
|
||||
// ensureDeployed ensures the app is deployed and if so, returns deployment
|
||||
// meta info.
|
||||
func ensureDeployed(cl *dockerClient.Client, app app.App) (stack.DeployMeta, error) {
|
||||
log.Debugf("checking whether %s is already deployed", app.StackName())
|
||||
log.Debug(i18n.G("checking whether %s is already deployed", app.StackName()))
|
||||
|
||||
deployMeta, err := stack.IsDeployed(context.Background(), cl, app.StackName())
|
||||
if err != nil {
|
||||
@ -419,7 +420,7 @@ func ensureDeployed(cl *dockerClient.Client, app app.App) (stack.DeployMeta, err
|
||||
}
|
||||
|
||||
if !deployMeta.IsDeployed {
|
||||
return stack.DeployMeta{}, fmt.Errorf("%s is not deployed?", app.Name)
|
||||
return stack.DeployMeta{}, errors.New(i18n.G("%s is not deployed?", app.Name))
|
||||
}
|
||||
|
||||
return deployMeta, nil
|
||||
@ -430,32 +431,33 @@ var showReleaseNotes bool
|
||||
func init() {
|
||||
AppUpgradeCommand.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"),
|
||||
)
|
||||
|
||||
AppUpgradeCommand.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"),
|
||||
)
|
||||
|
||||
AppUpgradeCommand.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"),
|
||||
)
|
||||
|
||||
AppUpgradeCommand.Flags().BoolVarP(
|
||||
&showReleaseNotes,
|
||||
"releasenotes",
|
||||
"r",
|
||||
i18n.G("releasenotes"),
|
||||
i18n.G("r"),
|
||||
false,
|
||||
"only show release notes",
|
||||
i18n.G("only show release notes"),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user