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

@ -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)