feat: translation support
All checks were successful
continuous-integration/drone/push Build is passing

See #483
This commit is contained in:
2025-08-19 11:22:52 +02:00
parent 5cf6048ecb
commit ff32c06676
49 changed files with 466 additions and 405 deletions

View File

@ -3,6 +3,7 @@
[![Build Status](https://build.coopcloud.tech/api/badges/toolshed/abra/status.svg?ref=refs/heads/main)](https://build.coopcloud.tech/toolshed/abra) [![Build Status](https://build.coopcloud.tech/api/badges/toolshed/abra/status.svg?ref=refs/heads/main)](https://build.coopcloud.tech/toolshed/abra)
[![Go Report Card](https://goreportcard.com/badge/git.coopcloud.tech/toolshed/abra)](https://goreportcard.com/report/git.coopcloud.tech/toolshed/abra) [![Go Report Card](https://goreportcard.com/badge/git.coopcloud.tech/toolshed/abra)](https://goreportcard.com/report/git.coopcloud.tech/toolshed/abra)
[![Go Reference](https://pkg.go.dev/badge/coopcloud.tech/abra.svg)](https://pkg.go.dev/coopcloud.tech/abra) [![Go Reference](https://pkg.go.dev/badge/coopcloud.tech/abra.svg)](https://pkg.go.dev/coopcloud.tech/abra)
[![Translation status](https://translate.coopcloud.tech/widget/co-op-cloud/svg-badge.svg)](https://translate.coopcloud.tech/engage/co-op-cloud/)
The Co-op Cloud utility belt 🎩🐇 The Co-op Cloud utility belt 🎩🐇

View File

@ -3,13 +3,14 @@ package cli
import ( import (
"os" "os"
"github.com/leonelquinteros/gotext"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var AutocompleteCommand = &cobra.Command{ var AutocompleteCommand = &cobra.Command{
Use: "autocomplete [bash|zsh|fish|powershell]", Use: gotext.Get("autocomplete [bash|zsh|fish|powershell]"),
Short: "Generate autocompletion script", Short: gotext.Get("Generate autocompletion script"),
Long: `To load completions: Long: gotext.Get(`To load completions:
Bash: Bash:
# Load autocompletion for the current Bash session # Load autocompletion for the current Bash session
@ -43,7 +44,7 @@ PowerShell:
# To load autocompletions for every new session, run: # To load autocompletions for every new session, run:
PS> abra autocomplete powershell > abra.ps1 PS> abra autocomplete powershell > abra.ps1
# and source this file from your PowerShell profile.`, # and source this file from your PowerShell profile.`),
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"}, ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),

View File

@ -12,23 +12,24 @@ import (
"coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
charmLog "github.com/charmbracelet/log" charmLog "github.com/charmbracelet/log"
"github.com/leonelquinteros/gotext"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/cobra/doc" "github.com/spf13/cobra/doc"
) )
func Run(version, commit string) { func Run(version, commit string) {
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "abra [cmd] [args] [flags]", Use: gotext.Get("abra [cmd] [args] [flags]"),
Short: "The Co-op Cloud command-line utility belt 🎩🐇", Short: gotext.Get("The Co-op Cloud command-line utility belt 🎩🐇"),
Version: fmt.Sprintf("%s-%s", version, commit[:7]), Version: fmt.Sprintf("%s-%s", version, commit[:7]),
ValidArgs: []string{ ValidArgs: []string{
"app", gotext.Get("app"),
"autocomplete", gotext.Get("autocomplete"),
"catalogue", gotext.Get("catalogue"),
"man", gotext.Get("man"),
"recipe", gotext.Get("recipe"),
"server", gotext.Get("server"),
"upgrade", gotext.Get("upgrade"),
}, },
PersistentPreRun: func(cmd *cobra.Command, args []string) { PersistentPreRun: func(cmd *cobra.Command, args []string) {
dirs := []map[string]os.FileMode{ dirs := []map[string]os.FileMode{
@ -62,24 +63,24 @@ func Run(version, commit string) {
log.SetReportCaller(true) log.SetReportCaller(true)
} }
log.Debugf("abra version %s, commit %s", version, commit) log.Debugf(gotext.Get("abra version %s, commit %s", version, commit))
}, },
} }
rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.CompletionOptions.DisableDefaultCmd = true
manCommand := &cobra.Command{ manCommand := &cobra.Command{
Use: "man [flags]", Use: gotext.Get("man [flags]"),
Aliases: []string{"m"}, Aliases: []string{"m"},
Short: "Generate manpage", Short: gotext.Get("Generate manpage"),
Example: ` # generate the man pages into /usr/local/share/man/man1 Example: gotext.Get(` # generate the man pages into /usr/local/share/man/man1
abra_path=$(which abra) # pass abra absolute path to sudo below abra_path=$(which abra) # pass abra absolute path to sudo below
sudo $abra_path man sudo $abra_path man
sudo mandb sudo mandb
# read the man pages # read the man pages
man abra man abra
man abra-app-deploy`, man abra-app-deploy`),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
header := &doc.GenManHeader{ header := &doc.GenManHeader{
Title: "ABRA", Title: "ABRA",
@ -88,7 +89,7 @@ func Run(version, commit string) {
manDir := "/usr/local/share/man/man1" manDir := "/usr/local/share/man/man1"
if _, err := os.Stat(manDir); os.IsNotExist(err) { if _, err := os.Stat(manDir); os.IsNotExist(err) {
log.Fatalf("unable to proceed, '%s' does not exist?") log.Fatal(gotext.Get("unable to proceed, %s does not exist?", manDir))
} }
err := doc.GenManTree(rootCmd, header, manDir) err := doc.GenManTree(rootCmd, header, manDir)
@ -96,7 +97,7 @@ func Run(version, commit string) {
log.Fatal(err) log.Fatal(err)
} }
log.Info("don't forget to run 'sudo mandb'") log.Info(gotext.Get("don't forget to run 'sudo mandb'"))
}, },
} }
@ -105,7 +106,7 @@ func Run(version, commit string) {
"debug", "debug",
"d", "d",
false, false,
"show debug messages", gotext.Get("show debug messages"),
) )
rootCmd.PersistentFlags().BoolVarP( rootCmd.PersistentFlags().BoolVarP(
@ -113,7 +114,7 @@ func Run(version, commit string) {
"no-input", "no-input",
"n", "n",
false, false,
"toggle non-interactive mode", gotext.Get("toggle non-interactive mode"),
) )
rootCmd.PersistentFlags().BoolVarP( rootCmd.PersistentFlags().BoolVarP(
@ -121,7 +122,7 @@ func Run(version, commit string) {
"offline", "offline",
"o", "o",
false, false,
"prefer offline & filesystem access", gotext.Get("prefer offline & filesystem access"),
) )
rootCmd.PersistentFlags().BoolVarP( rootCmd.PersistentFlags().BoolVarP(
@ -129,7 +130,7 @@ func Run(version, commit string) {
"ignore-env-version", "ignore-env-version",
"i", "i",
false, false,
"ignore .env version checkout", gotext.Get("ignore .env version checkout"),
) )
catalogue.CatalogueCommand.AddCommand( catalogue.CatalogueCommand.AddCommand(

View File

@ -2,6 +2,7 @@ package updater
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
@ -21,6 +22,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
@ -30,14 +32,14 @@ const SERVER = "localhost"
// NotifyCommand checks for available upgrades. // NotifyCommand checks for available upgrades.
var NotifyCommand = &cobra.Command{ var NotifyCommand = &cobra.Command{
Use: "notify [flags]", Use: gotext.Get("notify [flags]"),
Aliases: []string{"n"}, Aliases: []string{"n"},
Short: "Check for available upgrades", Short: gotext.Get("Check for available upgrades"),
Long: `Notify on new versions for deployed apps. Long: gotext.Get(`Notify on new versions for deployed apps.
If a new patch/minor version is available, a notification is printed. 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, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cl, err := client.New("default") cl, err := client.New("default")
@ -69,10 +71,10 @@ Use "--major/-m" to include new major versions.`,
// UpgradeCommand upgrades apps. // UpgradeCommand upgrades apps.
var UpgradeCommand = &cobra.Command{ var UpgradeCommand = &cobra.Command{
Use: "upgrade [[stack] [recipe] | --all] [flags]", Use: gotext.Get("upgrade [[stack] [recipe] | --all] [flags]"),
Aliases: []string{"u"}, Aliases: []string{"u"},
Short: "Upgrade apps", Short: gotext.Get("Upgrade apps"),
Long: `Upgrade an app by specifying stack name and recipe. Long: gotext.Get(`Upgrade an app by specifying stack name and recipe.
Use "--all" to upgrade every deployed app. 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 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" 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 are upgraded, to update chaos deployments use the "--chaos/-C" flag. Use it
with care.`, with care.`),
Args: cobra.RangeArgs(0, 2), Args: cobra.RangeArgs(0, 2),
// TODO(d1): complete stack/recipe // TODO(d1): complete stack/recipe
// ValidArgsFunction: func( // ValidArgsFunction: func(
@ -98,7 +100,7 @@ with care.`,
} }
if !updateAll && len(args) != 2 { if !updateAll && len(args) != 2 {
log.Fatal("missing arguments or --all/-a flag") log.Fatal(gotext.Get("missing arguments or --all/-a flag"))
} }
if !updateAll { 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(gotext.Get("no %s label found for %s", label, stackName))
return "", nil return "", nil
} }
@ -171,7 +173,7 @@ func getBoolLabel(cl *dockerclient.Client, stackName string, label string) (bool
return value, nil return value, nil
} }
log.Debugf("boolean label %s could not be found for %s, set default to false.", label, stackName) log.Debug(gotext.Get("boolean label %s could not be found for %s, set default to false.", label, stackName))
return false, nil return false, nil
} }
@ -192,12 +194,12 @@ func getEnv(cl *dockerclient.Client, stackName string) (envfile.AppEnv, error) {
for _, envString := range envList { for _, envString := range envList {
splitString := strings.SplitN(envString, "=", 2) splitString := strings.SplitN(envString, "=", 2)
if len(splitString) != 2 { if len(splitString) != 2 {
log.Debugf("can't separate key from value: %s (this variable is probably unset)", envString) log.Debug(gotext.Get("can't separate key from value: %s (this variable is probably unset)", envString))
continue continue
} }
k := splitString[0] k := splitString[0]
v := splitString[1] v := splitString[1]
log.Debugf("for %s read env %s with value: %s from docker service", stackName, k, v) log.Debugf(gotext.Get("for %s read env %s with value: %s from docker service", stackName, k, v))
envMap[k] = v envMap[k] = v
} }
} }
@ -219,14 +221,14 @@ func getLatestUpgrade(cl *dockerclient.Client, stackName string, recipeName stri
} }
if len(availableUpgrades) == 0 { if len(availableUpgrades) == 0 {
log.Debugf("no available upgrades for %s", stackName) log.Debugf(gotext.Get("no available upgrades for %s", stackName))
return "", nil return "", nil
} }
var chosenUpgrade string var chosenUpgrade string
if len(availableUpgrades) > 0 { if len(availableUpgrades) > 0 {
chosenUpgrade = availableUpgrades[len(availableUpgrades)-1] chosenUpgrade = availableUpgrades[len(availableUpgrades)-1]
log.Infof("%s (%s) can be upgraded from version %s to %s", stackName, recipeName, deployedVersion, chosenUpgrade) log.Info(gotext.Get("%s (%s) can be upgraded from version %s to %s", stackName, recipeName, deployedVersion, chosenUpgrade))
} }
return chosenUpgrade, nil 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. // getDeployedVersion returns the currently deployed version of an app.
func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName string) (string, error) { func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName string) (string, error) {
log.Debugf("retrieve deployed version whether %s is already deployed", stackName) log.Debug(gotext.Get("retrieve deployed version whether %s is already deployed", stackName))
deployMeta, err := stack.IsDeployed(context.Background(), cl, stackName) deployMeta, err := stack.IsDeployed(context.Background(), cl, stackName)
if err != nil { if err != nil {
@ -242,11 +244,11 @@ func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName st
} }
if !deployMeta.IsDeployed { if !deployMeta.IsDeployed {
return "", fmt.Errorf("%s is not deployed?", stackName) return "", errors.New(gotext.Get("%s is not deployed?", stackName))
} }
if deployMeta.Version == "unknown" { if deployMeta.Version == "unknown" {
return "", fmt.Errorf("failed to determine deployed version of %s", stackName) return "", errors.New(gotext.Get("failed to determine deployed version of %s", stackName))
} }
return deployMeta.Version, nil return deployMeta.Version, nil
@ -268,7 +270,7 @@ func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName
} }
if len(versions) == 0 { if len(versions) == 0 {
log.Warnf("no published releases for %s in the recipe catalogue?", recipeName) log.Warn(gotext.Get("no published releases for %s in the recipe catalogue?", recipeName))
return nil, nil 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(gotext.Get("available updates for %s: %s", stackName, availableUpgrades))
return availableUpgrades, nil return availableUpgrades, nil
} }

View File

@ -7,22 +7,23 @@ import (
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// UpgradeCommand upgrades abra in-place. // UpgradeCommand upgrades abra in-place.
var UpgradeCommand = &cobra.Command{ var UpgradeCommand = &cobra.Command{
Use: "upgrade [flags]", Use: gotext.Get("upgrade [flags]"),
Aliases: []string{"u"}, Aliases: []string{"u"},
Short: "Upgrade abra", Short: gotext.Get("Upgrade abra"),
Long: `Upgrade abra in-place with the latest stable or release candidate. Long: gotext.Get(`Upgrade abra in-place with the latest stable or release candidate.
By default, the latest stable release is downloaded. By default, the latest stable release is downloaded.
Use "--rc/-r" to install the latest release candidate. Please bear in mind that Use "--rc/-r" to install the latest release candidate. Please bear in mind that
it may contain absolutely catastrophic deal-breaker bugs. Thank you very much it may contain absolutely catastrophic deal-breaker bugs. Thank you very much
for the testing efforts 💗`, for the testing efforts 💗`),
Example: " abra upgrade --rc", Example: gotext.Get(" abra upgrade --rc"),
Args: cobra.NoArgs, Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
mainURL := "https://install.abra.coopcloud.tech" mainURL := "https://install.abra.coopcloud.tech"
@ -33,7 +34,7 @@ for the testing efforts 💗`,
c = exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash -s -- --rc", releaseCandidateURL)) c = exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash -s -- --rc", releaseCandidateURL))
} }
log.Debugf("attempting to run %s", c) log.Debugf(gotext.Get("attempting to run %s", c))
if err := internal.RunCmd(c); err != nil { if err := internal.RunCmd(c); err != nil {
log.Fatal(err) log.Fatal(err)
@ -51,6 +52,6 @@ func init() {
"rc", "rc",
"r", "r",
false, false,
"install release candidate (may contain bugs)", gotext.Get("install release candidate (may contain bugs)"),
) )
} }

View File

@ -1,12 +1,12 @@
package autocomplete package autocomplete
import ( import (
"fmt"
"sort" "sort"
"coopcloud.tech/abra/pkg/app" "coopcloud.tech/abra/pkg/app"
appPkg "coopcloud.tech/abra/pkg/app" appPkg "coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/abra/pkg/recipe"
"github.com/leonelquinteros/gotext"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -14,7 +14,7 @@ import (
func AppNameComplete() ([]string, cobra.ShellCompDirective) { func AppNameComplete() ([]string, cobra.ShellCompDirective) {
appFiles, err := app.LoadAppFiles("") appFiles, err := app.LoadAppFiles("")
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
@ -29,7 +29,7 @@ func AppNameComplete() ([]string, cobra.ShellCompDirective) {
func ServiceNameComplete(appName string) ([]string, cobra.ShellCompDirective) { func ServiceNameComplete(appName string) ([]string, cobra.ShellCompDirective) {
serviceNames, err := app.GetAppServiceNames(appName) serviceNames, err := app.GetAppServiceNames(appName)
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
@ -40,7 +40,7 @@ func ServiceNameComplete(appName string) ([]string, cobra.ShellCompDirective) {
func RecipeNameComplete() ([]string, cobra.ShellCompDirective) { func RecipeNameComplete() ([]string, cobra.ShellCompDirective) {
catl, err := recipe.ReadRecipeCatalogue(false) catl, err := recipe.ReadRecipeCatalogue(false)
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
@ -56,7 +56,7 @@ func RecipeNameComplete() ([]string, cobra.ShellCompDirective) {
func RecipeVersionComplete(recipeName string) ([]string, cobra.ShellCompDirective) { func RecipeVersionComplete(recipeName string) ([]string, cobra.ShellCompDirective) {
catl, err := recipe.ReadRecipeCatalogue(true) catl, err := recipe.ReadRecipeCatalogue(true)
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
@ -74,7 +74,7 @@ func RecipeVersionComplete(recipeName string) ([]string, cobra.ShellCompDirectiv
func ServerNameComplete() ([]string, cobra.ShellCompDirective) { func ServerNameComplete() ([]string, cobra.ShellCompDirective) {
files, err := app.LoadAppFiles("") files, err := app.LoadAppFiles("")
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
@ -90,13 +90,13 @@ func ServerNameComplete() ([]string, cobra.ShellCompDirective) {
func CommandNameComplete(appName string) ([]string, cobra.ShellCompDirective) { func CommandNameComplete(appName string) ([]string, cobra.ShellCompDirective) {
app, err := app.Get(appName) app, err := app.Get(appName)
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
cmdNames, err := appPkg.ReadAbraShCmdNames(app.Recipe.AbraShPath) cmdNames, err := appPkg.ReadAbraShCmdNames(app.Recipe.AbraShPath)
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }
@ -111,7 +111,7 @@ func SecretComplete(recipeName string) ([]string, cobra.ShellCompDirective) {
config, err := r.GetComposeConfig(nil) config, err := r.GetComposeConfig(nil)
if err != nil { if err != nil {
err := fmt.Sprintf("autocomplete failed: %s", err) err := gotext.Get("autocomplete failed: %s", err)
return []string{err}, cobra.ShellCompDirectiveError return []string{err}, cobra.ShellCompDirectiveError
} }

View File

@ -1,6 +1,7 @@
package catalogue package catalogue
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path" "path"
@ -10,13 +11,14 @@ import (
gitPkg "coopcloud.tech/abra/pkg/git" gitPkg "coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/leonelquinteros/gotext"
) )
// EnsureCatalogue ensures that the catalogue is cloned locally & present. // EnsureCatalogue ensures that the catalogue is cloned locally & present.
func EnsureCatalogue() error { func EnsureCatalogue() error {
catalogueDir := path.Join(config.ABRA_DIR, "catalogue") catalogueDir := path.Join(config.ABRA_DIR, "catalogue")
if _, err := os.Stat(catalogueDir); err != nil && os.IsNotExist(err) { if _, err := os.Stat(catalogueDir); err != nil && os.IsNotExist(err) {
log.Debugf("catalogue is missing, retrieving now") log.Debug(gotext.Get("catalogue is missing, retrieving now"))
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, config.CATALOGUE_JSON_REPO_NAME) url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, config.CATALOGUE_JSON_REPO_NAME)
if err := gitPkg.Clone(catalogueDir, url); err != nil { if err := gitPkg.Clone(catalogueDir, url); err != nil {
@ -35,8 +37,7 @@ func EnsureIsClean() error {
} }
if !isClean { if !isClean {
msg := "%s has locally unstaged changes? please commit/remove your changes before proceeding" return errors.New(gotext.Get("%s has locally unstaged changes? please commit/remove your changes before proceeding", config.CATALOGUE_DIR))
return fmt.Errorf(msg, config.CATALOGUE_DIR)
} }
return nil return nil
@ -55,8 +56,7 @@ func EnsureUpToDate() error {
} }
if len(remotes) == 0 { if len(remotes) == 0 {
msg := "cannot ensure %s is up-to-date, no git remotes configured" log.Debugf(gotext.Get("cannot ensure %s is up-to-date, no git remotes configured", config.CATALOGUE_DIR))
log.Debugf(msg, config.CATALOGUE_DIR)
return nil return nil
} }
@ -81,7 +81,7 @@ func EnsureUpToDate() error {
} }
} }
log.Debugf("fetched latest git changes for %s", config.CATALOGUE_DIR) log.Debugf(gotext.Get("fetched latest git changes for %s", config.CATALOGUE_DIR))
return nil return nil
} }

View File

@ -4,7 +4,6 @@ package client
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"net/http" "net/http"
"os" "os"
"time" "time"
@ -14,6 +13,7 @@ import (
sshPkg "coopcloud.tech/abra/pkg/ssh" sshPkg "coopcloud.tech/abra/pkg/ssh"
commandconnPkg "coopcloud.tech/abra/pkg/upstream/commandconn" commandconnPkg "coopcloud.tech/abra/pkg/upstream/commandconn"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
// Conf is a Docker client configuration. // Conf is a Docker client configuration.
@ -41,7 +41,7 @@ func New(serverName string, opts ...Opt) (*client.Client, error) {
if serverName != "default" { if serverName != "default" {
context, err := GetContext(serverName) context, err := GetContext(serverName)
if err != nil { if err != nil {
return nil, fmt.Errorf("unknown server, run \"abra server add %s\"?", serverName) return nil, errors.New(gotext.Get("unknown server, run \"abra server add %s\"?", serverName))
} }
ctxEndpoint, err := contextPkg.GetContextEndpoint(context) ctxEndpoint, err := contextPkg.GetContextEndpoint(context)
@ -85,7 +85,7 @@ func New(serverName string, opts ...Opt) (*client.Client, error) {
return nil, err return nil, err
} }
log.Debugf("created client for %s", serverName) log.Debugf(gotext.Get("created client for %s", serverName))
info, err := cl.Info(context.Background()) info, err := cl.Info(context.Background())
if err != nil { if err != nil {
@ -94,10 +94,10 @@ func New(serverName string, opts ...Opt) (*client.Client, error) {
if info.Swarm.LocalNodeState == "inactive" { if info.Swarm.LocalNodeState == "inactive" {
if serverName != "default" { if serverName != "default" {
return cl, fmt.Errorf("swarm mode not enabled on %s?", serverName) return cl, errors.New(gotext.Get("swarm mode not enabled on %s?", serverName))
} }
return cl, errors.New("swarm mode not enabled on local server?") return cl, errors.New(gotext.Get("swarm mode not enabled on local server?"))
} }
return cl, nil return cl, nil

View File

@ -2,11 +2,12 @@ package client
import ( import (
"context" "context"
"fmt" "errors"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
func GetConfigs(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]swarm.Config, error) { func GetConfigs(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]swarm.Config, error) {
@ -31,7 +32,7 @@ func GetConfigNames(configs []swarm.Config) []string {
func RemoveConfigs(cl *client.Client, ctx context.Context, configNames []string, force bool) error { func RemoveConfigs(cl *client.Client, ctx context.Context, configNames []string, force bool) error {
for _, confName := range configNames { for _, confName := range configNames {
if err := cl.ConfigRemove(context.Background(), confName); err != nil { if err := cl.ConfigRemove(context.Background(), confName); err != nil {
return fmt.Errorf("conf %s: %s", confName, err) return errors.New(gotext.Get("conf %s: %s", confName, err))
} }
} }
return nil return nil

View File

@ -10,6 +10,7 @@ import (
dConfig "github.com/docker/cli/cli/config" dConfig "github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/docker"
contextStore "github.com/docker/cli/cli/context/store" contextStore "github.com/docker/cli/cli/context/store"
"github.com/leonelquinteros/gotext"
) )
type Context = contextStore.Metadata type Context = contextStore.Metadata
@ -22,7 +23,7 @@ func CreateContext(contextName string) error {
return err return err
} }
log.Debugf("created the %s context", contextName) log.Debugf(gotext.Get("created the %s context", contextName))
return nil return nil
} }
@ -62,7 +63,7 @@ func createContext(name string, host string) error {
func DeleteContext(name string) error { func DeleteContext(name string) error {
if name == "default" { if name == "default" {
return errors.New("context 'default' cannot be removed") return errors.New(gotext.Get("context 'default' cannot be removed"))
} }
if _, err := GetContext(name); err != nil { if _, err := GetContext(name); err != nil {

View File

@ -2,11 +2,13 @@ package client
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/containers/image/docker" "github.com/containers/image/docker"
"github.com/containers/image/types" "github.com/containers/image/types"
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/leonelquinteros/gotext"
) )
// GetRegistryTags retrieves all tags of an image from a container registry. // GetRegistryTags retrieves all tags of an image from a container registry.
@ -15,7 +17,7 @@ func GetRegistryTags(img reference.Named) ([]string, error) {
ref, err := docker.ParseReference(fmt.Sprintf("//%s", img)) ref, err := docker.ParseReference(fmt.Sprintf("//%s", img))
if err != nil { if err != nil {
return tags, fmt.Errorf("failed to parse image %s, saw: %s", img, err.Error()) return tags, errors.New(gotext.Get("failed to parse image %s, saw: %s", img, err.Error()))
} }
ctx := context.Background() ctx := context.Background()

View File

@ -2,6 +2,7 @@ package client
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"time" "time"
@ -9,6 +10,7 @@ import (
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
func GetVolumes(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]*volume.Volume, error) { func GetVolumes(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]*volume.Volume, error) {
@ -54,9 +56,9 @@ func retryFunc(retries int, fn func() error) error {
} }
if i+1 < retries { if i+1 < retries {
sleep := time.Duration(i+1) * time.Duration(i+1) sleep := time.Duration(i+1) * time.Duration(i+1)
log.Infof("%s: waiting %d seconds before next retry", err, sleep) log.Infof(gotext.Get("%s: waiting %d seconds before next retry", err, sleep))
time.Sleep(sleep * time.Second) time.Sleep(sleep * time.Second)
} }
} }
return fmt.Errorf("%d retries failed", retries) return errors.New(gotext.Get("%d retries failed", retries))
} }

View File

@ -6,6 +6,7 @@ import (
"path/filepath" "path/filepath"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
) )
@ -16,13 +17,13 @@ func LoadAbraConfig() Abra {
wd, _ := os.Getwd() wd, _ := os.Getwd()
configFile := findAbraConfig(wd) configFile := findAbraConfig(wd)
if configFile == "" { if configFile == "" {
log.Debugf("no config file found") log.Debugf(gotext.Get("no config file found"))
return Abra{} return Abra{}
} }
data, err := os.ReadFile(configFile) data, err := os.ReadFile(configFile)
if err != nil { if err != nil {
// Do nothing, when an error occurs // Do nothing, when an error occurs
log.Debugf("error reading config file: %s", err) log.Debugf(gotext.Get("error reading config file: %s", err))
return Abra{} return Abra{}
} }
@ -30,10 +31,10 @@ func LoadAbraConfig() Abra {
err = yaml.Unmarshal(data, &config) err = yaml.Unmarshal(data, &config)
if err != nil { if err != nil {
// Do nothing, when an error occurs // Do nothing, when an error occurs
log.Debugf("error loading config file: %s", err) log.Debugf(gotext.Get("error loading config file: %s", err))
return Abra{} return Abra{}
} }
log.Debugf("config file loaded from: %s", configFile) log.Debugf(gotext.Get("config file loaded from: %s", configFile))
config.configPath = filepath.Dir(configFile) config.configPath = filepath.Dir(configFile)
return config return config
} }
@ -73,26 +74,24 @@ type Abra struct {
// 3. use $HOME/.abra when above two options failed // 3. use $HOME/.abra when above two options failed
func (a Abra) GetAbraDir() string { func (a Abra) GetAbraDir() string {
if dir, exists := os.LookupEnv("ABRA_DIR"); exists && dir != "" { if dir, exists := os.LookupEnv("ABRA_DIR"); exists && dir != "" {
log.Debug("read abra dir from $ABRA_DIR") log.Debug(gotext.Get("read abra dir from $ABRA_DIR"))
return dir return dir
} }
if a.AbraDir != "" { if a.AbraDir != "" {
log.Debug("read abra dir from config file") log.Debug(gotext.Get("read abra dir from config file"))
if path.IsAbs(a.AbraDir) { if path.IsAbs(a.AbraDir) {
return a.AbraDir return a.AbraDir
} }
// Make the path absolute // Make the path absolute
return path.Join(a.configPath, a.AbraDir) return path.Join(a.configPath, a.AbraDir)
} }
log.Debug("using default abra dir") log.Debug(gotext.Get("using default abra dir"))
return os.ExpandEnv("$HOME/.abra") return os.ExpandEnv("$HOME/.abra")
} }
func (a Abra) GetServersDir() string { return path.Join(a.GetAbraDir(), "servers") } func (a Abra) GetServersDir() string { return path.Join(a.GetAbraDir(), "servers") }
func (a Abra) GetRecipesDir() string { return path.Join(a.GetAbraDir(), "recipes") } func (a Abra) GetRecipesDir() string { return path.Join(a.GetAbraDir(), "recipes") }
func (a Abra) GetLogsDir() string { return path.Join(a.GetAbraDir(), "logs") } func (a Abra) GetLogsDir() string { return path.Join(a.GetAbraDir(), "logs") }
func (a Abra) GetVendorDir() string { return path.Join(a.GetAbraDir(), "vendor") }
func (a Abra) GetBackupDir() string { return path.Join(a.GetAbraDir(), "backups") }
func (a Abra) GetCatalogueDir() string { return path.Join(a.GetAbraDir(), "catalogue") } func (a Abra) GetCatalogueDir() string { return path.Join(a.GetAbraDir(), "catalogue") }
var config = LoadAbraConfig() var config = LoadAbraConfig()
@ -102,8 +101,6 @@ var (
SERVERS_DIR = config.GetServersDir() SERVERS_DIR = config.GetServersDir()
RECIPES_DIR = config.GetRecipesDir() RECIPES_DIR = config.GetRecipesDir()
LOGS_DIR = config.GetLogsDir() LOGS_DIR = config.GetLogsDir()
VENDOR_DIR = config.GetVendorDir()
BACKUP_DIR = config.GetBackupDir()
CATALOGUE_DIR = config.GetCatalogueDir() CATALOGUE_DIR = config.GetCatalogueDir()
RECIPES_JSON = path.Join(config.GetCatalogueDir(), "recipes.json") RECIPES_JSON = path.Join(config.GetCatalogueDir(), "recipes.json")
REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud" REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"

View File

@ -1,7 +1,7 @@
package config package config
import ( import (
"fmt" "errors"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
"os" "os"
@ -10,6 +10,7 @@ import (
"strings" "strings"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
) )
const MAX_SANITISED_APP_NAME_LENGTH = 45 const MAX_SANITISED_APP_NAME_LENGTH = 45
@ -33,7 +34,7 @@ func GetServers() ([]string, error) {
} }
} }
log.Debugf("retrieved %v servers: %s", len(filtered), filtered) log.Debugf(gotext.Get("retrieved %v servers: %s", len(filtered), filtered))
return filtered, nil return filtered, nil
} }
@ -46,7 +47,7 @@ func ReadServerNames() ([]string, error) {
return nil, err return nil, err
} }
log.Debugf("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR) log.Debugf(gotext.Get("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR))
return serverNames, nil return serverNames, nil
} }
@ -70,7 +71,7 @@ func GetAllFilesInDirectory(directory string) ([]fs.FileInfo, error) {
realPath, err := filepath.EvalSymlinks(filePath) realPath, err := filepath.EvalSymlinks(filePath)
if err != nil { if err != nil {
log.Warnf("broken symlink in your abra config folders: %s", filePath) log.Warnf(gotext.Get("broken symlink in your abra config folders: %s", filePath))
} else { } else {
realFile, err := os.Stat(realPath) realFile, err := os.Stat(realPath)
if err != nil { if err != nil {
@ -94,7 +95,7 @@ func GetAllFoldersInDirectory(directory string) ([]string, error) {
return nil, err return nil, err
} }
if len(files) == 0 { if len(files) == 0 {
return nil, fmt.Errorf("directory is empty: %s", directory) return nil, errors.New(gotext.Get("directory is empty: %s", directory))
} }
for _, file := range files { for _, file := range files {
@ -103,7 +104,7 @@ func GetAllFoldersInDirectory(directory string) ([]string, error) {
filePath := path.Join(directory, file.Name()) filePath := path.Join(directory, file.Name())
realDir, err := filepath.EvalSymlinks(filePath) realDir, err := filepath.EvalSymlinks(filePath)
if err != nil { if err != nil {
log.Warnf("broken symlink in your abra config folders: %s", filePath) log.Warnf(gotext.Get("broken symlink in your abra config folders: %s", filePath))
} else if stat, err := os.Stat(realDir); err == nil && stat.IsDir() { } else if stat, err := os.Stat(realDir); err == nil && stat.IsDir() {
// path is a directory // path is a directory
folders = append(folders, file.Name()) folders = append(folders, file.Name())

View File

@ -2,6 +2,7 @@ package container
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@ -12,6 +13,7 @@ import (
containerTypes "github.com/docker/docker/api/types/container" containerTypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
// GetContainer retrieves a container. If noInput is false and the retrievd // GetContainer retrieves a container. If noInput is false and the retrievd
@ -26,7 +28,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
if len(containers) == 0 { if len(containers) == 0 {
filter := filters.Get("name")[0] filter := filters.Get("name")[0]
return types.Container{}, fmt.Errorf("no containers matching the %v filter found?", filter) return types.Container{}, errors.New(gotext.Get("no containers matching the %v filter found?", filter))
} }
if len(containers) > 1 { if len(containers) > 1 {
@ -35,19 +37,19 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
containerName := strings.Join(container.Names, " ") containerName := strings.Join(container.Names, " ")
trimmed := strings.TrimPrefix(containerName, "/") trimmed := strings.TrimPrefix(containerName, "/")
created := formatter.HumanDuration(container.Created) created := formatter.HumanDuration(container.Created)
containersRaw = append(containersRaw, fmt.Sprintf("%s (created %v)", trimmed, created)) containersRaw = append(containersRaw, gotext.Get("%s (created %v)", trimmed, created))
} }
if noInput { if noInput {
err := fmt.Errorf("expected 1 container but found %v: %s", len(containers), strings.Join(containersRaw, " ")) err := errors.New(gotext.Get("expected 1 container but found %v: %s", len(containers), strings.Join(containersRaw, " ")))
return types.Container{}, err return types.Container{}, err
} }
log.Warnf("ambiguous container list received, prompting for input") log.Warnf(gotext.Get("ambiguous container list received, prompting for input"))
var response string var response string
prompt := &survey.Select{ prompt := &survey.Select{
Message: "which container are you looking for?", Message: gotext.Get("which container are you looking for?"),
Options: containersRaw, Options: containersRaw,
} }
@ -64,7 +66,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
} }
} }
log.Fatal("failed to match chosen container") log.Fatal(gotext.Get("failed to match chosen container"))
} }
return containers[0], nil return containers[0], nil
@ -79,5 +81,6 @@ func GetContainerFromStackAndService(cl *client.Client, stack, service string) (
if err != nil { if err != nil {
return types.Container{}, err return types.Container{}, err
} }
return container, nil return container, nil
} }

View File

@ -8,6 +8,7 @@ import (
"github.com/docker/cli/cli/context" "github.com/docker/cli/cli/context"
contextStore "github.com/docker/cli/cli/context/store" contextStore "github.com/docker/cli/cli/context/store"
cliflags "github.com/docker/cli/cli/flags" cliflags "github.com/docker/cli/cli/flags"
"github.com/leonelquinteros/gotext"
) )
func NewDefaultDockerContextStore() *command.ContextStoreWithDefault { func NewDefaultDockerContextStore() *command.ContextStoreWithDefault {
@ -30,7 +31,7 @@ func NewDefaultDockerContextStore() *command.ContextStoreWithDefault {
func GetContextEndpoint(ctx contextStore.Metadata) (string, error) { func GetContextEndpoint(ctx contextStore.Metadata) (string, error) {
endpointmeta, ok := ctx.Endpoints["docker"].(context.EndpointMetaBase) endpointmeta, ok := ctx.Endpoints["docker"].(context.EndpointMetaBase)
if !ok { if !ok {
err := errors.New("context lacks Docker endpoint") err := errors.New(gotext.Get("context lacks Docker endpoint"))
return "", err return "", err
} }
return endpointmeta.Host, nil return endpointmeta.Host, nil

View File

@ -1,19 +1,21 @@
package dns package dns
import ( import (
"fmt" "errors"
"net" "net"
"github.com/leonelquinteros/gotext"
) )
// EnsureIPv4 ensures that an ipv4 address is set for a domain name // EnsureIPv4 ensures that an ipv4 address is set for a domain name
func EnsureIPv4(domainName string) (string, error) { func EnsureIPv4(domainName string) (string, error) {
ipv4, err := net.ResolveIPAddr("ip4", domainName) ipv4, err := net.ResolveIPAddr("ip4", domainName)
if err != nil { if err != nil {
return "", fmt.Errorf("%s: unable to resolve IPv4 address: %s", domainName, err) return "", errors.New(gotext.Get("%s: unable to resolve IPv4 address: %s", domainName, err))
} }
if ipv4 == nil { if ipv4 == nil {
return "", fmt.Errorf("%s: no IPv4 available", domainName) return "", errors.New(gotext.Get("%s: no IPv4 available", domainName))
} }
return ipv4.String(), nil return ipv4.String(), nil
@ -33,7 +35,7 @@ func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
} }
if domainIPv4 == "" { if domainIPv4 == "" {
return ipv4, fmt.Errorf("cannot resolve ipv4 for %s?", domainName) return ipv4, errors.New(gotext.Get("cannot resolve ipv4 for %s?", domainName))
} }
serverIPv4, err := EnsureIPv4(server) serverIPv4, err := EnsureIPv4(server)
@ -42,12 +44,16 @@ func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
} }
if serverIPv4 == "" { if serverIPv4 == "" {
return ipv4, fmt.Errorf("cannot resolve ipv4 for %s?", server) return ipv4, errors.New(gotext.Get("cannot resolve ipv4 for %s?", server))
} }
if domainIPv4 != serverIPv4 { if domainIPv4 != serverIPv4 {
err := "app domain %s (%s) does not appear to resolve to app server %s (%s)?" return ipv4, errors.New(
return ipv4, fmt.Errorf(err, domainName, domainIPv4, server, serverIPv4) gotext.Get(
"app domain %s (%s) does not appear to resolve to app server %s (%s)?",
domainName, domainIPv4, server, serverIPv4,
),
)
} }
return ipv4, nil return ipv4, nil

View File

@ -2,13 +2,14 @@ package envfile
import ( import (
"bufio" "bufio"
"fmt" "errors"
"os" "os"
"regexp" "regexp"
"strings" "strings"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"git.coopcloud.tech/toolshed/godotenv" "git.coopcloud.tech/toolshed/godotenv"
"github.com/leonelquinteros/gotext"
) )
// AppEnv is a map of the values in an apps env config // AppEnv is a map of the values in an apps env config
@ -38,7 +39,7 @@ func ReadEnvWithModifiers(filePath string) (AppEnv, AppModifiers, error) {
return nil, mods, err return nil, mods, err
} }
log.Debugf("read %s from %s", envVars, filePath) log.Debugf(gotext.Get("read %s from %s", envVars, filePath))
return envVars, mods, nil return envVars, mods, nil
} }
@ -69,16 +70,16 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
envVarDef := splitVals[len(splitVals)-1] envVarDef := splitVals[len(splitVals)-1]
keyVal := strings.Split(envVarDef, "=") keyVal := strings.Split(envVarDef, "=")
if len(keyVal) != 2 { if len(keyVal) != 2 {
return envVars, fmt.Errorf("couldn't parse %s", txt) return envVars, errors.New(gotext.Get("couldn't parse %s", txt))
} }
envVars[keyVal[0]] = keyVal[1] envVars[keyVal[0]] = keyVal[1]
} }
} }
if len(envVars) > 0 { if len(envVars) > 0 {
log.Debugf("read %s from %s", envVars, abraSh) log.Debugf(gotext.Get("read %s from %s", envVars, abraSh))
} else { } else {
log.Debugf("read 0 env var exports from %s", abraSh) log.Debugf(gotext.Get("read 0 env var exports from %s", abraSh))
} }
return envVars, nil return envVars, nil

View File

@ -11,6 +11,7 @@ import (
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table" "github.com/charmbracelet/lipgloss/table"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/leonelquinteros/gotext"
"golang.org/x/term" "golang.org/x/term"
"coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/config"
@ -42,7 +43,7 @@ func RemoveSha(str string) string {
func HumanDuration(timestamp int64) string { func HumanDuration(timestamp int64) string {
date := time.Unix(timestamp, 0) date := time.Unix(timestamp, 0)
now := time.Now().UTC() now := time.Now().UTC()
return units.HumanDuration(now.Sub(date)) + " ago" return units.HumanDuration(now.Sub(date)) + gotext.Get(" ago")
} }
// CreateTable prepares a table layout for output. // CreateTable prepares a table layout for output.
@ -76,7 +77,7 @@ func CreateTable() (*table.Table, error) {
func PrintTable(t *table.Table) error { func PrintTable(t *table.Table) error {
if isAbraCI, ok := os.LookupEnv("ABRA_CI"); ok && isAbraCI == "1" { if isAbraCI, ok := os.LookupEnv("ABRA_CI"); ok && isAbraCI == "1" {
// NOTE(d1): no width limits for CI testing since we test against outputs // NOTE(d1): no width limits for CI testing since we test against outputs
log.Debug("detected ABRA_CI=1") log.Debug(gotext.Get("detected ABRA_CI=1"))
fmt.Println(t) fmt.Println(t)
return nil return nil
} }
@ -130,7 +131,7 @@ func CreateOverview(header string, rows [][]string) string {
} }
if len(row) > 2 { if len(row) > 2 {
panic("CreateOverview: only accepts rows of len == 2") panic(gotext.Get("CreateOverview: only accepts rows of len == 2"))
} }
lenOffset := 4 lenOffset := 4
@ -234,7 +235,7 @@ func StripTagMeta(image string) string {
} }
if originalImage != image { if originalImage != image {
log.Debugf("stripped %s to %s for parsing", originalImage, image) log.Debugf(gotext.Get("stripped %s to %s for parsing", originalImage, image))
} }
return image return image

View File

@ -3,6 +3,7 @@ package git
import ( import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/leonelquinteros/gotext"
) )
// Add adds a file to the git index. // Add adds a file to the git index.
@ -18,7 +19,7 @@ func Add(repoPath, path string, dryRun bool) error {
} }
if dryRun { if dryRun {
log.Debugf("dry run: adding %s", path) log.Debugf(gotext.Get("dry run: adding %s", path))
} else { } else {
worktree.Add(path) worktree.Add(path)
} }

View File

@ -1,11 +1,13 @@
package git package git
import ( import (
"errors"
"fmt" "fmt"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/leonelquinteros/gotext"
) )
// Check if a branch exists in a repo. Use this and not repository.Branch(), // Check if a branch exists in a repo. Use this and not repository.Branch(),
@ -63,7 +65,7 @@ func GetDefaultBranch(repo *git.Repository, repoPath string) (plumbing.Reference
if !HasBranch(repo, "master") { if !HasBranch(repo, "master") {
if !HasBranch(repo, "main") { if !HasBranch(repo, "main") {
return "", fmt.Errorf("failed to select default branch in %s", repoPath) return "", errors.New(gotext.Get("failed to select default branch in %s", repoPath))
} }
branch = "main" branch = "main"
} }
@ -90,11 +92,11 @@ func CheckoutDefaultBranch(repo *git.Repository, repoPath string) (plumbing.Refe
} }
if err := worktree.Checkout(checkOutOpts); err != nil { if err := worktree.Checkout(checkOutOpts); err != nil {
log.Debugf("failed to check out %s in %s", branch, repoPath) log.Debugf(gotext.Get("failed to check out %s in %s", branch, repoPath))
return branch, err return branch, err
} }
log.Debugf("successfully checked out %v in %s", branch, repoPath) log.Debugf(gotext.Get("successfully checked out %v in %s", branch, repoPath))
return branch, nil return branch, nil
} }

View File

@ -2,6 +2,7 @@ package git
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -10,6 +11,7 @@ import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/leonelquinteros/gotext"
) )
// gitCloneIgnoreErr checks whether we can ignore a git clone error or not. // gitCloneIgnoreErr checks whether we can ignore a git clone error or not.
@ -44,7 +46,7 @@ func Clone(dir, url string) error {
go func() { go func() {
if _, err := os.Stat(dir); os.IsNotExist(err) { if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Debugf("git clone: %s", url) log.Debugf(gotext.Get("git clone: %s", url))
_, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{ _, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
URL: url, URL: url,
@ -54,16 +56,16 @@ func Clone(dir, url string) error {
}) })
if err != nil && gitCloneIgnoreErr(err) { if err != nil && gitCloneIgnoreErr(err) {
log.Debugf("git clone: %s cloned successfully", dir) log.Debugf(gotext.Get("git clone: %s cloned successfully", dir))
errCh <- nil errCh <- nil
} }
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {
errCh <- fmt.Errorf("git clone %s: cancelled due to interrupt", dir) errCh <- errors.New(gotext.Get("git clone %s: cancelled due to interrupt", dir))
} }
if err != nil { if err != nil {
log.Debug("git clone: main branch failed, attempting master branch") log.Debug(gotext.Get("git clone: main branch failed, attempting master branch"))
_, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{ _, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
URL: url, URL: url,
@ -73,7 +75,7 @@ func Clone(dir, url string) error {
}) })
if err != nil && gitCloneIgnoreErr(err) { if err != nil && gitCloneIgnoreErr(err) {
log.Debugf("git clone: %s cloned successfully", dir) log.Debugf(gotext.Get("git clone: %s cloned successfully", dir))
errCh <- nil errCh <- nil
} }
@ -82,9 +84,9 @@ func Clone(dir, url string) error {
} }
} }
log.Debugf("git clone: %s cloned successfully", dir) log.Debugf(gotext.Get("git clone: %s cloned successfully", dir))
} else { } else {
log.Debugf("git clone: %s already exists", dir) log.Debugf(gotext.Get("git clone: %s already exists", dir))
} }
errCh <- nil errCh <- nil
@ -95,9 +97,9 @@ func Clone(dir, url string) error {
cancelCtx() cancelCtx()
fmt.Println() // NOTE(d1): newline after ^C fmt.Println() // NOTE(d1): newline after ^C
if err := os.RemoveAll(dir); err != nil { if err := os.RemoveAll(dir); err != nil {
return fmt.Errorf("unable to clean up git clone of %s: %s", dir, err) return errors.New(gotext.Get("unable to clean up git clone of %s: %s", dir, err))
} }
return fmt.Errorf("git clone %s: cancelled due to interrupt", dir) return errors.New(gotext.Get("git clone %s: cancelled due to interrupt", dir))
case err := <-errCh: case err := <-errCh:
return err return err
} }

View File

@ -1,16 +1,17 @@
package git package git
import ( import (
"fmt" "errors"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/leonelquinteros/gotext"
) )
// Commit runs a git commit // Commit runs a git commit
func Commit(repoPath, commitMessage string, dryRun bool) error { func Commit(repoPath, commitMessage string, dryRun bool) error {
if commitMessage == "" { if commitMessage == "" {
return fmt.Errorf("no commit message specified?") return errors.New(gotext.Get("no commit message specified?"))
} }
commitRepo, err := git.PlainOpen(repoPath) commitRepo, err := git.PlainOpen(repoPath)
@ -38,9 +39,9 @@ func Commit(repoPath, commitMessage string, dryRun bool) error {
if err != nil { if err != nil {
return err return err
} }
log.Debug("git changes commited") log.Debug(gotext.Get("git changes commited"))
} else { } else {
log.Debug("dry run: no changes commited") log.Debug(gotext.Get("dry run: no changes commited"))
} }
return nil return nil

View File

@ -1,14 +1,16 @@
package git package git
import ( import (
"fmt" "errors"
"os" "os"
"github.com/leonelquinteros/gotext"
) )
// EnsureGitRepo ensures a git repo .git folder exists // EnsureGitRepo ensures a git repo .git folder exists
func EnsureGitRepo(repoPath string) error { func EnsureGitRepo(repoPath string) error {
if _, err := os.Stat(repoPath); os.IsNotExist(err) { if _, err := os.Stat(repoPath); os.IsNotExist(err) {
return fmt.Errorf("no .git directory in %s?", repoPath) return errors.New(gotext.Get("no .git directory in %s?", repoPath))
} }
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"os/exec" "os/exec"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
) )
// getGitDiffArgs builds the `git diff` invocation args. It removes the usage // getGitDiffArgs builds the `git diff` invocation args. It removes the usage
@ -26,7 +27,7 @@ func getGitDiffArgs(repoPath string) []string {
// skips if it cannot find the command on the system. // skips if it cannot find the command on the system.
func DiffUnstaged(path string) error { func DiffUnstaged(path string) error {
if _, err := exec.LookPath("git"); err != nil { if _, err := exec.LookPath("git"); err != nil {
log.Warnf("unable to locate git command, cannot output diff") log.Warnf(gotext.Get("unable to locate git command, cannot output diff"))
return nil return nil
} }

View File

@ -1,40 +1,41 @@
package git package git
import ( import (
"fmt" "errors"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/object"
"github.com/leonelquinteros/gotext"
) )
// Init inits a new repo and commits all the stuff if you want // Init inits a new repo and commits all the stuff if you want
func Init(repoPath string, commit bool, gitName, gitEmail string) error { func Init(repoPath string, commit bool, gitName, gitEmail string) error {
repo, err := git.PlainInit(repoPath, false) repo, err := git.PlainInit(repoPath, false)
if err != nil { if err != nil {
return fmt.Errorf("git init: %s", err) return errors.New(gotext.Get("git init: %s", err))
} }
if err = SwitchToMain(repo); err != nil { if err = SwitchToMain(repo); err != nil {
return fmt.Errorf("git branch rename: %s", err) return errors.New(gotext.Get("git branch rename: %s", err))
} }
log.Debugf("initialised new git repo in %s", repoPath) log.Debugf(gotext.Get("initialised new git repo in %s", repoPath))
if commit { if commit {
commitRepo, err := git.PlainOpen(repoPath) commitRepo, err := git.PlainOpen(repoPath)
if err != nil { if err != nil {
return fmt.Errorf("git open: %s", err) return errors.New(gotext.Get("git open: %s", err))
} }
commitWorktree, err := commitRepo.Worktree() commitWorktree, err := commitRepo.Worktree()
if err != nil { if err != nil {
return fmt.Errorf("git worktree: %s", err) return errors.New(gotext.Get("git worktree: %s", err))
} }
if err := commitWorktree.AddWithOptions(&git.AddOptions{All: true}); err != nil { if err := commitWorktree.AddWithOptions(&git.AddOptions{All: true}); err != nil {
return fmt.Errorf("git add: %s", err) return errors.New(gotext.Get("git add: %s", err))
} }
var author *object.Signature var author *object.Signature
@ -43,10 +44,10 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
} }
if _, err = commitWorktree.Commit("init", &git.CommitOptions{Author: author}); err != nil { if _, err = commitWorktree.Commit("init", &git.CommitOptions{Author: author}); err != nil {
return fmt.Errorf("git commit: %s", err) return errors.New(gotext.Get("git commit: %s", err))
} }
log.Debugf("init committed all files for new git repo in %s", repoPath) log.Debugf(gotext.Get("init committed all files for new git repo in %s", repoPath))
} }
return nil return nil
@ -56,20 +57,20 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
func SwitchToMain(repo *git.Repository) error { func SwitchToMain(repo *git.Repository) error {
ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main")) ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main"))
if err := repo.Storer.SetReference(ref); err != nil { if err := repo.Storer.SetReference(ref); err != nil {
return fmt.Errorf("set reference: %s", err) return errors.New(gotext.Get("set reference: %s", err))
} }
cfg, err := repo.Config() cfg, err := repo.Config()
if err != nil { if err != nil {
return fmt.Errorf("repo config: %s", err) return errors.New(gotext.Get("repo config: %s", err))
} }
cfg.Init.DefaultBranch = "main" cfg.Init.DefaultBranch = "main"
if err := repo.SetConfig(cfg); err != nil { if err := repo.SetConfig(cfg); err != nil {
return fmt.Errorf("repo set config: %s", err) return errors.New(gotext.Get("repo set config: %s", err))
} }
log.Debug("set 'main' as the default branch") log.Debug(gotext.Get("set 'main' as the default branch"))
return nil return nil
} }

View File

@ -4,12 +4,13 @@ import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/config"
"github.com/leonelquinteros/gotext"
) )
// Push pushes the latest changes & optionally tags to the default remote // Push pushes the latest changes & optionally tags to the default remote
func Push(repoDir string, remote string, tags bool, dryRun bool) error { func Push(repoDir string, remote string, tags bool, dryRun bool) error {
if dryRun { if dryRun {
log.Debugf("dry run: no git changes pushed in %s", repoDir) log.Debugf(gotext.Get("dry run: no git changes pushed in %s", repoDir))
return nil return nil
} }
@ -27,7 +28,7 @@ func Push(repoDir string, remote string, tags bool, dryRun bool) error {
return err return err
} }
log.Debugf("git changes pushed") log.Debugf(gotext.Get("git changes pushed"))
if tags { if tags {
opts.RefSpecs = append(opts.RefSpecs, config.RefSpec("+refs/tags/*:refs/tags/*")) opts.RefSpecs = append(opts.RefSpecs, config.RefSpec("+refs/tags/*:refs/tags/*"))
@ -36,7 +37,7 @@ func Push(repoDir string, remote string, tags bool, dryRun bool) error {
return err return err
} }
log.Debugf("git tags pushed") log.Debugf(gotext.Get("git tags pushed"))
} }
return nil return nil

View File

@ -2,7 +2,6 @@ package git
import ( import (
"errors" "errors"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/user" "os/user"
@ -13,6 +12,7 @@ import (
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
gitConfigPkg "github.com/go-git/go-git/v5/config" gitConfigPkg "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing/format/gitignore" "github.com/go-git/go-git/v5/plumbing/format/gitignore"
"github.com/leonelquinteros/gotext"
) )
// IsClean checks if a repo has unstaged changes // IsClean checks if a repo has unstaged changes
@ -23,12 +23,12 @@ func IsClean(repoPath string) (bool, error) {
return false, git.ErrRepositoryNotExists return false, git.ErrRepositoryNotExists
} }
return false, fmt.Errorf("unable to open %s: %s", repoPath, err) return false, errors.New(gotext.Get("unable to open %s: %s", repoPath, err))
} }
worktree, err := repo.Worktree() worktree, err := repo.Worktree()
if err != nil { if err != nil {
return false, fmt.Errorf("unable to open worktree of %s: %s", repoPath, err) return false, errors.New(gotext.Get("unable to open worktree of %s: %s", repoPath, err))
} }
patterns, err := GetExcludesFiles() patterns, err := GetExcludesFiles()
@ -42,14 +42,14 @@ func IsClean(repoPath string) (bool, error) {
status, err := worktree.Status() status, err := worktree.Status()
if err != nil { if err != nil {
return false, fmt.Errorf("unable to query status of %s: %s", repoPath, err) return false, errors.New(gotext.Get("unable to query status of %s: %s", repoPath, err))
} }
if status.String() != "" { if status.String() != "" {
noNewline := strings.TrimSuffix(status.String(), "\n") noNewline := strings.TrimSuffix(status.String(), "\n")
log.Debugf("git status: %s: %s", repoPath, noNewline) log.Debugf(gotext.Get("git status: %s: %s", repoPath, noNewline))
} else { } else {
log.Debugf("git status: %s: clean", repoPath) log.Debugf(gotext.Get("git status: %s: clean", repoPath))
} }
return status.IsClean(), nil return status.IsClean(), nil
@ -85,7 +85,7 @@ func parseGitConfig() (*gitConfigPkg.Config, error) {
globalGitConfig := filepath.Join(usr.HomeDir, ".gitconfig") globalGitConfig := filepath.Join(usr.HomeDir, ".gitconfig")
if _, err := os.Stat(globalGitConfig); err != nil { if _, err := os.Stat(globalGitConfig); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Debugf("no %s exists, not reading any global gitignore config", globalGitConfig) log.Debugf(gotext.Get("no %s exists, not reading any global gitignore config", globalGitConfig))
return cfg, nil return cfg, nil
} }
return cfg, err return cfg, err
@ -127,7 +127,7 @@ func parseExcludesFile(excludesfile string) ([]gitignore.Pattern, error) {
if _, err := os.Stat(excludesfile); err != nil { if _, err := os.Stat(excludesfile); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
log.Debugf("no %s exists, skipping reading gitignore paths", excludesfile) log.Debugf(gotext.Get("no %s exists, skipping reading gitignore paths", excludesfile))
return ps, nil return ps, nil
} }
return ps, err return ps, err
@ -146,7 +146,7 @@ func parseExcludesFile(excludesfile string) ([]gitignore.Pattern, error) {
} }
} }
log.Debugf("read global ignore paths: %s", strings.Join(pathsRaw, " ")) log.Debugf(gotext.Get("read global ignore paths: %s", strings.Join(pathsRaw, " ")))
return ps, nil return ps, nil
} }

View File

@ -6,12 +6,13 @@ import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/config"
"github.com/leonelquinteros/gotext"
) )
// CreateRemote creates a new git remote in a repository // CreateRemote creates a new git remote in a repository
func CreateRemote(repo *git.Repository, name, url string, dryRun bool) error { func CreateRemote(repo *git.Repository, name, url string, dryRun bool) error {
if dryRun { if dryRun {
log.Debugf("dry run: remote %s (%s) not created", name, url) log.Debugf(gotext.Get("dry run: remote %s (%s) not created", name, url))
return nil return nil
} }

View File

@ -1,6 +1,7 @@
package lint package lint
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
@ -13,11 +14,12 @@ import (
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/leonelquinteros/gotext"
) )
var ( var (
Warn = "warn" Warn = gotext.Get("warn")
Critical = "critical" Critical = gotext.Get("critical")
) )
type LintFunction func(recipe.Recipe) (bool, error) type LintFunction func(recipe.Recipe) (bool, error)
@ -47,10 +49,10 @@ func (l LintRule) Skip(recipe recipe.Recipe) bool {
if l.SkipCondition != nil { if l.SkipCondition != nil {
ok, err := l.SkipCondition(recipe) ok, err := l.SkipCondition(recipe)
if err != nil { if err != nil {
log.Debugf("%s: skip condition: %s", l.Ref, err) log.Debugf(gotext.Get("%s: skip condition: %s", l.Ref, err))
} }
if ok { if ok {
log.Debugf("skipping %s based on skip condition", l.Ref) log.Debugf(gotext.Get("skipping %s based on skip condition", l.Ref))
return true return true
} }
} }
@ -62,117 +64,117 @@ var LintRules = map[string][]LintRule{
"warn": { "warn": {
{ {
Ref: "R001", Ref: "R001",
Level: "warn", Level: gotext.Get("warn"),
Description: "compose config has expected version", Description: gotext.Get("compose config has expected version"),
HowToResolve: "ensure 'version: \"3.8\"' in compose configs", HowToResolve: gotext.Get("ensure 'version: \"3.8\"' in compose configs"),
Function: LintComposeVersion, Function: LintComposeVersion,
}, },
{ {
Ref: "R002", Ref: "R002",
Level: "warn", Level: gotext.Get("warn"),
Description: "healthcheck enabled for all services", Description: gotext.Get("healthcheck enabled for all services"),
HowToResolve: "wire up healthchecks", HowToResolve: gotext.Get("wire up healthchecks"),
Function: LintHealthchecks, Function: LintHealthchecks,
}, },
{ {
Ref: "R003", Ref: "R003",
Level: "warn", Level: gotext.Get("warn"),
Description: "all images use a tag", Description: gotext.Get("all images use a tag"),
HowToResolve: "use a tag for all images", HowToResolve: gotext.Get("use a tag for all images"),
Function: LintAllImagesTagged, Function: LintAllImagesTagged,
}, },
{ {
Ref: "R004", Ref: "R004",
Level: "warn", Level: gotext.Get("warn"),
Description: "no unstable tags", Description: gotext.Get("no unstable tags"),
HowToResolve: "tag all images with stable tags", HowToResolve: gotext.Get("tag all images with stable tags"),
Function: LintNoUnstableTags, Function: LintNoUnstableTags,
}, },
{ {
Ref: "R005", Ref: "R005",
Level: "warn", Level: gotext.Get("warn"),
Description: "tags use semver-like format", Description: gotext.Get("tags use semver-like format"),
HowToResolve: "use semver-like tags", HowToResolve: gotext.Get("use semver-like tags"),
Function: LintSemverLikeTags, Function: LintSemverLikeTags,
}, },
{ {
Ref: "R006", Ref: "R006",
Level: "warn", Level: gotext.Get("warn"),
Description: "has published catalogue version", Description: gotext.Get("has published catalogue version"),
HowToResolve: "publish a recipe version to the catalogue", HowToResolve: gotext.Get("publish a recipe version to the catalogue"),
Function: LintHasPublishedVersion, Function: LintHasPublishedVersion,
}, },
{ {
Ref: "R007", Ref: "R007",
Level: "warn", Level: gotext.Get("warn"),
Description: "README.md metadata filled in", Description: gotext.Get("README.md metadata filled in"),
HowToResolve: "fill out all the metadata", HowToResolve: gotext.Get("fill out all the metadata"),
Function: LintMetadataFilledIn, Function: LintMetadataFilledIn,
}, },
{ {
Ref: "R013", Ref: "R013",
Level: "warn", Level: gotext.Get("warn"),
Description: "git.coopcloud.tech repo exists", Description: gotext.Get("git.coopcloud.tech repo exists"),
HowToResolve: "upload your recipe to git.coopcloud.tech/coop-cloud/...", HowToResolve: gotext.Get("upload your recipe to git.coopcloud.tech/coop-cloud/..."),
Function: LintHasRecipeRepo, Function: LintHasRecipeRepo,
}, },
{ {
Ref: "R015", Ref: "R015",
Level: "warn", Level: gotext.Get("warn"),
Description: "long secret names", Description: gotext.Get("long secret names"),
HowToResolve: "reduce length of secret names to 12 chars", HowToResolve: gotext.Get("reduce length of secret names to 12 chars"),
Function: LintSecretLengths, Function: LintSecretLengths,
}, },
}, },
"error": { "error": {
{ {
Ref: "R008", Ref: "R008",
Level: "error", Level: gotext.Get("error"),
Description: ".env.sample provided", Description: gotext.Get(".env.sample provided"),
HowToResolve: "create an example .env.sample", HowToResolve: gotext.Get("create an example .env.sample"),
Function: LintEnvConfigPresent, Function: LintEnvConfigPresent,
}, },
{ {
Ref: "R009", Ref: "R009",
Level: "error", Level: gotext.Get("error"),
Description: "one service named 'app'", Description: gotext.Get("one service named 'app'"),
HowToResolve: "name a servce 'app'", HowToResolve: gotext.Get("name a servce 'app'"),
Function: LintAppService, Function: LintAppService,
}, },
{ {
Ref: "R015", Ref: "R015",
Level: "error", Level: gotext.Get("error"),
Description: "deploy labels stanza present", Description: gotext.Get("deploy labels stanza present"),
HowToResolve: "include \"deploy: labels: ...\" stanza", HowToResolve: gotext.Get("include \"deploy: labels: ...\" stanza"),
Function: LintDeployLabelsPresent, Function: LintDeployLabelsPresent,
}, },
{ {
Ref: "R010", Ref: "R010",
Level: "error", Level: gotext.Get("error"),
Description: "traefik routing enabled", Description: gotext.Get("traefik routing enabled"),
HowToResolve: "include \"traefik.enable=true\" deploy label", HowToResolve: gotext.Get("include \"traefik.enable=true\" deploy label"),
Function: LintTraefikEnabled, Function: LintTraefikEnabled,
SkipCondition: LintTraefikEnabledSkipCondition, SkipCondition: LintTraefikEnabledSkipCondition,
}, },
{ {
Ref: "R011", Ref: "R011",
Level: "error", Level: gotext.Get("error"),
Description: "all services have images", Description: gotext.Get("all services have images"),
HowToResolve: "ensure \"image: ...\" set on all services", HowToResolve: gotext.Get("ensure \"image: ...\" set on all services"),
Function: LintImagePresent, Function: LintImagePresent,
}, },
{ {
Ref: "R012", Ref: "R012",
Level: "error", Level: gotext.Get("error"),
Description: "config version are vendored", Description: gotext.Get("config version are vendored"),
HowToResolve: "vendor config versions in an abra.sh", HowToResolve: gotext.Get("vendor config versions in an abra.sh"),
Function: LintAbraShVendors, Function: LintAbraShVendors,
}, },
{ {
Ref: "R014", Ref: "R014",
Level: "error", Level: gotext.Get("error"),
Description: "only annotated tags used for recipe version", Description: gotext.Get("only annotated tags used for recipe version"),
HowToResolve: "replace lightweight tag with annotated tag", HowToResolve: gotext.Get("replace lightweight tag with annotated tag"),
Function: LintValidTags, Function: LintValidTags,
}, },
}, },
@ -182,9 +184,9 @@ var LintRules = map[string][]LintRule{
// used in code paths such as "app deploy" to avoid nasty surprises but not for // used in code paths such as "app deploy" to avoid nasty surprises but not for
// the typical linting commands, which do handle other levels. // the typical linting commands, which do handle other levels.
func LintForErrors(recipe recipe.Recipe) error { func LintForErrors(recipe recipe.Recipe) error {
log.Debugf("linting for critical errors in %s configs", recipe.Name) log.Debugf(gotext.Get("linting for critical errors in %s configs", recipe.Name))
var errors string var errs string
for level := range LintRules { for level := range LintRules {
if level != "error" { if level != "error" {
@ -198,19 +200,19 @@ func LintForErrors(recipe recipe.Recipe) error {
ok, err := rule.Function(recipe) ok, err := rule.Function(recipe)
if err != nil { if err != nil {
errors += fmt.Sprintf("\nlint %s: %s", rule.Ref, err) errs += gotext.Get("\nlint %s: %s", rule.Ref, err)
} }
if !ok { if !ok {
errors += fmt.Sprintf("\n * %s (%s)", rule.Description, rule.Ref) errs += fmt.Sprintf("\n * %s (%s)", rule.Description, rule.Ref)
} }
} }
} }
if len(errors) > 0 { if len(errs) > 0 {
return fmt.Errorf("recipe '%s' failed lint checks:\n"+errors[1:], recipe.Name) return errors.New(gotext.Get("recipe '%s' failed lint checks:\n"+errs[1:], recipe.Name))
} }
log.Debugf("linting successful, %s is well configured", recipe.Name) log.Debugf(gotext.Get("linting successful, %s is well configured", recipe.Name))
return nil return nil
} }
@ -256,7 +258,7 @@ func LintAppService(recipe recipe.Recipe) (bool, error) {
func LintTraefikEnabledSkipCondition(r recipe.Recipe) (bool, error) { func LintTraefikEnabledSkipCondition(r recipe.Recipe) (bool, error) {
sampleEnv, err := r.SampleEnv() sampleEnv, err := r.SampleEnv()
if err != nil { if err != nil {
return false, fmt.Errorf("Unable to discover .env.sample for %s", r.Name) return false, errors.New(gotext.Get("unable to discover .env.sample for %s", r.Name))
} }
if _, ok := sampleEnv["DOMAIN"]; !ok { if _, ok := sampleEnv["DOMAIN"]; !ok {
@ -476,7 +478,7 @@ func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
} }
for name := range config.Secrets { for name := range config.Secrets {
if len(name) > 12 { if len(name) > 12 {
return false, fmt.Errorf("secret %s is longer than 12 characters", name) return false, errors.New(gotext.Get("secret %s is longer than 12 characters", name))
} }
} }
@ -486,12 +488,12 @@ func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
func LintValidTags(recipe recipe.Recipe) (bool, error) { func LintValidTags(recipe recipe.Recipe) (bool, error) {
repo, err := git.PlainOpen(recipe.Dir) repo, err := git.PlainOpen(recipe.Dir)
if err != nil { if err != nil {
return false, fmt.Errorf("unable to open %s: %s", recipe.Dir, err) return false, errors.New(gotext.Get("unable to open %s: %s", recipe.Dir, err))
} }
iter, err := repo.Tags() iter, err := repo.Tags()
if err != nil { if err != nil {
log.Fatalf("unable to list local tags for %s", recipe.Name) log.Fatalf(gotext.Get("unable to list local tags for %s", recipe.Name))
} }
if err := iter.ForEach(func(ref *plumbing.Reference) error { if err := iter.ForEach(func(ref *plumbing.Reference) error {
@ -499,7 +501,7 @@ func LintValidTags(recipe recipe.Recipe) (bool, error) {
if err != nil { if err != nil {
switch err { switch err {
case plumbing.ErrObjectNotFound: case plumbing.ErrObjectNotFound:
return fmt.Errorf("invalid lightweight tag detected") return errors.New(gotext.Get("invalid lightweight tag detected"))
default: default:
return err return err
} }

View File

@ -3,6 +3,7 @@ package logs
import ( import (
"bufio" "bufio"
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -13,6 +14,7 @@ import (
containerTypes "github.com/docker/docker/api/types/container" containerTypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
dockerClient "github.com/docker/docker/client" dockerClient "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
type TailOpts struct { type TailOpts struct {
@ -81,7 +83,7 @@ func TailLogs(
} }
if _, err = io.Copy(os.Stdout, logs); err != nil && err != io.EOF { if _, err = io.Copy(os.Stdout, logs); err != nil && err != io.EOF {
errCh <- fmt.Errorf("tailLogs: unable to copy buffer: %s", err) errCh <- errors.New(gotext.Get("tailLogs: unable to copy buffer: %s", err))
} }
} }
}(service.ID) }(service.ID)

View File

@ -1,6 +1,7 @@
package recipe package recipe
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -13,6 +14,7 @@ import (
loader "coopcloud.tech/abra/pkg/upstream/stack" loader "coopcloud.tech/abra/pkg/upstream/stack"
"github.com/distribution/reference" "github.com/distribution/reference"
composetypes "github.com/docker/cli/cli/compose/types" composetypes "github.com/docker/cli/cli/compose/types"
"github.com/leonelquinteros/gotext"
) )
// GetComposeFiles gets the list of compose files for an app (or recipe if you // GetComposeFiles gets the list of compose files for an app (or recipe if you
@ -24,7 +26,7 @@ func (r Recipe) GetComposeFiles(appEnv map[string]string) ([]string, error) {
if err := ensurePathExists(r.ComposePath); err != nil { if err := ensurePathExists(r.ComposePath); err != nil {
return []string{}, err return []string{}, err
} }
log.Debugf("no COMPOSE_FILE detected, loading default: %s", r.ComposePath) log.Debugf(gotext.Get("no COMPOSE_FILE detected, loading default: %s", r.ComposePath))
return []string{r.ComposePath}, nil return []string{r.ComposePath}, nil
} }
@ -33,7 +35,7 @@ func (r Recipe) GetComposeFiles(appEnv map[string]string) ([]string, error) {
if err := ensurePathExists(path); err != nil { if err := ensurePathExists(path); err != nil {
return []string{}, err return []string{}, err
} }
log.Debugf("COMPOSE_FILE detected, loading %s", path) log.Debugf(gotext.Get("COMPOSE_FILE detected, loading %s", path))
return []string{path}, nil return []string{path}, nil
} }
@ -42,7 +44,7 @@ func (r Recipe) GetComposeFiles(appEnv map[string]string) ([]string, error) {
numComposeFiles := strings.Count(composeFileEnvVar, ":") + 1 numComposeFiles := strings.Count(composeFileEnvVar, ":") + 1
envVars := strings.SplitN(composeFileEnvVar, ":", numComposeFiles) envVars := strings.SplitN(composeFileEnvVar, ":", numComposeFiles)
if len(envVars) != numComposeFiles { if len(envVars) != numComposeFiles {
return composeFiles, fmt.Errorf("COMPOSE_FILE (=\"%s\") parsing failed?", composeFileEnvVar) return composeFiles, errors.New(gotext.Get("COMPOSE_FILE (=\"%s\") parsing failed?", composeFileEnvVar))
} }
for _, file := range envVars { for _, file := range envVars {
@ -53,8 +55,8 @@ func (r Recipe) GetComposeFiles(appEnv map[string]string) ([]string, error) {
composeFiles = append(composeFiles, path) composeFiles = append(composeFiles, path)
} }
log.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", ")) log.Debugf(gotext.Get("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", ")))
log.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), r.Name) log.Debugf(gotext.Get("retrieved %s configs for %s", strings.Join(composeFiles, ", "), r.Name))
return composeFiles, nil return composeFiles, nil
} }
@ -67,7 +69,7 @@ func (r Recipe) GetComposeConfig(env map[string]string) (*composetypes.Config, e
} }
if len(composeFiles) == 0 { if len(composeFiles) == 0 {
return nil, fmt.Errorf("%s is missing a compose.yml or compose.*.yml file?", r.Name) return nil, errors.New(gotext.Get("%s is missing a compose.yml or compose.*.yml file?", r.Name))
} }
if env == nil { if env == nil {
@ -102,7 +104,7 @@ func (r Recipe) GetVersionLabelLocal() (string, error) {
} }
if label == "" { if label == "" {
return label, fmt.Errorf("%s has no version label? try running \"abra recipe sync %s\" first?", r.Name, r.Name) return label, errors.New(gotext.Get("%s has no version label? try running \"abra recipe sync %s\" first?", r.Name, r.Name))
} }
return label, nil return label, nil
@ -118,7 +120,7 @@ func (r Recipe) UpdateTag(image, tag string) (bool, error) {
return false, err return false, err
} }
log.Debugf("considering %s config(s) for tag update", strings.Join(composeFiles, ", ")) log.Debugf(gotext.Get("considering %s config(s) for tag update", strings.Join(composeFiles, ", ")))
for _, composeFile := range composeFiles { for _, composeFile := range composeFiles {
opts := stack.Deploy{Composefiles: []string{composeFile}} opts := stack.Deploy{Composefiles: []string{composeFile}}
@ -148,13 +150,13 @@ func (r Recipe) UpdateTag(image, tag string) (bool, error) {
case reference.NamedTagged: case reference.NamedTagged:
composeTag = img.(reference.NamedTagged).Tag() composeTag = img.(reference.NamedTagged).Tag()
default: default:
log.Debugf("unable to parse %s, skipping", img) log.Debugf(gotext.Get("unable to parse %s, skipping", img))
continue continue
} }
composeImage := formatter.StripTagMeta(reference.Path(img)) composeImage := formatter.StripTagMeta(reference.Path(img))
log.Debugf("parsed %s from %s", composeTag, service.Image) log.Debugf(gotext.Get("parsed %s from %s", composeTag, service.Image))
if image == composeImage { if image == composeImage {
bytes, err := ioutil.ReadFile(composeFile) bytes, err := ioutil.ReadFile(composeFile)
@ -166,7 +168,7 @@ func (r Recipe) UpdateTag(image, tag string) (bool, error) {
new := fmt.Sprintf("%s:%s", composeImage, tag) new := fmt.Sprintf("%s:%s", composeImage, tag)
replacedBytes := strings.Replace(string(bytes), old, new, -1) replacedBytes := strings.Replace(string(bytes), old, new, -1)
log.Debugf("updating %s to %s in %s", old, new, compose.Filename) log.Debugf(gotext.Get("updating %s to %s in %s", old, new, compose.Filename))
if err := os.WriteFile(compose.Filename, []byte(replacedBytes), 0o764); err != nil { if err := os.WriteFile(compose.Filename, []byte(replacedBytes), 0o764); err != nil {
return false, err return false, err
@ -186,7 +188,7 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
return err return err
} }
log.Debugf("considering %s config(s) for label update", strings.Join(composeFiles, ", ")) log.Debugf(gotext.Get("considering %s config(s) for label update", strings.Join(composeFiles, ", ")))
for _, composeFile := range composeFiles { for _, composeFile := range composeFiles {
opts := stack.Deploy{Composefiles: []string{composeFile}} opts := stack.Deploy{Composefiles: []string{composeFile}}
@ -224,27 +226,27 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
return err return err
} }
old := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", value) old := gotext.Get("coop-cloud.${STACK_NAME}.version=%s", value)
replacedBytes := strings.Replace(string(bytes), old, label, -1) replacedBytes := strings.Replace(string(bytes), old, label, -1)
if old == label { if old == label {
log.Warnf("%s is already set, nothing to do?", label) log.Warnf(gotext.Get("%s is already set, nothing to do?", label))
return nil return nil
} }
log.Debugf("updating %s to %s in %s", old, label, compose.Filename) log.Debugf(gotext.Get("updating %s to %s in %s", old, label, compose.Filename))
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0o764); err != nil { if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0o764); err != nil {
return err return err
} }
log.Infof("synced label %s to service %s", label, serviceName) log.Infof(gotext.Get("synced label %s to service %s", label, serviceName))
} }
} }
if !discovered { if !discovered {
log.Warn("no existing label found, automagic insertion not supported yet") log.Warn(gotext.Get("no existing label found, automagic insertion not supported yet"))
log.Fatalf("add '- \"%s\"' manually to the 'app' service in %s", label, composeFile) log.Fatalf(gotext.Get("add '- \"%s\"' manually to the 'app' service in %s", label, composeFile))
} }
} }

View File

@ -1,18 +1,20 @@
package recipe package recipe
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path" "path"
"coopcloud.tech/abra/pkg/envfile" "coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/formatter"
"github.com/leonelquinteros/gotext"
) )
func (r Recipe) SampleEnv() (map[string]string, error) { func (r Recipe) SampleEnv() (map[string]string, error) {
sampleEnv, err := envfile.ReadEnv(r.SampleEnvPath) sampleEnv, err := envfile.ReadEnv(r.SampleEnvPath)
if err != nil { if err != nil {
return sampleEnv, fmt.Errorf("unable to discover .env.sample for %s", r.Name) return sampleEnv, errors.New(gotext.Get("unable to discover .env.sample for %s", r.Name))
} }
return sampleEnv, nil return sampleEnv, nil
} }
@ -31,7 +33,7 @@ func (r Recipe) GetReleaseNotes(version string) (string, error) {
return "", err return "", err
} }
title := formatter.BoldStyle.Render(fmt.Sprintf("%s release notes:", version)) title := formatter.BoldStyle.Render(gotext.Get("%s release notes:", version))
withTitle := fmt.Sprintf("%s\n%s\n", title, releaseNotes) withTitle := fmt.Sprintf("%s\n%s\n", title, releaseNotes)
return withTitle, nil return withTitle, nil

View File

@ -1,6 +1,7 @@
package recipe package recipe
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"slices" "slices"
@ -15,6 +16,7 @@ import (
"github.com/distribution/reference" "github.com/distribution/reference"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/leonelquinteros/gotext"
) )
type EnsureContext struct { type EnsureContext struct {
@ -45,9 +47,9 @@ func (r Recipe) Ensure(ctx EnsureContext) error {
} }
if r.EnvVersion != "" && !ctx.IgnoreEnvVersion { if r.EnvVersion != "" && !ctx.IgnoreEnvVersion {
log.Debugf("ensuring env version %s", r.EnvVersion) log.Debugf(gotext.Get("ensuring env version %s", r.EnvVersion))
if strings.Contains(r.EnvVersion, "+U") { if strings.Contains(r.EnvVersion, "+U") {
return fmt.Errorf("can not redeploy chaos version (%s) without --chaos", r.EnvVersion) return errors.New(gotext.Get("can not redeploy chaos version (%s) without --chaos", r.EnvVersion))
} }
if _, err := r.EnsureVersion(r.EnvVersion); err != nil { if _, err := r.EnsureVersion(r.EnvVersion); err != nil {
@ -146,16 +148,16 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
joinedTags := strings.Join(parsedTags, ", ") joinedTags := strings.Join(parsedTags, ", ")
if joinedTags != "" { if joinedTags != "" {
log.Debugf("read %s as tags for recipe %s", joinedTags, r.Name) log.Debugf(gotext.Get("read %s as tags for recipe %s", joinedTags, r.Name))
} }
var opts *git.CheckoutOptions var opts *git.CheckoutOptions
if tagRef.String() == "" { if tagRef.String() == "" {
log.Debugf("attempting to checkout '%s' as chaos commit", version) log.Debugf(gotext.Get("attempting to checkout '%s' as chaos commit", version))
hash, err := repo.ResolveRevision(plumbing.Revision(version)) hash, err := repo.ResolveRevision(plumbing.Revision(version))
if err != nil { if err != nil {
log.Fatalf("unable to resolve '%s': %s", version, err) log.Fatalf(gotext.Get("unable to resolve '%s': %s", version, err))
} }
opts = &git.CheckoutOptions{Hash: *hash, Create: false, Force: true} opts = &git.CheckoutOptions{Hash: *hash, Create: false, Force: true}
@ -173,7 +175,7 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
return isChaosCommit, nil return isChaosCommit, nil
} }
log.Debugf("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir) log.Debugf(gotext.Get("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir))
return isChaosCommit, nil return isChaosCommit, nil
} }
@ -182,11 +184,11 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
func (r Recipe) EnsureIsClean() error { func (r Recipe) EnsureIsClean() error {
isClean, err := gitPkg.IsClean(r.Dir) isClean, err := gitPkg.IsClean(r.Dir)
if err != nil { if err != nil {
return fmt.Errorf("unable to check git clean status in %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to check git clean status in %s: %s", r.Dir, err))
} }
if !isClean { if !isClean {
return fmt.Errorf("%s (%s) has locally unstaged changes?", r.Name, r.Dir) return errors.New(gotext.Get("%s (%s) has locally unstaged changes?", r.Name, r.Dir))
} }
return nil return nil
@ -220,7 +222,7 @@ func (r Recipe) EnsureLatest() error {
} }
if err := worktree.Checkout(checkOutOpts); err != nil { if err := worktree.Checkout(checkOutOpts); err != nil {
log.Debugf("failed to check out %s in %s", branch, r.Dir) log.Debugf(gotext.Get("failed to check out %s in %s", branch, r.Dir))
return err return err
} }
@ -231,33 +233,33 @@ func (r Recipe) EnsureLatest() error {
func (r Recipe) EnsureUpToDate() error { func (r Recipe) EnsureUpToDate() error {
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
if err != nil { if err != nil {
return fmt.Errorf("unable to open %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to open %s: %s", r.Dir, err))
} }
remotes, err := repo.Remotes() remotes, err := repo.Remotes()
if err != nil { if err != nil {
return fmt.Errorf("unable to read remotes in %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to read remotes in %s: %s", r.Dir, err))
} }
if len(remotes) == 0 { if len(remotes) == 0 {
log.Debugf("cannot ensure %s is up-to-date, no git remotes configured", r.Name) log.Debugf(gotext.Get("cannot ensure %s is up-to-date, no git remotes configured", r.Name))
return nil return nil
} }
worktree, err := repo.Worktree() worktree, err := repo.Worktree()
if err != nil { if err != nil {
return fmt.Errorf("unable to open git work tree in %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to open git work tree in %s: %s", r.Dir, err))
} }
branch, err := gitPkg.CheckoutDefaultBranch(repo, r.Dir) branch, err := gitPkg.CheckoutDefaultBranch(repo, r.Dir)
if err != nil { if err != nil {
return fmt.Errorf("unable to check out default branch in %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to check out default branch in %s: %s", r.Dir, err))
} }
fetchOpts := &git.FetchOptions{Tags: git.AllTags} fetchOpts := &git.FetchOptions{Tags: git.AllTags}
if err := repo.Fetch(fetchOpts); err != nil { if err := repo.Fetch(fetchOpts); err != nil {
if !strings.Contains(err.Error(), "already up-to-date") { if !strings.Contains(err.Error(), "already up-to-date") {
return fmt.Errorf("unable to fetch tags in %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to fetch tags in %s: %s", r.Dir, err))
} }
} }
@ -269,11 +271,11 @@ func (r Recipe) EnsureUpToDate() error {
if err := worktree.Pull(opts); err != nil { if err := worktree.Pull(opts); err != nil {
if !strings.Contains(err.Error(), "already up-to-date") { if !strings.Contains(err.Error(), "already up-to-date") {
return fmt.Errorf("unable to git pull in %s: %s", r.Dir, err) return errors.New(gotext.Get("unable to git pull in %s: %s", r.Dir, err))
} }
} }
log.Debugf("fetched latest git changes for %s", r.Name) log.Debugf(gotext.Get("fetched latest git changes for %s", r.Name))
return nil return nil
} }
@ -362,7 +364,7 @@ func (r Recipe) Tags() ([]string, error) {
return version1.IsLessThan(version2) return version1.IsLessThan(version2)
}) })
log.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name) log.Debugf(gotext.Get("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name))
return tags, nil return tags, nil
} }
@ -373,7 +375,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
versions := RecipeVersions{} versions := RecipeVersions{}
log.Debugf("git: opening repository in %s", r.Dir) log.Debugf(gotext.Get("git: opening repository in %s", r.Dir))
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
if err != nil { if err != nil {
@ -393,7 +395,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
if err := gitTags.ForEach(func(ref *plumbing.Reference) (err error) { if err := gitTags.ForEach(func(ref *plumbing.Reference) (err error) {
tag := strings.TrimPrefix(string(ref.Name()), "refs/tags/") tag := strings.TrimPrefix(string(ref.Name()), "refs/tags/")
log.Debugf("processing %s for %s", tag, r.Name) log.Debugf(gotext.Get("processing %s for %s", tag, r.Name))
checkOutOpts := &git.CheckoutOptions{ checkOutOpts := &git.CheckoutOptions{
Create: false, Create: false,
@ -401,11 +403,11 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
Branch: plumbing.ReferenceName(ref.Name()), Branch: plumbing.ReferenceName(ref.Name()),
} }
if err := worktree.Checkout(checkOutOpts); err != nil { if err := worktree.Checkout(checkOutOpts); err != nil {
log.Debugf("failed to check out %s in %s", tag, r.Dir) log.Debugf(gotext.Get("failed to check out %s in %s", tag, r.Dir))
return err return err
} }
log.Debugf("git checkout: %s in %s", ref.Name(), r.Dir) log.Debugf(gotext.Get("git checkout: %s in %s", ref.Name(), r.Dir))
config, err := r.GetComposeConfig(nil) config, err := r.GetComposeConfig(nil)
if err != nil { if err != nil {
@ -429,7 +431,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
case reference.NamedTagged: case reference.NamedTagged:
tag = img.(reference.NamedTagged).Tag() tag = img.(reference.NamedTagged).Tag()
case reference.Named: case reference.Named:
warnMsg = append(warnMsg, fmt.Sprintf("%s service is missing image tag?", path)) warnMsg = append(warnMsg, gotext.Get("%s service is missing image tag?", path))
continue continue
} }
@ -453,7 +455,7 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
sortRecipeVersions(versions) sortRecipeVersions(versions)
log.Debugf("collected %s for %s", versions, r.Dir) log.Debugf(gotext.Get("collected %s for %s", versions, r.Dir))
var uniqueWarnings []string var uniqueWarnings []string
for _, w := range warnMsg { for _, w := range warnMsg {

View File

@ -13,6 +13,7 @@ import (
"strings" "strings"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/leonelquinteros/gotext"
"coopcloud.tech/abra/pkg/catalogue" "coopcloud.tech/abra/pkg/catalogue"
"coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/config"
@ -70,7 +71,7 @@ func (r RecipeMeta) LatestVersion() string {
version = tag version = tag
} }
log.Debugf("choosing %s as latest version of %s", version, r.Name) log.Debugf(gotext.Get("choosing %s as latest version of %s", version, r.Name))
return version return version
} }
@ -126,7 +127,7 @@ func Get(name string) Recipe {
if strings.Contains(name, ":") { if strings.Contains(name, ":") {
split := strings.Split(name, ":") split := strings.Split(name, ":")
if len(split) > 2 { if len(split) > 2 {
log.Fatalf("version seems invalid: %s", name) log.Fatalf(gotext.Get("version seems invalid: %s", name))
} }
name = split[0] name = split[0]
@ -134,7 +135,7 @@ func Get(name string) Recipe {
versionRaw = version versionRaw = version
if strings.HasSuffix(version, config.DIRTY_DEFAULT) { if strings.HasSuffix(version, config.DIRTY_DEFAULT) {
version = strings.Replace(split[1], config.DIRTY_DEFAULT, "", 1) version = strings.Replace(split[1], config.DIRTY_DEFAULT, "", 1)
log.Debugf("removed dirty suffix from .env version: %s -> %s", split[1], version) log.Debugf(gotext.Get("removed dirty suffix from .env version: %s -> %s", split[1], version))
} }
} }
@ -143,7 +144,7 @@ func Get(name string) Recipe {
if strings.Contains(name, "/") { if strings.Contains(name, "/") {
u, err := url.Parse(name) u, err := url.Parse(name)
if err != nil { if err != nil {
log.Fatalf("invalid recipe: %s", err) log.Fatalf(gotext.Get("invalid recipe: %s", err))
} }
u.Scheme = "https" u.Scheme = "https"
gitURL = u.String() + ".git" gitURL = u.String() + ".git"
@ -171,7 +172,7 @@ func Get(name string) Recipe {
dirty, err := r.IsDirty() dirty, err := r.IsDirty()
if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) { if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
log.Fatalf("failed to check git status of %s: %s", r.Name, err) log.Fatalf(gotext.Get("failed to check git status of %s: %s", r.Name, err))
} }
r.Dirty = dirty r.Dirty = dirty
@ -195,16 +196,16 @@ type Recipe struct {
// String outputs a human-friendly string representation. // String outputs a human-friendly string representation.
func (r Recipe) String() string { func (r Recipe) String() string {
out := fmt.Sprintf("{name: %s, ", r.Name) out := gotext.Get("{name: %s, ", r.Name)
out += fmt.Sprintf("version : %s, ", r.EnvVersion) out += gotext.Get("version : %s, ", r.EnvVersion)
out += fmt.Sprintf("dirty: %v, ", r.Dirty) out += gotext.Get("dirty: %v, ", r.Dirty)
out += fmt.Sprintf("dir: %s, ", r.Dir) out += gotext.Get("dir: %s, ", r.Dir)
out += fmt.Sprintf("git url: %s, ", r.GitURL) out += gotext.Get("git url: %s, ", r.GitURL)
out += fmt.Sprintf("ssh url: %s, ", r.SSHURL) out += gotext.Get("ssh url: %s, ", r.SSHURL)
out += fmt.Sprintf("compose: %s, ", r.ComposePath) out += gotext.Get("compose: %s, ", r.ComposePath)
out += fmt.Sprintf("readme: %s, ", r.ReadmePath) out += gotext.Get("readme: %s, ", r.ReadmePath)
out += fmt.Sprintf("sample env: %s, ", r.SampleEnvPath) out += gotext.Get("sample env: %s, ", r.SampleEnvPath)
out += fmt.Sprintf("abra.sh: %s}", r.AbraShPath) out += gotext.Get("abra.sh: %s}", r.AbraShPath)
return out return out
} }
@ -233,7 +234,7 @@ func GetRecipeFeaturesAndCategory(r Recipe) (Features, string, []string, error)
feat = Features{} feat = Features{}
) )
log.Debugf("%s: attempt recipe metadata parse", r.ReadmePath) log.Debugf(gotext.Get("%s: attempt recipe metadata parse", r.ReadmePath))
readmeFS, err := ioutil.ReadFile(r.ReadmePath) readmeFS, err := ioutil.ReadFile(r.ReadmePath)
if err != nil { if err != nil {
@ -321,12 +322,12 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, []string, error
if imageRowString != "" { if imageRowString != "" {
warnMsgs = append( warnMsgs = append(
warnMsgs, warnMsgs,
fmt.Sprintf("%s: image meta has incorrect format: %s", recipeName, imageRowString), gotext.Get("%s: image meta has incorrect format: %s", recipeName, imageRowString),
) )
} else { } else {
warnMsgs = append( warnMsgs = append(
warnMsgs, warnMsgs,
fmt.Sprintf("%s: image meta is empty?", recipeName), gotext.Get("%s: image meta is empty?", recipeName),
) )
} }
@ -357,14 +358,14 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, []string, error
func GetStringInBetween(recipeName, str, start, end string) (result string, err error) { func GetStringInBetween(recipeName, str, start, end string) (result string, err error) {
s := strings.Index(str, start) s := strings.Index(str, start)
if s == -1 { if s == -1 {
return "", fmt.Errorf("%s: marker string %s not found", recipeName, start) return "", errors.New(gotext.Get("%s: marker string %s not found", recipeName, start))
} }
s += len(start) s += len(start)
e := strings.Index(str[s:], end) e := strings.Index(str[s:], end)
if e == -1 { if e == -1 {
return "", fmt.Errorf("%s: end marker %s not found", recipeName, end) return "", errors.New(gotext.Get("%s: end marker %s not found", recipeName, end))
} }
return str[s : s+e], nil return str[s : s+e], nil
@ -402,7 +403,7 @@ func readRecipeCatalogueFS(target interface{}) error {
return err return err
} }
log.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON) log.Debugf(gotext.Get("read recipe catalogue from file system cache in %s", config.RECIPES_JSON))
return nil return nil
} }
@ -431,7 +432,7 @@ func VersionsOfService(recipe, serviceName string, offline bool) ([]string, erro
} }
} }
log.Debugf("detected versions %s for %s", strings.Join(versions, ", "), recipe) log.Debugf(gotext.Get("detected versions %s for %s", strings.Join(versions, ", "), recipe))
return versions, nil return versions, nil
} }
@ -454,11 +455,11 @@ func GetRecipeMeta(recipeName string, offline bool) (RecipeMeta, error) {
recipeMeta, ok := catl[recipeName] recipeMeta, ok := catl[recipeName]
if !ok { if !ok {
return RecipeMeta{}, RecipeMissingFromCatalogue{ return RecipeMeta{}, RecipeMissingFromCatalogue{
err: fmt.Sprintf("recipe %s does not exist?", recipeName), err: gotext.Get("recipe %s does not exist?", recipeName),
} }
} }
log.Debugf("recipe metadata retrieved for %s", recipeName) log.Debugf(gotext.Get("recipe metadata retrieved for %s", recipeName))
return recipeMeta, nil return recipeMeta, nil
} }
@ -545,13 +546,13 @@ func ReadReposMetadata(debug bool) (RepoCatalogue, error) {
reposMeta := make(RepoCatalogue) reposMeta := make(RepoCatalogue)
pageIdx := 1 pageIdx := 1
bar := formatter.CreateProgressbar(-1, "collecting recipe listing") bar := formatter.CreateProgressbar(-1, gotext.Get("collecting recipe listing"))
for { for {
var reposList []RepoMeta var reposList []RepoMeta
pagedURL := fmt.Sprintf("%s?page=%v", ReposMetadataURL, pageIdx) pagedURL := fmt.Sprintf("%s?page=%v", ReposMetadataURL, pageIdx)
log.Debugf("fetching repo metadata from %s", pagedURL) log.Debugf(gotext.Get("fetching repo metadata from %s", pagedURL))
if err := web.ReadJSON(pagedURL, &reposList); err != nil { if err := web.ReadJSON(pagedURL, &reposList); err != nil {
return reposMeta, err return reposMeta, err
@ -655,7 +656,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string, debug bool) erro
cloneLimiter := limit.New(3) cloneLimiter := limit.New(3)
retrieveBar := formatter.CreateProgressbar(barLength, "retrieving recipes") retrieveBar := formatter.CreateProgressbar(barLength, gotext.Get("retrieving recipes"))
ch := make(chan string, barLength) ch := make(chan string, barLength)
for _, repoMeta := range repos { for _, repoMeta := range repos {
go func(rm RepoMeta) { go func(rm RepoMeta) {

View File

@ -6,12 +6,13 @@ import (
"os/exec" "os/exec"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
) )
// PassInsertSecret inserts a secret into a pass store. // PassInsertSecret inserts a secret into a pass store.
func PassInsertSecret(secretValue, secretName, appName, server string) error { func PassInsertSecret(secretValue, secretName, appName, server string) error {
if _, err := exec.LookPath("pass"); err != nil { if _, err := exec.LookPath("pass"); err != nil {
return errors.New("pass command not found on $PATH, is it installed?") return errors.New(gotext.Get("pass command not found on $PATH, is it installed?"))
} }
cmd := fmt.Sprintf( cmd := fmt.Sprintf(
@ -19,13 +20,13 @@ func PassInsertSecret(secretValue, secretName, appName, server string) error {
secretValue, server, appName, secretName, secretValue, server, appName, secretName,
) )
log.Debugf("attempting to run %s", cmd) log.Debugf(gotext.Get("attempting to run %s", cmd))
if err := exec.Command("bash", "-c", cmd).Run(); err != nil { if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err return err
} }
log.Infof("%s inserted into pass store", secretName) log.Infof(gotext.Get("%s inserted into pass store", secretName))
return nil return nil
} }
@ -33,7 +34,7 @@ func PassInsertSecret(secretValue, secretName, appName, server string) error {
// PassRmSecret deletes a secret from a pass store. // PassRmSecret deletes a secret from a pass store.
func PassRmSecret(secretName, appName, server string) error { func PassRmSecret(secretName, appName, server string) error {
if _, err := exec.LookPath("pass"); err != nil { if _, err := exec.LookPath("pass"); err != nil {
return errors.New("pass command not found on $PATH, is it installed?") return errors.New(gotext.Get("pass command not found on $PATH, is it installed?"))
} }
cmd := fmt.Sprintf( cmd := fmt.Sprintf(
@ -41,13 +42,13 @@ func PassRmSecret(secretName, appName, server string) error {
server, appName, secretName, server, appName, secretName,
) )
log.Debugf("attempting to run %s", cmd) log.Debugf(gotext.Get("attempting to run %s", cmd))
if err := exec.Command("bash", "-c", cmd).Run(); err != nil { if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err return err
} }
log.Infof("%s removed from pass store", secretName) log.Infof(gotext.Get("%s removed from pass store", secretName))
return nil return nil
} }

View File

@ -5,6 +5,7 @@ package secret
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"slices" "slices"
"strconv" "strconv"
@ -21,6 +22,7 @@ import (
"github.com/decentral1se/passgen" "github.com/decentral1se/passgen"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
dockerClient "github.com/docker/docker/client" dockerClient "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
// Secret represents a secret. // Secret represents a secret.
@ -57,7 +59,7 @@ func GeneratePassword(length uint, charset string) (string, error) {
return "", err return "", err
} }
log.Debugf("generated %s", strings.Join(passwords, ", ")) log.Debugf(gotext.Get("generated %s", strings.Join(passwords, ", ")))
return passwords[0], nil return passwords[0], nil
} }
@ -75,7 +77,7 @@ func GeneratePassphrase() (string, error) {
return "", err return "", err
} }
log.Debugf("generated %s", strings.Join(passphrases, ", ")) log.Debugf(gotext.Get("generated %s", strings.Join(passphrases, ", ")))
return passphrases[0], nil return passphrases[0], nil
} }
@ -114,18 +116,18 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
} }
if len(enabledSecrets) == 0 { if len(enabledSecrets) == 0 {
log.Debugf("not generating app secrets, none enabled in recipe config") log.Debugf(gotext.Get("not generating app secrets, none enabled in recipe config"))
return nil, nil return nil, nil
} }
secretValues := map[string]Secret{} secretValues := map[string]Secret{}
for secretId, secretConfig := range composeConfig.Secrets { for secretId, secretConfig := range composeConfig.Secrets {
if string(secretConfig.Name[len(secretConfig.Name)-1]) == "_" { if string(secretConfig.Name[len(secretConfig.Name)-1]) == "_" {
return nil, fmt.Errorf("missing version for secret? (%s)", secretId) return nil, errors.New(gotext.Get("missing version for secret? (%s)", secretId))
} }
if !(slices.Contains(enabledSecrets, secretId)) { if !(slices.Contains(enabledSecrets, secretId)) {
log.Warnf("%s not enabled in recipe config, skipping", secretId) log.Warnf(gotext.Get("%s not enabled in recipe config, skipping", secretId))
continue continue
} }
@ -134,7 +136,7 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
value := Secret{Version: secretVersion, RemoteName: secretConfig.Name} value := Secret{Version: secretVersion, RemoteName: secretConfig.Name}
if len(value.RemoteName) > config.MAX_DOCKER_SECRET_LENGTH { if len(value.RemoteName) > config.MAX_DOCKER_SECRET_LENGTH {
return nil, fmt.Errorf("secret %s is > %d chars when combined with %s", secretId, config.MAX_DOCKER_SECRET_LENGTH, stackName) return nil, errors.New(gotext.Get("secret %s is > %d chars when combined with %s", secretId, config.MAX_DOCKER_SECRET_LENGTH, stackName))
} }
// Check if the length modifier is set for this secret. // Check if the length modifier is set for this secret.
@ -202,12 +204,12 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
defer wg.Done() defer wg.Done()
if secret.SkipGenerate { if secret.SkipGenerate {
log.Debugf("skipping generation of %s (generate=false)", secretName) log.Debugf(gotext.Get("skipping generation of %s (generate=false)", secretName))
ch <- nil ch <- nil
return return
} }
log.Debugf("attempting to generate and store %s on %s", secret.RemoteName, server) log.Debugf(gotext.Get("attempting to generate and store %s on %s", secret.RemoteName, server))
if secret.Length > 0 { if secret.Length > 0 {
password, err := GeneratePassword(uint(secret.Length), secret.Charset) password, err := GeneratePassword(uint(secret.Length), secret.Charset)
@ -218,7 +220,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
if err := client.StoreSecret(cl, secret.RemoteName, password, server); err != nil { if err := client.StoreSecret(cl, secret.RemoteName, password, server); err != nil {
if strings.Contains(err.Error(), "AlreadyExists") { if strings.Contains(err.Error(), "AlreadyExists") {
log.Warnf("%s already exists", secret.RemoteName) log.Warnf(gotext.Get("%s already exists", secret.RemoteName))
ch <- nil ch <- nil
} else { } else {
ch <- err ch <- err
@ -238,7 +240,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
if err := client.StoreSecret(cl, secret.RemoteName, passphrase, server); err != nil { if err := client.StoreSecret(cl, secret.RemoteName, passphrase, server); err != nil {
if strings.Contains(err.Error(), "AlreadyExists") { if strings.Contains(err.Error(), "AlreadyExists") {
log.Warnf("%s already exists", secret.RemoteName) log.Warnf(gotext.Get("%s already exists", secret.RemoteName))
ch <- nil ch <- nil
} else { } else {
ch <- err ch <- err
@ -263,7 +265,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
} }
} }
log.Debugf("generated and stored %v on %s", secrets, server) log.Debugf(gotext.Get("generated and stored %v on %s", secrets, server))
return secretsGenerated, nil return secretsGenerated, nil
} }

View File

@ -6,6 +6,7 @@ import (
"coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
) )
// CreateServerDir creates a server directory under ~/.abra. // CreateServerDir creates a server directory under ~/.abra.
@ -17,11 +18,11 @@ func CreateServerDir(serverName string) error {
return err return err
} }
log.Debugf("%s already exists", serverPath) log.Debugf(gotext.Get("%s already exists", serverPath))
return nil return nil
} }
log.Debugf("successfully created %s", serverPath) log.Debugf(gotext.Get("successfully created %s", serverPath))
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package service
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@ -12,6 +13,7 @@ import (
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
// GetService retrieves a service container based on a label. If prompt is true // GetService retrieves a service container based on a label. If prompt is true
@ -25,7 +27,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
} }
if len(services) == 0 { if len(services) == 0 {
return swarm.Service{}, fmt.Errorf("no services deployed?") return swarm.Service{}, errors.New(gotext.Get("no services deployed?"))
} }
var matchingServices []swarm.Service var matchingServices []swarm.Service
@ -36,7 +38,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
} }
if len(matchingServices) == 0 { if len(matchingServices) == 0 {
return swarm.Service{}, fmt.Errorf("no services deployed matching label '%s'?", label) return swarm.Service{}, errors.New(gotext.Get("no services deployed matching label '%s'?", label))
} }
if len(matchingServices) > 1 { if len(matchingServices) > 1 {
@ -48,15 +50,15 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
} }
if !prompt { if !prompt {
err := fmt.Errorf("expected 1 service but found %v: %s", len(matchingServices), strings.Join(servicesRaw, " ")) err := errors.New(gotext.Get("expected 1 service but found %v: %s", len(matchingServices), strings.Join(servicesRaw, " ")))
return swarm.Service{}, err return swarm.Service{}, err
} }
log.Warnf("ambiguous service list received, prompting for input") log.Warnf(gotext.Get("ambiguous service list received, prompting for input"))
var response string var response string
prompt := &survey.Select{ prompt := &survey.Select{
Message: "which service are you looking for?", Message: gotext.Get("which service are you looking for?"),
Options: servicesRaw, Options: servicesRaw,
} }
@ -72,7 +74,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
} }
} }
log.Fatal("failed to match chosen service") log.Fatal(gotext.Get("failed to match chosen service"))
} }
return matchingServices[0], nil return matchingServices[0], nil
@ -90,7 +92,7 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
if len(services) == 0 { if len(services) == 0 {
filter := filters.Get("name")[0] filter := filters.Get("name")[0]
return swarm.Service{}, fmt.Errorf("no services matching the %v filter found?", filter) return swarm.Service{}, errors.New(gotext.Get("no services matching the %v filter found?", filter))
} }
if len(services) != 1 { if len(services) != 1 {
@ -98,19 +100,19 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
for _, service := range services { for _, service := range services {
serviceName := service.Spec.Name serviceName := service.Spec.Name
created := formatter.HumanDuration(service.CreatedAt.Unix()) created := formatter.HumanDuration(service.CreatedAt.Unix())
servicesRaw = append(servicesRaw, fmt.Sprintf("%s (created %v)", serviceName, created)) servicesRaw = append(servicesRaw, gotext.Get("%s (created %v)", serviceName, created))
} }
if !prompt { if !prompt {
err := fmt.Errorf("expected 1 service but found %v: %s", len(services), strings.Join(servicesRaw, " ")) err := errors.New(gotext.Get("expected 1 service but found %v: %s", len(services), strings.Join(servicesRaw, " ")))
return swarm.Service{}, err return swarm.Service{}, err
} }
log.Warnf("ambiguous service list received, prompting for input") log.Warnf(gotext.Get("ambiguous service list received, prompting for input"))
var response string var response string
prompt := &survey.Select{ prompt := &survey.Select{
Message: "which service are you looking for?", Message: gotext.Get("which service are you looking for?"),
Options: servicesRaw, Options: servicesRaw,
} }
@ -126,7 +128,7 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
} }
} }
log.Fatal("failed to match chosen service") log.Fatal(gotext.Get("failed to match chosen service"))
} }
return services[0], nil return services[0], nil

View File

@ -1,8 +1,10 @@
package ssh package ssh
import ( import (
"fmt" "errors"
"strings" "strings"
"github.com/leonelquinteros/gotext"
) )
// Fatal is a error output wrapper which aims to make SSH failures easier to // Fatal is a error output wrapper which aims to make SSH failures easier to
@ -11,17 +13,17 @@ func Fatal(hostname string, err error) error {
out := err.Error() out := err.Error()
if strings.Contains(out, "Host key verification failed.") { if strings.Contains(out, "Host key verification failed.") {
return fmt.Errorf("SSH host key verification failed for %s", hostname) return errors.New(gotext.Get("SSH host key verification failed for %s", hostname))
} else if strings.Contains(out, "Could not resolve hostname") { } else if strings.Contains(out, "Could not resolve hostname") {
return fmt.Errorf("could not resolve hostname for %s", hostname) return errors.New(gotext.Get("could not resolve hostname for %s", hostname))
} else if strings.Contains(out, "Connection timed out") { } else if strings.Contains(out, "Connection timed out") {
return fmt.Errorf("connection timed out for %s", hostname) return errors.New(gotext.Get("connection timed out for %s", hostname))
} else if strings.Contains(out, "Permission denied") { } else if strings.Contains(out, "Permission denied") {
return fmt.Errorf("ssh auth: permission denied for %s", hostname) return errors.New(gotext.Get("ssh auth: permission denied for %s", hostname))
} else if strings.Contains(out, "Network is unreachable") { } else if strings.Contains(out, "Network is unreachable") {
return fmt.Errorf("unable to connect to %s, please check your SSH config", hostname) return errors.New(gotext.Get("unable to connect to %s, please check your SSH config", hostname))
} else if strings.Contains(out, "Is the docker daemon running") { } else if strings.Contains(out, "Is the docker daemon running") {
return fmt.Errorf("docker: is the daemon running / your user has docker permissions?") return errors.New(gotext.Get("docker: is the daemon running / your user has docker permissions?"))
} }
return err return err

View File

@ -3,7 +3,6 @@ package ui
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"sort" "sort"
"strings" "strings"
@ -17,6 +16,7 @@ import (
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
dockerClient "github.com/docker/docker/client" dockerClient "github.com/docker/docker/client"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/leonelquinteros/gotext"
) )
var IsRunning bool var IsRunning bool
@ -79,13 +79,13 @@ type stream struct {
} }
func (s stream) String() string { func (s stream) String() string {
out := fmt.Sprintf("{decoder: %v, ", s.decoder) out := gotext.Get("{decoder: %v, ", s.decoder)
out += fmt.Sprintf("err: %v, ", s.Err) out += gotext.Get("err: %v, ", s.Err)
out += fmt.Sprintf("id: %s, ", s.id) out += gotext.Get("id: %s, ", s.id)
out += fmt.Sprintf("name: %s, ", s.Name) out += gotext.Get("name: %s, ", s.Name)
out += fmt.Sprintf("reader: %v, ", s.reader) out += gotext.Get("reader: %v, ", s.reader)
out += fmt.Sprintf("writer: %v, ", s.writer) out += gotext.Get("writer: %v, ", s.writer)
out += fmt.Sprintf("status: %s, ", s.status) out += gotext.Get("status: %s, ", s.status)
return out return out
} }
@ -118,7 +118,7 @@ func (s stream) process() tea.Msg {
func (s stream) healthcheck(m Model) tea.Msg { func (s stream) healthcheck(m Model) tea.Msg {
filters := filters.NewArgs() filters := filters.NewArgs()
filters.Add("name", fmt.Sprintf("^%s", s.Name)) filters.Add("name", gotext.Get("^%s", s.Name))
containers, err := m.cl.ContainerList(m.ctx, containerTypes.ListOptions{Filters: filters}) containers, err := m.cl.ContainerList(m.ctx, containerTypes.ListOptions{Filters: filters})
if err != nil { if err != nil {
@ -327,10 +327,10 @@ func (m Model) View() string {
status := stream.status status := stream.status
if strings.Contains(stream.status, "converged") && !stream.rollback { if strings.Contains(stream.status, "converged") && !stream.rollback {
status = "succeeded" status = gotext.Get("succeeded")
} }
if strings.Contains(stream.status, "rolled back") { if strings.Contains(stream.status, "rolled back") {
status = "rolled back" status = gotext.Get("rolled back")
} }
retries := 0 retries := 0
@ -338,7 +338,7 @@ func (m Model) View() string {
retries = stream.retries retries = stream.retries
} }
output := fmt.Sprintf("%s: %s (retries: %v, healthcheck: %s)", output := gotext.Get("%s: %s (retries: %v, healthcheck: %s)",
formatter.BoldStyle.Render(short), formatter.BoldStyle.Render(short),
status, status,
retries, retries,

View File

@ -17,7 +17,6 @@ package commandconn
import ( import (
"bytes" "bytes"
"context" "context"
"fmt"
"io" "io"
"net" "net"
"os" "os"
@ -28,6 +27,7 @@ import (
"time" "time"
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors" "github.com/pkg/errors"
exec "golang.org/x/sys/execabs" exec "golang.org/x/sys/execabs"
) )
@ -46,7 +46,7 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
) )
c.cmd = exec.CommandContext(ctx, cmd, args...) c.cmd = exec.CommandContext(ctx, cmd, args...)
// we assume that args never contains sensitive information // we assume that args never contains sensitive information
log.Debugf("commandconn: starting %s with %v", cmd, args) log.Debugf(gotext.Get("commandconn: starting %s with %v", cmd, args))
c.cmd.Env = os.Environ() c.cmd.Env = os.Environ()
c.cmd.SysProcAttr = &syscall.SysProcAttr{} c.cmd.SysProcAttr = &syscall.SysProcAttr{}
setPdeathsig(c.cmd) setPdeathsig(c.cmd)
@ -62,7 +62,7 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
c.cmd.Stderr = &stderrWriter{ c.cmd.Stderr = &stderrWriter{
stderrMu: &c.stderrMu, stderrMu: &c.stderrMu,
stderr: &c.stderr, stderr: &c.stderr,
debugPrefix: fmt.Sprintf("commandconn (%s):", cmd), debugPrefix: gotext.Get("commandconn (%s):", cmd),
} }
c.localAddr = dummyAddr{network: "dummy", s: "dummy-0"} c.localAddr = dummyAddr{network: "dummy", s: "dummy-0"}
c.remoteAddr = dummyAddr{network: "dummy", s: "dummy-1"} c.remoteAddr = dummyAddr{network: "dummy", s: "dummy-1"}
@ -138,7 +138,7 @@ func (c *commandConn) kill() error {
return nil return nil
} }
} }
return errors.Wrapf(werr, "commandconn: failed to wait") return errors.Wrap(werr, gotext.Get("commandconn: failed to wait"))
} }
func (c *commandConn) onEOF(eof error) error { func (c *commandConn) onEOF(eof error) error {
@ -159,7 +159,7 @@ func (c *commandConn) onEOF(eof error) error {
c.stderrMu.Lock() c.stderrMu.Lock()
stderr := c.stderr.String() stderr := c.stderr.String()
c.stderrMu.Unlock() c.stderrMu.Unlock()
return errors.Errorf("command %v did not exit after %v: stderr=%q", c.cmd.Args, eof, stderr) return errors.New(gotext.Get("command %v did not exit after %v: stderr=%q", c.cmd.Args, eof, stderr))
} }
} }
c.cmdMutex.Unlock() c.cmdMutex.Unlock()
@ -169,7 +169,7 @@ func (c *commandConn) onEOF(eof error) error {
c.stderrMu.Lock() c.stderrMu.Lock()
stderr := c.stderr.String() stderr := c.stderr.String()
c.stderrMu.Unlock() c.stderrMu.Unlock()
return errors.Errorf("command %v has exited with %v, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=%s", c.cmd.Args, werr, stderr) return errors.New(gotext.Get("command %v has exited with %v, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=%s", c.cmd.Args, werr, stderr))
} }
func ignorableCloseError(err error) bool { func ignorableCloseError(err error) bool {
@ -236,7 +236,7 @@ func (c *commandConn) Write(p []byte) (int, error) {
func (c *commandConn) Close() error { func (c *commandConn) Close() error {
var err error var err error
if err = c.CloseRead(); err != nil { if err = c.CloseRead(); err != nil {
log.Warnf("commandConn.Close: CloseRead: %v", err) log.Warnf(gotext.Get("commandConn.Close: CloseRead: %v", err))
} }
if err = c.CloseWrite(); err != nil { if err = c.CloseWrite(); err != nil {
// muted because https://github.com/docker/compose/issues/8544 // muted because https://github.com/docker/compose/issues/8544
@ -252,15 +252,15 @@ func (c *commandConn) RemoteAddr() net.Addr {
return c.remoteAddr return c.remoteAddr
} }
func (c *commandConn) SetDeadline(t time.Time) error { func (c *commandConn) SetDeadline(t time.Time) error {
log.Debugf("unimplemented call: SetDeadline(%v)", t) log.Debugf(gotext.Get("unimplemented call: SetDeadline(%v)", t))
return nil return nil
} }
func (c *commandConn) SetReadDeadline(t time.Time) error { func (c *commandConn) SetReadDeadline(t time.Time) error {
log.Debugf("unimplemented call: SetReadDeadline(%v)", t) log.Debugf(gotext.Get("unimplemented call: SetReadDeadline(%v)", t))
return nil return nil
} }
func (c *commandConn) SetWriteDeadline(t time.Time) error { func (c *commandConn) SetWriteDeadline(t time.Time) error {
log.Debugf("unimplemented call: SetWriteDeadline(%v)", t) log.Debugf(gotext.Get("unimplemented call: SetWriteDeadline(%v)", t))
return nil return nil
} }

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/docker"
dCliContextStore "github.com/docker/cli/cli/context/store" dCliContextStore "github.com/docker/cli/cli/context/store"
dClient "github.com/docker/docker/client" dClient "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -34,7 +35,7 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*connhelper.Conne
case "ssh": case "ssh":
ctxConnDetails, err := ssh.ParseURL(daemonURL) ctxConnDetails, err := ssh.ParseURL(daemonURL)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "ssh host connection is not valid") return nil, errors.Wrap(err, gotext.Get("ssh host connection is not valid"))
} }
return &connhelper.ConnectionHelper{ return &connhelper.ConnectionHelper{

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
apiclient "github.com/docker/docker/client" apiclient "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
) )
// RunExec runs a command on a remote container. io.Writer corresponds to the // RunExec runs a command on a remote container. io.Writer corresponds to the
@ -39,7 +40,7 @@ func RunExec(dockerCli command.Cli, client *apiclient.Client, containerID string
execID := response.ID execID := response.ID
if execID == "" { if execID == "" {
return nil, errors.New("exec ID empty") return nil, errors.New(gotext.Get("exec ID empty"))
} }
if execOptions.Detach { if execOptions.Detach {
@ -104,12 +105,12 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclie
if execOpts.Tty && dockerCli.In().IsTerminal() { if execOpts.Tty && dockerCli.In().IsTerminal() {
if err := MonitorTtySize(ctx, client, dockerCli, execID, true); err != nil { if err := MonitorTtySize(ctx, client, dockerCli, execID, true); err != nil {
fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err) fmt.Fprintln(dockerCli.Err(), gotext.Get("Error monitoring TTY size:"), err)
} }
} }
if err := <-errCh; err != nil { if err := <-errCh; err != nil {
log.Debugf("Error hijack: %s", err) log.Debugf(gotext.Get("Error hijack: %s", err))
return out, err return out, err
} }

View File

@ -2,7 +2,7 @@ package container // https://github.com/docker/cli/blob/master/cli/command/conta
import ( import (
"context" "context"
"fmt" "errors"
"io" "io"
"runtime" "runtime"
"sync" "sync"
@ -12,6 +12,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/leonelquinteros/gotext"
"github.com/moby/term" "github.com/moby/term"
) )
@ -39,7 +40,7 @@ type hijackedIOStreamer struct {
func (h *hijackedIOStreamer) stream(ctx context.Context) error { func (h *hijackedIOStreamer) stream(ctx context.Context) error {
restoreInput, err := h.setupInput() restoreInput, err := h.setupInput()
if err != nil { if err != nil {
return fmt.Errorf("unable to setup input stream: %s", err) return errors.New(gotext.Get("unable to setup input stream: %s", err))
} }
defer restoreInput() defer restoreInput()
@ -78,7 +79,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
} }
if err := setRawTerminal(h.streams); err != nil { if err := setRawTerminal(h.streams); err != nil {
return nil, fmt.Errorf("unable to set IO streams as raw terminal: %s", err) return nil, errors.New(gotext.Get("unable to set IO streams as raw terminal: %s", err))
} }
// Use sync.Once so we may call restore multiple times but ensure we // Use sync.Once so we may call restore multiple times but ensure we
@ -96,7 +97,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
if h.detachKeys != "" { if h.detachKeys != "" {
customEscapeKeys, err := term.ToBytes(h.detachKeys) customEscapeKeys, err := term.ToBytes(h.detachKeys)
if err != nil { if err != nil {
log.Warnf("invalid detach escape keys, using default: %s", err) log.Warnf(gotext.Get("invalid detach escape keys, using default: %s", err))
} else { } else {
escapeKeys = customEscapeKeys escapeKeys = customEscapeKeys
} }
@ -128,10 +129,10 @@ func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
_, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader) _, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader)
} }
log.Debug("[hijack] End of stdout") log.Debug(gotext.Get("[hijack] end of stdout"))
if err != nil { if err != nil {
log.Debugf("Error receiveStdout: %s", err) log.Debugf(gotext.Get("error receiveStdout: %s", err))
} }
outputDone <- err outputDone <- err
@ -152,7 +153,7 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// messages will be in normal type. // messages will be in normal type.
restoreInput() restoreInput()
log.Debug("[hijack] End of stdin") log.Debug(gotext.Get("[hijack] End of stdin"))
if _, ok := err.(term.EscapeError); ok { if _, ok := err.(term.EscapeError); ok {
detached <- err detached <- err
@ -163,12 +164,12 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// This error will also occur on the receive // This error will also occur on the receive
// side (from stdout) where it will be // side (from stdout) where it will be
// propagated back to the caller. // propagated back to the caller.
log.Debugf("Error sendStdin: %s", err) log.Debugf(gotext.Get("error sendStdin: %s", err))
} }
} }
if err := h.resp.CloseWrite(); err != nil { if err := h.resp.CloseWrite(); err != nil {
log.Debugf("Couldn't send EOF: %s", err) log.Debugf(gotext.Get("couldn't send EOF: %s", err))
} }
close(inputDone) close(inputDone)

View File

@ -13,6 +13,7 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
apiclient "github.com/docker/docker/client" apiclient "github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
"github.com/moby/sys/signal" "github.com/moby/sys/signal"
) )
@ -35,7 +36,7 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin
} }
if err != nil { if err != nil {
log.Debugf("Error resize: %s\r", err) log.Debugf(gotext.Get("error resize: %s\r", err))
} }
return err return err
} }
@ -62,7 +63,7 @@ func initTtySize(ctx context.Context, client *apiclient.Client, cli command.Cli,
} }
} }
if err != nil { if err != nil {
fmt.Fprintln(cli.Err(), "failed to resize tty, using default size") fmt.Fprintln(cli.Err(), gotext.Get("failed to resize tty, using default size"))
} }
}() }()
} }

View File

@ -18,6 +18,7 @@ import (
"github.com/docker/docker/api/types/versions" "github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -39,7 +40,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
for _, secret := range requestedSecrets { for _, secret := range requestedSecrets {
if _, exists := secretRefs[secret.File.Name]; exists { if _, exists := secretRefs[secret.File.Name]; exists {
return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName) return nil, errors.New(gotext.Get("duplicate secret target for %s not allowed", secret.SecretName))
} }
secretRef := new(swarmtypes.SecretReference) secretRef := new(swarmtypes.SecretReference)
*secretRef = *secret *secretRef = *secret
@ -68,7 +69,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
for _, ref := range secretRefs { for _, ref := range secretRefs {
id, ok := foundSecrets[ref.SecretName] id, ok := foundSecrets[ref.SecretName]
if !ok { if !ok {
return nil, errors.Errorf("secret not found: %s", ref.SecretName) return nil, errors.New(gotext.Get("secret not found: %s", ref.SecretName))
} }
// set the id for the ref to properly assign in swarm // set the id for the ref to properly assign in swarm
@ -118,7 +119,7 @@ func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarmtypes.
} }
if _, exists := configRefs[config.File.Name]; exists { if _, exists := configRefs[config.File.Name]; exists {
return nil, errors.Errorf("duplicate config target for %s not allowed", config.ConfigName) return nil, errors.New(gotext.Get("duplicate config target for %s not allowed", config.ConfigName))
} }
configRefs[config.File.Name] = configRef configRefs[config.File.Name] = configRef
@ -149,7 +150,7 @@ func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarmtypes.
for _, ref := range configRefs { for _, ref := range configRefs {
id, ok := foundConfigs[ref.ConfigName] id, ok := foundConfigs[ref.ConfigName]
if !ok { if !ok {
return nil, errors.Errorf("config not found: %s", ref.ConfigName) return nil, errors.New(gotext.Get("config not found: %s", ref.ConfigName))
} }
// set the id for the ref to properly assign in swarm // set the id for the ref to properly assign in swarm
@ -164,7 +165,7 @@ func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarmtypes.
for _, ref := range runtimeRefs { for _, ref := range runtimeRefs {
id, ok := foundConfigs[ref.ConfigName] id, ok := foundConfigs[ref.ConfigName]
if !ok { if !ok {
return nil, errors.Errorf("config not found: %s", ref.ConfigName) return nil, errors.New(gotext.Get("config not found: %s", ref.ConfigName))
} }
ref.ConfigID = id ref.ConfigID = id
@ -371,7 +372,7 @@ func convertServiceNetworks(
for networkName, network := range networks { for networkName, network := range networks {
networkConfig, ok := networkConfigs[networkName] networkConfig, ok := networkConfigs[networkName]
if !ok && networkName != defaultNetwork { if !ok && networkName != defaultNetwork {
return nil, errors.Errorf("undefined network %q", networkName) return nil, errors.New(gotext.Get("undefined network %q", networkName))
} }
var aliases []string var aliases []string
if network != nil { if network != nil {
@ -410,7 +411,7 @@ func convertServiceSecrets(
lookup := func(key string) (composetypes.FileObjectConfig, error) { lookup := func(key string) (composetypes.FileObjectConfig, error) {
secretSpec, exists := secretSpecs[key] secretSpec, exists := secretSpecs[key]
if !exists { if !exists {
return composetypes.FileObjectConfig{}, errors.Errorf("undefined secret %q", key) return composetypes.FileObjectConfig{}, errors.New(gotext.Get("undefined secret %q", key))
} }
return composetypes.FileObjectConfig(secretSpec), nil return composetypes.FileObjectConfig(secretSpec), nil
} }
@ -458,7 +459,7 @@ func convertServiceConfigObjs(
lookup := func(key string) (composetypes.FileObjectConfig, error) { lookup := func(key string) (composetypes.FileObjectConfig, error) {
configSpec, exists := configSpecs[key] configSpec, exists := configSpecs[key]
if !exists { if !exists {
return composetypes.FileObjectConfig{}, errors.Errorf("undefined config %q", key) return composetypes.FileObjectConfig{}, errors.New(gotext.Get("undefined config %q", key))
} }
return composetypes.FileObjectConfig(configSpec), nil return composetypes.FileObjectConfig(configSpec), nil
} }
@ -600,7 +601,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
) )
if healthcheck.Disable { if healthcheck.Disable {
if len(healthcheck.Test) != 0 { if len(healthcheck.Test) != 0 {
return nil, errors.Errorf("test and disable can't be set at the same time") return nil, errors.New(gotext.Get("test and disable can't be set at the same time"))
} }
return &container.HealthConfig{ return &container.HealthConfig{
Test: []string{"NONE"}, Test: []string{"NONE"},
@ -648,7 +649,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
MaxAttempts: &attempts, MaxAttempts: &attempts,
}, nil }, nil
default: default:
return nil, errors.Errorf("unknown restart policy: %s", restart) return nil, errors.New(gotext.Get("unknown restart policy: %s", restart))
} }
} }
@ -770,13 +771,13 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
switch mode { switch mode {
case "global": case "global":
if replicas != nil { if replicas != nil {
return serviceMode, errors.Errorf("replicas can only be used with replicated mode") return serviceMode, errors.New(gotext.Get("replicas can only be used with replicated mode"))
} }
serviceMode.Global = &swarm.GlobalService{} serviceMode.Global = &swarm.GlobalService{}
case "replicated", "": case "replicated", "":
serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas} serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas}
default: default:
return serviceMode, errors.Errorf("Unknown mode: %s", mode) return serviceMode, errors.New(gotext.Get("unknown mode: %s", mode))
} }
return serviceMode, nil return serviceMode, nil
} }
@ -809,9 +810,9 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
case l == 0: case l == 0:
return nil, nil return nil, nil
case l == 2: case l == 2:
return nil, errors.Errorf("invalid credential spec: cannot specify both %s and %s", o[0], o[1]) return nil, errors.New(gotext.Get("invalid credential spec: cannot specify both %s and %s", o[0], o[1]))
case l > 2: case l > 2:
return nil, errors.Errorf("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1]) return nil, errors.New(gotext.Get("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1]))
} }
swarmCredSpec := swarm.CredentialSpec(spec) swarmCredSpec := swarm.CredentialSpec(spec)
// if we're using a swarm Config for the credential spec, over-write it // if we're using a swarm Config for the credential spec, over-write it
@ -830,7 +831,7 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
return &swarmCredSpec, nil return &swarmCredSpec, nil
} }
} }
return nil, errors.Errorf("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config) return nil, errors.New(gotext.Get("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config))
} }
return &swarmCredSpec, nil return &swarmCredSpec, nil
} }

View File

@ -3,6 +3,7 @@ package convert // https://github.com/docker/cli/blob/master/cli/compose/convert
import ( import (
composetypes "github.com/docker/cli/cli/compose/types" composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/mount"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -40,10 +41,10 @@ func handleVolumeToMount(
result := createMountFromVolume(volume) result := createMountFromVolume(volume)
if volume.Tmpfs != nil { if volume.Tmpfs != nil {
return mount.Mount{}, errors.New("tmpfs options are incompatible with type volume") return mount.Mount{}, errors.New(gotext.Get("tmpfs options are incompatible with type volume"))
} }
if volume.Bind != nil { if volume.Bind != nil {
return mount.Mount{}, errors.New("bind options are incompatible with type volume") return mount.Mount{}, errors.New(gotext.Get("bind options are incompatible with type volume"))
} }
// Anonymous volumes // Anonymous volumes
if volume.Source == "" { if volume.Source == "" {
@ -52,7 +53,7 @@ func handleVolumeToMount(
stackVolume, exists := stackVolumes[volume.Source] stackVolume, exists := stackVolumes[volume.Source]
if !exists { if !exists {
return mount.Mount{}, errors.Errorf("undefined volume %q", volume.Source) return mount.Mount{}, errors.New(gotext.Get("undefined volume %q", volume.Source))
} }
result.Source = namespace.Scope(volume.Source) result.Source = namespace.Scope(volume.Source)
@ -86,13 +87,13 @@ func handleBindToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, er
result := createMountFromVolume(volume) result := createMountFromVolume(volume)
if volume.Source == "" { if volume.Source == "" {
return mount.Mount{}, errors.New("invalid bind source, source cannot be empty") return mount.Mount{}, errors.New(gotext.Get("invalid bind source, source cannot be empty"))
} }
if volume.Volume != nil { if volume.Volume != nil {
return mount.Mount{}, errors.New("volume options are incompatible with type bind") return mount.Mount{}, errors.New(gotext.Get("volume options are incompatible with type bind"))
} }
if volume.Tmpfs != nil { if volume.Tmpfs != nil {
return mount.Mount{}, errors.New("tmpfs options are incompatible with type bind") return mount.Mount{}, errors.New(gotext.Get("tmpfs options are incompatible with type bind"))
} }
if volume.Bind != nil { if volume.Bind != nil {
result.BindOptions = &mount.BindOptions{ result.BindOptions = &mount.BindOptions{
@ -106,13 +107,13 @@ func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
result := createMountFromVolume(volume) result := createMountFromVolume(volume)
if volume.Source != "" { if volume.Source != "" {
return mount.Mount{}, errors.New("invalid tmpfs source, source must be empty") return mount.Mount{}, errors.New(gotext.Get("invalid tmpfs source, source must be empty"))
} }
if volume.Bind != nil { if volume.Bind != nil {
return mount.Mount{}, errors.New("bind options are incompatible with type tmpfs") return mount.Mount{}, errors.New(gotext.Get("bind options are incompatible with type tmpfs"))
} }
if volume.Volume != nil { if volume.Volume != nil {
return mount.Mount{}, errors.New("volume options are incompatible with type tmpfs") return mount.Mount{}, errors.New(gotext.Get("volume options are incompatible with type tmpfs"))
} }
if volume.Tmpfs != nil { if volume.Tmpfs != nil {
result.TmpfsOptions = &mount.TmpfsOptions{ result.TmpfsOptions = &mount.TmpfsOptions{
@ -126,13 +127,13 @@ func handleNpipeToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
result := createMountFromVolume(volume) result := createMountFromVolume(volume)
if volume.Source == "" { if volume.Source == "" {
return mount.Mount{}, errors.New("invalid npipe source, source cannot be empty") return mount.Mount{}, errors.New(gotext.Get("invalid npipe source, source cannot be empty"))
} }
if volume.Volume != nil { if volume.Volume != nil {
return mount.Mount{}, errors.New("volume options are incompatible with type npipe") return mount.Mount{}, errors.New(gotext.Get("volume options are incompatible with type npipe"))
} }
if volume.Tmpfs != nil { if volume.Tmpfs != nil {
return mount.Mount{}, errors.New("tmpfs options are incompatible with type npipe") return mount.Mount{}, errors.New(gotext.Get("tmpfs options are incompatible with type npipe"))
} }
if volume.Bind != nil { if volume.Bind != nil {
result.BindOptions = &mount.BindOptions{ result.BindOptions = &mount.BindOptions{
@ -158,5 +159,5 @@ func convertVolumeToMount(
case "npipe": case "npipe":
return handleNpipeToMount(volume) return handleNpipeToMount(volume)
} }
return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs or npipe") return mount.Mount{}, errors.New(gotext.Get("volume type must be volume, bind, tmpfs or npipe"))
} }

View File

@ -3,11 +3,13 @@ package web
import ( import (
"encoding/json" "encoding/json"
"fmt" "errors"
"io" "io"
"net/http" "net/http"
"os" "os"
"time" "time"
"github.com/leonelquinteros/gotext"
) )
// Timeout is the time it takes before a web request bails out waiting for a // Timeout is the time it takes before a web request bails out waiting for a
@ -40,7 +42,7 @@ func GetFile(filepath string, url string) (err error) {
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return fmt.Errorf("bad status: %s", resp.Status) return errors.New(gotext.Get("bad status: %s", resp.Status))
} }
_, err = io.Copy(out, resp.Body) _, err = io.Copy(out, resp.Body)