feat: translation support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
See #483
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/tagcmp"
|
||||
@ -37,10 +38,10 @@ type anUpgrade struct {
|
||||
}
|
||||
|
||||
var RecipeUpgradeCommand = &cobra.Command{
|
||||
Use: "upgrade <recipe> [flags]",
|
||||
Aliases: []string{"u"},
|
||||
Short: "Upgrade recipe image tags",
|
||||
Long: `Upgrade a given <recipe> configuration.
|
||||
Use: i18n.G("upgrade <recipe> [flags]"),
|
||||
Aliases: []string{i18n.G("u")},
|
||||
Short: i18n.G("Upgrade recipe image tags"),
|
||||
Long: i18n.G(`Upgrade a given <recipe> configuration.
|
||||
|
||||
It will update the relevant compose file tags on the local file system.
|
||||
|
||||
@ -52,7 +53,7 @@ The command is interactive and will show a select input which allows you to
|
||||
make a seclection. Use the "?" key to see more help on navigating this
|
||||
interface.
|
||||
|
||||
You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
You may invoke this command in "wizard" mode and be prompted for input.`),
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
ValidArgsFunction: func(
|
||||
cmd *cobra.Command,
|
||||
@ -71,7 +72,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
if bumpType != 0 {
|
||||
// a bitwise check if the number is a power of 2
|
||||
if (bumpType & (bumpType - 1)) != 0 {
|
||||
log.Fatal("you can only use one of: --major, --minor, --patch.")
|
||||
log.Fatal(i18n.G("you can only use one of: --major, --minor, --patch."))
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
versionsPath := path.Join(recipe.Dir, "versions")
|
||||
servicePins := make(map[string]imgPin)
|
||||
if _, err := os.Stat(versionsPath); err == nil {
|
||||
log.Debugf("found versions file for %s", recipe.Name)
|
||||
log.Debug(i18n.G("found versions file for %s", recipe.Name))
|
||||
file, err := os.Open(versionsPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -97,7 +98,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
line := scanner.Text()
|
||||
splitLine := strings.Split(line, " ")
|
||||
if splitLine[0] != "pin" || len(splitLine) != 3 {
|
||||
log.Fatalf("malformed version pin specification: %s", line)
|
||||
log.Fatal(i18n.G("malformed version pin specification: %s", line))
|
||||
}
|
||||
pinSlice := strings.Split(splitLine[2], ":")
|
||||
pinTag, err := tagcmp.Parse(pinSlice[1])
|
||||
@ -115,7 +116,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
versionsPresent = true
|
||||
} else {
|
||||
log.Debugf("did not find versions file for %s", recipe.Name)
|
||||
log.Debug(i18n.G("did not find versions file for %s", recipe.Name))
|
||||
}
|
||||
|
||||
config, err := recipe.GetComposeConfig(nil)
|
||||
@ -135,26 +136,26 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
|
||||
image := reference.Path(img)
|
||||
log.Debugf("retrieved %s from remote registry for %s", regVersions, image)
|
||||
log.Debug(i18n.G("retrieved %s from remote registry for %s", regVersions, image))
|
||||
image = formatter.StripTagMeta(image)
|
||||
|
||||
switch img.(type) {
|
||||
case reference.NamedTagged:
|
||||
if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) {
|
||||
log.Debugf("%s not considered semver-like", img.(reference.NamedTagged).Tag())
|
||||
log.Debug(i18n.G("%s not considered semver-like", img.(reference.NamedTagged).Tag()))
|
||||
}
|
||||
default:
|
||||
log.Warnf("unable to read tag for image %s, is it missing? skipping upgrade for %s", image, service.Name)
|
||||
log.Warn(i18n.G("unable to read tag for image %s, is it missing? skipping upgrade for %s", image, service.Name))
|
||||
continue
|
||||
}
|
||||
|
||||
tag, err := tagcmp.Parse(img.(reference.NamedTagged).Tag())
|
||||
if err != nil {
|
||||
log.Warnf("unable to parse %s, error was: %s, skipping upgrade for %s", image, err.Error(), service.Name)
|
||||
log.Warn(i18n.G("unable to parse %s, error was: %s, skipping upgrade for %s", image, err.Error(), service.Name))
|
||||
continue
|
||||
}
|
||||
|
||||
log.Debugf("parsed %s for %s", tag, service.Name)
|
||||
log.Debug(i18n.G("parsed %s for %s", tag, service.Name))
|
||||
|
||||
var compatible []tagcmp.Tag
|
||||
for _, regVersion := range regVersions {
|
||||
@ -168,12 +169,12 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("detected potential upgradable tags %s for %s", compatible, service.Name)
|
||||
log.Debug(i18n.G("detected potential upgradable tags %s for %s", compatible, service.Name))
|
||||
|
||||
sort.Sort(tagcmp.ByTagDesc(compatible))
|
||||
|
||||
if len(compatible) == 0 && !allTags {
|
||||
log.Info(fmt.Sprintf("no new versions available for %s, assuming %s is the latest (use -a/--all-tags to see all anyway)", image, tag))
|
||||
log.Info(i18n.G("no new versions available for %s, assuming %s is the latest (use -a/--all-tags to see all anyway)", image, tag))
|
||||
continue // skip on to the next tag and don't update any compose files
|
||||
}
|
||||
|
||||
@ -195,7 +196,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("detected compatible upgradable tags %s for %s", compatibleStrings, service.Name)
|
||||
log.Debug(i18n.G("detected compatible upgradable tags %s for %s", compatibleStrings, service.Name))
|
||||
|
||||
var upgradeTag string
|
||||
_, ok := servicePins[service.Name]
|
||||
@ -212,13 +213,13 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
}
|
||||
if contains {
|
||||
log.Infof("upgrading service %s from %s to %s (pinned tag: %s)", service.Name, tag.String(), upgradeTag, pinnedTagString)
|
||||
log.Info(i18n.G("upgrading service %s from %s to %s (pinned tag: %s)", service.Name, tag.String(), upgradeTag, pinnedTagString))
|
||||
} else {
|
||||
log.Infof("service %s, image %s pinned to %s, no compatible upgrade found", service.Name, servicePins[service.Name].image, pinnedTagString)
|
||||
log.Info(i18n.G("service %s, image %s pinned to %s, no compatible upgrade found", service.Name, servicePins[service.Name].image, pinnedTagString))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
log.Fatalf("service %s is at version %s, but pinned to %s, please correct your compose.yml file manually!", service.Name, tag.String(), pinnedTag.String())
|
||||
log.Fatal(i18n.G("service %s is at version %s, but pinned to %s, please correct your compose.yml file manually!", service.Name, tag.String(), pinnedTag.String()))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
@ -235,17 +236,17 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
}
|
||||
if upgradeTag == "" {
|
||||
log.Warnf("not upgrading from %s to %s for %s, because the upgrade type is more serious than what user wants", tag.String(), compatible[0].String(), image)
|
||||
log.Warn(i18n.G("not upgrading from %s to %s for %s, because the upgrade type is more serious than what user wants", tag.String(), compatible[0].String(), image))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
msg := fmt.Sprintf("upgrade to which tag? (service: %s, image: %s, tag: %s)", service.Name, image, tag)
|
||||
msg := i18n.G("upgrade to which tag? (service: %s, image: %s, tag: %s)", service.Name, image, tag)
|
||||
if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) || allTags {
|
||||
tag := img.(reference.NamedTagged).Tag()
|
||||
if !allTags {
|
||||
log.Warn(fmt.Sprintf("unable to determine versioning semantics of %s, listing all tags", tag))
|
||||
log.Warn(i18n.G("unable to determine versioning semantics of %s, listing all tags", tag))
|
||||
}
|
||||
msg = fmt.Sprintf("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag)
|
||||
msg = i18n.G("upgrade to which tag? (service: %s, tag: %s)", service.Name, tag)
|
||||
compatibleStrings = []string{"skip"}
|
||||
for _, regVersion := range regVersions {
|
||||
compatibleStrings = append(compatibleStrings, regVersion)
|
||||
@ -276,7 +277,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
} else {
|
||||
prompt := &survey.Select{
|
||||
Message: msg,
|
||||
Help: "enter / return to confirm, choose 'skip' to not upgrade this tag, vim mode is enabled",
|
||||
Help: i18n.G("enter / return to confirm, choose 'skip' to not upgrade this tag, vim mode is enabled"),
|
||||
VimMode: true,
|
||||
Options: compatibleStrings,
|
||||
}
|
||||
@ -292,11 +293,11 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
log.Fatal(err)
|
||||
}
|
||||
if ok {
|
||||
log.Infof("tag upgraded from %s to %s for %s", tag.String(), upgradeTag, image)
|
||||
log.Info(i18n.G("tag upgraded from %s to %s for %s", tag.String(), upgradeTag, image))
|
||||
}
|
||||
} else {
|
||||
if !internal.NoInput {
|
||||
log.Warnf("not upgrading %s, skipping as requested", image)
|
||||
log.Warn(i18n.G("not upgrading %s, skipping as requested", image))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -314,7 +315,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
}
|
||||
|
||||
for _, upgrade := range upgradeList {
|
||||
log.Infof("can upgrade service: %s, image: %s, tag: %s ::", upgrade.Service, upgrade.Image, upgrade.Tag)
|
||||
log.Info(i18n.G("can upgrade service: %s, image: %s, tag: %s ::", upgrade.Service, upgrade.Image, upgrade.Tag))
|
||||
for _, utag := range upgrade.UpgradeTags {
|
||||
log.Infof(" %s", utag)
|
||||
}
|
||||
@ -326,7 +327,7 @@ You may invoke this command in "wizard" mode and be prompted for input.`,
|
||||
log.Fatal(err)
|
||||
}
|
||||
if !isClean {
|
||||
log.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||
log.Info(i18n.G("%s currently has these unstaged changes 👇", recipe.Name))
|
||||
if err := gitPkg.DiffUnstaged(recipe.Dir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -341,41 +342,41 @@ var (
|
||||
func init() {
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Major,
|
||||
"major",
|
||||
"x",
|
||||
i18n.G("major"),
|
||||
i18n.G("x"),
|
||||
false,
|
||||
"increase the major part of the version",
|
||||
i18n.G("increase the major part of the version"),
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Minor,
|
||||
"minor",
|
||||
"y",
|
||||
i18n.G("minor"),
|
||||
i18n.G("y"),
|
||||
false,
|
||||
"increase the minor part of the version",
|
||||
i18n.G("increase the minor part of the version"),
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.Patch,
|
||||
"patch",
|
||||
"z",
|
||||
i18n.G("patch"),
|
||||
i18n.G("z"),
|
||||
false,
|
||||
"increase the patch part of the version",
|
||||
i18n.G("increase the patch part of the version"),
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&internal.MachineReadable,
|
||||
"machine",
|
||||
"m",
|
||||
i18n.G("machine"),
|
||||
i18n.G("m"),
|
||||
false,
|
||||
"print machine-readable output",
|
||||
i18n.G("print machine-readable output"),
|
||||
)
|
||||
|
||||
RecipeUpgradeCommand.Flags().BoolVarP(
|
||||
&allTags,
|
||||
"all-tags",
|
||||
"a",
|
||||
i18n.G("all-tags"),
|
||||
i18n.G("a"),
|
||||
false,
|
||||
"list all tags, not just upgrades",
|
||||
i18n.G("list all tags, not just upgrades"),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user