refactor(recipe): load load compoes config where its used

This commit is contained in:
2024-07-08 12:31:39 +02:00
parent 99da8d4e57
commit c1b03bcbd7
16 changed files with 263 additions and 230 deletions

View File

@ -58,13 +58,8 @@ recipes.
log.Fatal("cannot use <version> and --chaos together")
}
r2 := recipe.Get2(app.Recipe)
if err := r2.Ensure(internal.Chaos, internal.Offline); err != nil {
log.Fatal(err)
}
r, err := recipe.Get(app.Recipe, internal.Offline)
if err != nil {
r := recipe.Get2(app.Recipe)
if err := r.Ensure(internal.Chaos, internal.Offline); err != nil {
log.Fatal(err)
}
@ -92,7 +87,7 @@ recipes.
if specificVersion != "" {
version = specificVersion
log.Debugf("choosing %s as version to deploy", version)
if err := r2.EnsureVersion(version); err != nil {
if err := r.EnsureVersion(version); err != nil {
log.Fatal(err)
}
}
@ -128,7 +123,7 @@ recipes.
if len(versions) == 0 && !internal.Chaos {
log.Warn("no published versions in catalogue, trying local recipe repository")
recipeVersions, err := recipe.GetRecipeVersions(app.Recipe, internal.Offline)
recipeVersions, err := r.GetRecipeVersions(internal.Offline)
if err != nil {
log.Warn(err)
}
@ -142,7 +137,7 @@ recipes.
if len(versions) > 0 && !internal.Chaos {
version = versions[len(versions)-1]
log.Debugf("choosing %s as version to deploy", version)
if err := r2.EnsureVersion(version); err != nil {
if err := r.EnsureVersion(version); err != nil {
log.Fatal(err)
}
} else {
@ -158,7 +153,7 @@ recipes.
if internal.Chaos {
log.Warnf("chaos mode engaged")
var err error
version, err = r2.ChaosVersion()
version, err = r.ChaosVersion()
if err != nil {
log.Fatal(err)
}
@ -173,7 +168,7 @@ recipes.
app.Env[k] = v
}
composeFiles, err := r2.GetComposeFiles(app.Env)
composeFiles, err := r.GetComposeFiles(app.Env)
if err != nil {
log.Fatal(err)
}

View File

@ -80,7 +80,7 @@ var appNewCommand = cli.Command{
if c.Args().Get(1) == "" {
var version string
recipeVersions, err := recipePkg.GetRecipeVersions(recipe.Name, internal.Offline)
recipeVersions, err := r.GetRecipeVersions(internal.Offline)
if err != nil {
log.Fatal(err)
}

View File

@ -58,13 +58,8 @@ recipes.
log.Fatal("cannot use <version> and --chaos together")
}
r2 := recipe.Get2(app.Recipe)
if err := r2.Ensure(internal.Chaos, internal.Offline); err != nil {
log.Fatal(err)
}
r, err := recipe.Get(app.Recipe, internal.Offline)
if err != nil {
r := recipe.Get2(app.Recipe)
if err := r.Ensure(internal.Chaos, internal.Offline); err != nil {
log.Fatal(err)
}
@ -100,7 +95,7 @@ recipes.
if len(versions) == 0 && !internal.Chaos {
log.Warn("no published versions in catalogue, trying local recipe repository")
recipeVersions, err := recipe.GetRecipeVersions(app.Recipe, internal.Offline)
recipeVersions, err := r.GetRecipeVersions(internal.Offline)
if err != nil {
log.Warn(err)
}
@ -170,7 +165,7 @@ recipes.
}
if !internal.Chaos {
if err := r2.EnsureVersion(chosenDowngrade); err != nil {
if err := r.EnsureVersion(chosenDowngrade); err != nil {
log.Fatal(err)
}
}
@ -178,7 +173,7 @@ recipes.
if internal.Chaos {
log.Warn("chaos mode engaged")
var err error
chosenDowngrade, err = r2.ChaosVersion()
chosenDowngrade, err = r.ChaosVersion()
if err != nil {
log.Fatal(err)
}
@ -193,7 +188,7 @@ recipes.
app.Env[k] = v
}
composeFiles, err := r2.GetComposeFiles(app.Env)
composeFiles, err := r.GetComposeFiles(app.Env)
if err != nil {
log.Fatal(err)
}

View File

@ -69,12 +69,8 @@ recipes.
log.Fatal(err)
}
recipe, err := recipePkg.Get(app.Recipe, internal.Offline)
if err != nil {
log.Fatal(err)
}
if err := lint.LintForErrors(recipe); err != nil {
r2 := recipePkg.Get2(app.Recipe)
if err := lint.LintForErrors(r2); err != nil {
log.Fatal(err)
}
@ -106,7 +102,7 @@ recipes.
if len(versions) == 0 && !internal.Chaos {
log.Warn("no published versions in catalogue, trying local recipe repository")
recipeVersions, err := recipePkg.GetRecipeVersions(app.Recipe, internal.Offline)
recipeVersions, err := r2.GetRecipeVersions(internal.Offline)
if err != nil {
log.Warn(err)
}

View File

@ -99,7 +99,7 @@ keys configured on your account.
continue
}
versions, err := recipe.GetRecipeVersions(recipeMeta.Name, internal.Offline)
versions, err := r.GetRecipeVersions(internal.Offline)
if err != nil {
log.Warn(err)
}

View File

@ -85,10 +85,14 @@ func SetBumpType(bumpType string) {
}
// GetMainAppImage retrieves the main 'app' image name
func GetMainAppImage(recipe recipe.Recipe) (string, error) {
func GetMainAppImage(recipe recipe.Recipe2) (string, error) {
var path string
for _, service := range recipe.Config.Services {
config, err := recipe.GetComposeConfig(nil)
if err != nil {
return "", err
}
for _, service := range config.Services {
if service.Name == "app" {
img, err := reference.ParseNormalizedNamed(service.Image)
if err != nil {

View File

@ -47,7 +47,7 @@ var recipeLintCommand = cli.Command{
}
skipped := false
if rule.Skip(recipe) {
if rule.Skip(r) {
skipped = true
}
@ -58,7 +58,7 @@ var recipeLintCommand = cli.Command{
satisfied := false
if !skipped {
ok, err := rule.Function(recipe)
ok, err := rule.Function(r)
if err != nil {
log.Warn(err)
}

View File

@ -65,12 +65,12 @@ your SSH keys configured on your account.
recipe := internal.ValidateRecipe(c)
r := recipePkg.Get2(recipe.Name)
imagesTmp, err := getImageVersions(recipe)
imagesTmp, err := getImageVersions(r)
if err != nil {
log.Fatal(err)
}
mainApp, err := internal.GetMainAppImage(recipe)
mainApp, err := internal.GetMainAppImage(r)
if err != nil {
log.Fatal(err)
}
@ -104,7 +104,7 @@ your SSH keys configured on your account.
if tagString == "" && (!internal.Major && !internal.Minor && !internal.Patch) {
var err error
tagString, err = getLabelVersion(recipe, false)
tagString, err = getLabelVersion(r, false)
if err != nil {
log.Fatal(err)
}
@ -143,11 +143,15 @@ your SSH keys configured on your account.
}
// getImageVersions retrieves image versions for a recipe
func getImageVersions(recipe recipe.Recipe) (map[string]string, error) {
func getImageVersions(recipe recipe.Recipe2) (map[string]string, error) {
services := make(map[string]string)
config, err := recipe.GetComposeConfig(nil)
if err != nil {
return nil, err
}
missingTag := false
for _, service := range recipe.Config.Services {
for _, service := range config.Services {
if service.Image == "" {
continue
}
@ -526,8 +530,8 @@ func cleanUpTag(tag, recipeName string) error {
return nil
}
func getLabelVersion(recipe recipe.Recipe, prompt bool) (string, error) {
initTag, err := recipePkg.GetVersionLabelLocal(recipe)
func getLabelVersion(recipe recipe.Recipe2, prompt bool) (string, error) {
initTag, err := recipe.GetVersionLabelLocal()
if err != nil {
return "", err
}

View File

@ -47,12 +47,12 @@ local file system.
recipe := internal.ValidateRecipe(c)
r := recipePkg.Get2(recipe.Name)
mainApp, err := internal.GetMainAppImage(recipe)
mainApp, err := internal.GetMainAppImage(r)
if err != nil {
log.Fatal(err)
}
imagesTmp, err := getImageVersions(recipe)
imagesTmp, err := getImageVersions(r)
if err != nil {
log.Fatal(err)
}

View File

@ -130,7 +130,12 @@ You may invoke this command in "wizard" mode and be prompted for input:
log.Debugf("did not find versions file for %s", recipe.Name)
}
for _, service := range recipe.Config.Services {
config, err := r.GetComposeConfig(nil)
if err != nil {
log.Fatal(err)
}
for _, service := range config.Services {
img, err := reference.ParseNormalizedNamed(service.Image)
if err != nil {
log.Fatal(err)

View File

@ -331,9 +331,7 @@ func processRecipeRepoVersion(r recipe.Recipe2, version string) error {
return err
}
if r, err := recipe.Get(r.Name, internal.Offline); err != nil {
return err
} else if err := lint.LintForErrors(r); err != nil {
if err := lint.LintForErrors(r); err != nil {
return err
}