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 updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/envfile"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/lint"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/abra/pkg/upstream/convert"
|
||||
@ -30,14 +32,14 @@ const SERVER = "localhost"
|
||||
|
||||
// NotifyCommand checks for available upgrades.
|
||||
var NotifyCommand = &cobra.Command{
|
||||
Use: "notify [flags]",
|
||||
Aliases: []string{"n"},
|
||||
Short: "Check for available upgrades",
|
||||
Long: `Notify on new versions for deployed apps.
|
||||
Use: i18n.G("notify [flags]"),
|
||||
Aliases: []string{i18n.G("n")},
|
||||
Short: i18n.G("Check for available upgrades"),
|
||||
Long: i18n.G(`Notify on new versions for deployed apps.
|
||||
|
||||
If a new patch/minor version is available, a notification is printed.
|
||||
|
||||
Use "--major/-m" to include new major versions.`,
|
||||
Use "--major/-m" to include new major versions.`),
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cl, err := client.New("default")
|
||||
@ -69,10 +71,10 @@ Use "--major/-m" to include new major versions.`,
|
||||
|
||||
// UpgradeCommand upgrades apps.
|
||||
var UpgradeCommand = &cobra.Command{
|
||||
Use: "upgrade [[stack] [recipe] | --all] [flags]",
|
||||
Aliases: []string{"u"},
|
||||
Short: "Upgrade apps",
|
||||
Long: `Upgrade an app by specifying stack name and recipe.
|
||||
Use: i18n.G("upgrade [[stack] [recipe] | --all] [flags]"),
|
||||
Aliases: []string{i18n.G("u")},
|
||||
Short: i18n.G("Upgrade apps"),
|
||||
Long: i18n.G(`Upgrade an app by specifying stack name and recipe.
|
||||
|
||||
Use "--all" to upgrade every deployed app.
|
||||
|
||||
@ -83,7 +85,7 @@ available, the app is upgraded.
|
||||
To include major versions use the "--major/-m" flag. You probably don't want
|
||||
that as it will break things. Only apps that are not deployed with "--chaos/-C"
|
||||
are upgraded, to update chaos deployments use the "--chaos/-C" flag. Use it
|
||||
with care.`,
|
||||
with care.`),
|
||||
Args: cobra.RangeArgs(0, 2),
|
||||
// TODO(d1): complete stack/recipe
|
||||
// ValidArgsFunction: func(
|
||||
@ -98,7 +100,7 @@ with care.`,
|
||||
}
|
||||
|
||||
if !updateAll && len(args) != 2 {
|
||||
log.Fatal("missing arguments or --all/-a flag")
|
||||
log.Fatal(i18n.G("missing arguments or --all/-a flag"))
|
||||
}
|
||||
|
||||
if !updateAll {
|
||||
@ -150,7 +152,7 @@ func getLabel(cl *dockerclient.Client, stackName string, label string) (string,
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("no %s label found for %s", label, stackName)
|
||||
log.Debug(i18n.G("no %s label found for %s", label, stackName))
|
||||
|
||||
return "", nil
|
||||
}
|
||||
@ -171,7 +173,7 @@ func getBoolLabel(cl *dockerclient.Client, stackName string, label string) (bool
|
||||
return value, nil
|
||||
}
|
||||
|
||||
log.Debugf("boolean label %s could not be found for %s, set default to false.", label, stackName)
|
||||
log.Debug(i18n.G("boolean label %s could not be found for %s, set default to false.", label, stackName))
|
||||
|
||||
return false, nil
|
||||
}
|
||||
@ -192,12 +194,12 @@ func getEnv(cl *dockerclient.Client, stackName string) (envfile.AppEnv, error) {
|
||||
for _, envString := range envList {
|
||||
splitString := strings.SplitN(envString, "=", 2)
|
||||
if len(splitString) != 2 {
|
||||
log.Debugf("can't separate key from value: %s (this variable is probably unset)", envString)
|
||||
log.Debug(i18n.G("can't separate key from value: %s (this variable is probably unset)", envString))
|
||||
continue
|
||||
}
|
||||
k := splitString[0]
|
||||
v := splitString[1]
|
||||
log.Debugf("for %s read env %s with value: %s from docker service", stackName, k, v)
|
||||
log.Debugf(i18n.G("for %s read env %s with value: %s from docker service", stackName, k, v))
|
||||
envMap[k] = v
|
||||
}
|
||||
}
|
||||
@ -219,14 +221,14 @@ func getLatestUpgrade(cl *dockerclient.Client, stackName string, recipeName stri
|
||||
}
|
||||
|
||||
if len(availableUpgrades) == 0 {
|
||||
log.Debugf("no available upgrades for %s", stackName)
|
||||
log.Debugf(i18n.G("no available upgrades for %s", stackName))
|
||||
return "", nil
|
||||
}
|
||||
|
||||
var chosenUpgrade string
|
||||
if len(availableUpgrades) > 0 {
|
||||
chosenUpgrade = availableUpgrades[len(availableUpgrades)-1]
|
||||
log.Infof("%s (%s) can be upgraded from version %s to %s", stackName, recipeName, deployedVersion, chosenUpgrade)
|
||||
log.Info(i18n.G("%s (%s) can be upgraded from version %s to %s", stackName, recipeName, deployedVersion, chosenUpgrade))
|
||||
}
|
||||
|
||||
return chosenUpgrade, nil
|
||||
@ -234,7 +236,7 @@ func getLatestUpgrade(cl *dockerclient.Client, stackName string, recipeName stri
|
||||
|
||||
// getDeployedVersion returns the currently deployed version of an app.
|
||||
func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName string) (string, error) {
|
||||
log.Debugf("retrieve deployed version whether %s is already deployed", stackName)
|
||||
log.Debug(i18n.G("retrieve deployed version whether %s is already deployed", stackName))
|
||||
|
||||
deployMeta, err := stack.IsDeployed(context.Background(), cl, stackName)
|
||||
if err != nil {
|
||||
@ -242,11 +244,11 @@ func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName st
|
||||
}
|
||||
|
||||
if !deployMeta.IsDeployed {
|
||||
return "", fmt.Errorf("%s is not deployed?", stackName)
|
||||
return "", errors.New(i18n.G("%s is not deployed?", stackName))
|
||||
}
|
||||
|
||||
if deployMeta.Version == "unknown" {
|
||||
return "", fmt.Errorf("failed to determine deployed version of %s", stackName)
|
||||
return "", errors.New(i18n.G("failed to determine deployed version of %s", stackName))
|
||||
}
|
||||
|
||||
return deployMeta.Version, nil
|
||||
@ -268,7 +270,7 @@ func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName
|
||||
}
|
||||
|
||||
if len(versions) == 0 {
|
||||
log.Warnf("no published releases for %s in the recipe catalogue?", recipeName)
|
||||
log.Warn(i18n.G("no published releases for %s in the recipe catalogue?", recipeName))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@ -294,7 +296,7 @@ func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("available updates for %s: %s", stackName, availableUpgrades)
|
||||
log.Debug(i18n.G("available updates for %s: %s", stackName, availableUpgrades))
|
||||
|
||||
return availableUpgrades, nil
|
||||
}
|
||||
@ -371,7 +373,7 @@ func createDeployConfig(r recipe.Recipe, stackName string, env envfile.AppEnv) (
|
||||
// tryUpgrade performs the upgrade if all the requirements are fulfilled.
|
||||
func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
|
||||
if recipeName == "" {
|
||||
log.Debugf("don't update %s due to missing recipe name", stackName)
|
||||
log.Debug(i18n.G("don't update %s due to missing recipe name", stackName))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -381,7 +383,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
|
||||
}
|
||||
|
||||
if chaos && !internal.Chaos {
|
||||
log.Debugf("don't update %s due to chaos deployment", stackName)
|
||||
log.Debug(i18n.G("don't update %s due to chaos deployment", stackName))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -391,7 +393,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
|
||||
}
|
||||
|
||||
if !updatesEnabled {
|
||||
log.Debugf("don't update %s due to disabled auto updates or missing ENABLE_AUTO_UPDATE env", stackName)
|
||||
log.Debug(i18n.G("don't update %s due to disabled auto updates or missing ENABLE_AUTO_UPDATE env", stackName))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -401,7 +403,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
|
||||
}
|
||||
|
||||
if upgradeVersion == "" {
|
||||
log.Debugf("don't update %s due to no new version", stackName)
|
||||
log.Debug(i18n.G("don't update %s due to no new version", stackName))
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -439,7 +441,7 @@ func upgrade(cl *dockerclient.Client, stackName, recipeName, upgradeVersion stri
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("upgrade %s (%s) to version %s", stackName, recipeName, upgradeVersion)
|
||||
log.Info(i18n.G("upgrade %s (%s) to version %s", stackName, recipeName, upgradeVersion))
|
||||
|
||||
serviceNames, err := appPkg.GetAppServiceNames(app.Name)
|
||||
if err != nil {
|
||||
@ -466,9 +468,9 @@ func upgrade(cl *dockerclient.Client, stackName, recipeName, upgradeVersion stri
|
||||
|
||||
func newKadabraApp(version, commit string) *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "kadabra [cmd] [flags]",
|
||||
Use: i18n.G("kadabra [cmd] [flags]"),
|
||||
Version: fmt.Sprintf("%s-%s", version, commit[:7]),
|
||||
Short: "The Co-op Cloud auto-updater 🤖 🚀",
|
||||
Short: i18n.G("The Co-op Cloud auto-updater 🤖 🚀"),
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
log.Logger.SetStyles(charmLog.DefaultStyles())
|
||||
charmLog.SetDefault(log.Logger)
|
||||
@ -479,18 +481,24 @@ func newKadabraApp(version, commit string) *cobra.Command {
|
||||
log.SetReportCaller(true)
|
||||
}
|
||||
|
||||
log.Debugf("kadabra version %s, commit %s", version, commit)
|
||||
log.Debug(i18n.G("kadabra version %s, commit %s", version, commit))
|
||||
},
|
||||
}
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
&internal.Debug, "debug", "d", false,
|
||||
"show debug messages",
|
||||
&internal.Debug,
|
||||
i18n.G("debug"),
|
||||
i18n.G("d"),
|
||||
false,
|
||||
i18n.G("show debug messages"),
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(
|
||||
&internal.NoInput, "no-input", "n", false,
|
||||
"toggle non-interactive mode",
|
||||
&internal.NoInput,
|
||||
i18n.G("no-input"),
|
||||
i18n.G("n"),
|
||||
false,
|
||||
i18n.G("toggle non-interactive mode"),
|
||||
)
|
||||
|
||||
rootCmd.AddCommand(
|
||||
@ -526,25 +534,25 @@ func init() {
|
||||
|
||||
UpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Chaos,
|
||||
"chaos",
|
||||
"C",
|
||||
i18n.G("chaos"),
|
||||
i18n.G("C"),
|
||||
false,
|
||||
"ignore uncommitted recipes changes",
|
||||
i18n.G("ignore uncommitted recipes changes"),
|
||||
)
|
||||
|
||||
UpgradeCommand.Flags().BoolVarP(
|
||||
&includeMajorUpdates,
|
||||
"major",
|
||||
"m",
|
||||
i18n.G("major"),
|
||||
i18n.G("m"),
|
||||
false,
|
||||
"check for major updates",
|
||||
i18n.G("check for major updates"),
|
||||
)
|
||||
|
||||
UpgradeCommand.Flags().BoolVarP(
|
||||
&updateAll,
|
||||
"all",
|
||||
"a",
|
||||
i18n.G("all"),
|
||||
i18n.G("a"),
|
||||
false,
|
||||
"update all deployed apps",
|
||||
i18n.G("update all deployed apps"),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user