diff --git a/cli/app/rollback.go b/cli/app/rollback.go index 223ceda7..a13acbc8 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -53,7 +53,7 @@ recipes. conf := runtime.New() if !internal.Chaos { - if err := recipe.EnsureUpToDate(app.Recipe); err != nil { + if err := recipe.EnsureUpToDate(app.Recipe, conf); err != nil { logrus.Fatal(err) } } diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 8ea8f4b0..2784d9f4 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -61,7 +61,7 @@ recipes. } if !internal.Chaos { - if err := recipe.EnsureUpToDate(app.Recipe); err != nil { + if err := recipe.EnsureUpToDate(app.Recipe, conf); err != nil { logrus.Fatal(err) } } diff --git a/cli/catalogue/catalogue.go b/cli/catalogue/catalogue.go index b4699a88..5e255d48 100644 --- a/cli/catalogue/catalogue.go +++ b/cli/catalogue/catalogue.go @@ -13,6 +13,7 @@ import ( "coopcloud.tech/abra/pkg/formatter" gitPkg "coopcloud.tech/abra/pkg/git" "coopcloud.tech/abra/pkg/recipe" + "coopcloud.tech/abra/pkg/runtime" "github.com/go-git/go-git/v5" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -54,6 +55,8 @@ keys configured on your account. ArgsUsage: "[]", Action: func(c *cli.Context) error { recipeName := c.Args().First() + conf := runtime.New() + if recipeName != "" { internal.ValidateRecipe(c) } @@ -79,7 +82,7 @@ keys configured on your account. if !internal.SkipUpdates { logrus.Warn(logMsg) - if err := recipe.UpdateRepositories(repos, recipeName); err != nil { + if err := recipe.UpdateRepositories(repos, recipeName, conf); err != nil { logrus.Fatal(err) } } @@ -97,7 +100,7 @@ keys configured on your account. continue } - versions, err := recipe.GetRecipeVersions(recipeMeta.Name) + versions, err := recipe.GetRecipeVersions(recipeMeta.Name, conf) if err != nil { logrus.Warn(err) } diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 3993aecd..da4b26cb 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -33,7 +33,7 @@ func DeployAction(c *cli.Context) error { } if !Chaos { - if err := recipe.EnsureUpToDate(app.Recipe); err != nil { + if err := recipe.EnsureUpToDate(app.Recipe, conf); err != nil { logrus.Fatal(err) } } diff --git a/cli/internal/new.go b/cli/internal/new.go index b05f2937..5ad8ca88 100644 --- a/cli/internal/new.go +++ b/cli/internal/new.go @@ -122,7 +122,8 @@ func ensureServerFlag() error { func NewAction(c *cli.Context) error { recipe := ValidateRecipeWithPrompt(c, runtime.WithEnsureRecipeLatest(false)) - if err := recipePkg.EnsureUpToDate(recipe.Name); err != nil { + conf := runtime.New(runtime.WithEnsureRecipeLatest(false)) + if err := recipePkg.EnsureUpToDate(recipe.Name, conf); err != nil { logrus.Fatal(err) } diff --git a/cli/recipe/fetch.go b/cli/recipe/fetch.go index b124c80c..3968f418 100644 --- a/cli/recipe/fetch.go +++ b/cli/recipe/fetch.go @@ -4,6 +4,7 @@ import ( "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/recipe" + "coopcloud.tech/abra/pkg/runtime" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -21,6 +22,8 @@ var recipeFetchCommand = cli.Command{ BashComplete: autocomplete.RecipeNameComplete, Action: func(c *cli.Context) error { recipeName := c.Args().First() + conf := runtime.New() + if recipeName != "" { internal.ValidateRecipe(c) return nil // ValidateRecipe ensures latest checkout @@ -31,7 +34,7 @@ var recipeFetchCommand = cli.Command{ logrus.Fatal(err) } - if err := recipe.UpdateRepositories(repos, recipeName); err != nil { + if err := recipe.UpdateRepositories(repos, recipeName, conf); err != nil { logrus.Fatal(err) } diff --git a/cli/recipe/lint.go b/cli/recipe/lint.go index f9e8e6a5..e5e440d3 100644 --- a/cli/recipe/lint.go +++ b/cli/recipe/lint.go @@ -8,6 +8,7 @@ import ( "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/lint" recipePkg "coopcloud.tech/abra/pkg/recipe" + "coopcloud.tech/abra/pkg/runtime" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -25,8 +26,9 @@ var recipeLintCommand = cli.Command{ BashComplete: autocomplete.RecipeNameComplete, Action: func(c *cli.Context) error { recipe := internal.ValidateRecipe(c) + conf := runtime.New() - if err := recipePkg.EnsureUpToDate(recipe.Name); err != nil { + if err := recipePkg.EnsureUpToDate(recipe.Name, conf); err != nil { logrus.Fatal(err) } diff --git a/cli/recipe/upgrade.go b/cli/recipe/upgrade.go index 8f7beeeb..dfbc849f 100644 --- a/cli/recipe/upgrade.go +++ b/cli/recipe/upgrade.go @@ -14,6 +14,7 @@ import ( "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/formatter" recipePkg "coopcloud.tech/abra/pkg/recipe" + "coopcloud.tech/abra/pkg/runtime" "coopcloud.tech/tagcmp" "github.com/AlecAivazis/survey/v2" "github.com/docker/distribution/reference" @@ -60,8 +61,9 @@ You may invoke this command in "wizard" mode and be prompted for input: Before: internal.SubCommandBefore, Action: func(c *cli.Context) error { recipe := internal.ValidateRecipeWithPrompt(c) + conf := runtime.New() - if err := recipePkg.EnsureUpToDate(recipe.Name); err != nil { + if err := recipePkg.EnsureUpToDate(recipe.Name, conf); err != nil { logrus.Fatal(err) } diff --git a/cli/updater/updater.go b/cli/updater/updater.go index e00034c5..af849b99 100644 --- a/cli/updater/updater.go +++ b/cli/updater/updater.go @@ -321,7 +321,7 @@ func processRecipeRepoVersion(recipeName, version string, conf *runtime.Config) return err } - if err := recipe.EnsureUpToDate(recipeName); err != nil { + if err := recipe.EnsureUpToDate(recipeName, conf); err != nil { return err } diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index cd47f820..1ec9112f 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -587,7 +587,11 @@ func GetStringInBetween(recipeName, str, start, end string) (result string, err } // EnsureUpToDate ensures that the local repo is synced to the remote -func EnsureUpToDate(recipeName string) error { +func EnsureUpToDate(recipeName string, conf *runtime.Config) error { + if !conf.EnsureRecipeLatest { + return nil + } + recipeDir := path.Join(config.RECIPES_DIR, recipeName) isClean, err := gitPkg.IsClean(recipeDir) @@ -932,10 +936,8 @@ func ReadReposMetadata() (RepoCatalogue, error) { } // GetRecipeVersions retrieves all recipe versions. -func GetRecipeVersions(recipeName string, opts ...runtime.Option) (RecipeVersions, error) { +func GetRecipeVersions(recipeName string, conf *runtime.Config) (RecipeVersions, error) { versions := RecipeVersions{} - conf := runtime.New(opts...) - recipeDir := path.Join(config.RECIPES_DIR, recipeName) logrus.Debugf("attempting to open git repository in %s", recipeDir) @@ -1037,7 +1039,7 @@ func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]stri } // UpdateRepositories clones and updates all recipe repositories locally. -func UpdateRepositories(repos RepoCatalogue, recipeName string) error { +func UpdateRepositories(repos RepoCatalogue, recipeName string, conf *runtime.Config) error { var barLength int if recipeName != "" { barLength = 1 @@ -1071,7 +1073,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error { logrus.Fatal(err) } - if err := EnsureUpToDate(rm.Name); err != nil { + if err := EnsureUpToDate(rm.Name, conf); err != nil { logrus.Fatal(err) } diff --git a/pkg/runtime/runtime.go b/pkg/runtime/runtime.go index a8580738..e604b4e1 100644 --- a/pkg/runtime/runtime.go +++ b/pkg/runtime/runtime.go @@ -11,7 +11,10 @@ type Config struct { EnsureRecipeLatest bool // ensure the local recipe has latest changes } -// Option modified a Config. +// Option modified a Config. The convetion for passing Options to functions is +// so far, only used in internal/validate.go. A Config is then constructed and +// passed down further into the code. This may change in the future but this is +// at least the abstraction so far. type Option func(c *Config) // New instantiates a new Config.