refactor(recipe): use method or variable for .env.sample

This commit is contained in:
2024-07-08 11:26:01 +02:00
parent 2f41b6d8b4
commit c861c09cce
11 changed files with 47 additions and 85 deletions

View File

@ -2,7 +2,6 @@ package app
import (
"fmt"
"path"
"coopcloud.tech/abra/cli/internal"
appPkg "coopcloud.tech/abra/pkg/app"
@ -121,7 +120,7 @@ var appNewCommand = cli.Command{
log.Debugf("%s sanitised as %s for new app", internal.Domain, sanitisedAppName)
if err := appPkg.TemplateAppEnvSample(
recipe.Name,
r,
internal.Domain,
internal.NewAppServer,
internal.Domain,
@ -142,8 +141,7 @@ var appNewCommand = cli.Command{
log.Fatal(err)
}
envSamplePath := path.Join(config.RECIPES_DIR, recipe.Name, ".env.sample")
secretsConfig, err := secret.ReadSecretsConfig(envSamplePath, composeFiles, appPkg.StackName(internal.Domain))
secretsConfig, err := secret.ReadSecretsConfig(r.SampleEnvPath, composeFiles, appPkg.StackName(internal.Domain))
if err != nil {
return err
}

View File

@ -12,6 +12,7 @@ import (
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/recipe"
"github.com/urfave/cli"
)
@ -55,6 +56,7 @@ recipe and domain in the sample environment config).
`,
Action: func(c *cli.Context) error {
recipeName := c.Args().First()
r := recipe.Get2(recipeName)
if recipeName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe name provided"))
@ -80,7 +82,7 @@ recipe and domain in the sample environment config).
toParse := []string{
path.Join(config.RECIPES_DIR, recipeName, "README.md"),
path.Join(config.RECIPES_DIR, recipeName, ".env.sample"),
r.SampleEnvPath,
}
for _, path := range toParse {
tpl, err := template.ParseFiles(path)

View File

@ -10,6 +10,7 @@ import (
"coopcloud.tech/abra/pkg/config"
gitPkg "coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/log"
recipePkg "coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/tagcmp"
"github.com/AlecAivazis/survey/v2"
"github.com/go-git/go-git/v5"
@ -44,6 +45,7 @@ local file system.
BashComplete: autocomplete.RecipeNameComplete,
Action: func(c *cli.Context) error {
recipe := internal.ValidateRecipe(c)
r := recipePkg.Get2(recipe.Name)
mainApp, err := internal.GetMainAppImage(recipe)
if err != nil {
@ -192,7 +194,7 @@ likely to change.
mainService := "app"
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", nextTag)
if !internal.Dry {
if err := recipe.UpdateLabel("compose.y*ml", mainService, label); err != nil {
if err := r.UpdateLabel("compose.y*ml", mainService, label); err != nil {
log.Fatal(err)
}
} else {

View File

@ -294,7 +294,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
}
}
if upgradeTag != "skip" {
ok, err := recipe.UpdateTag(image, upgradeTag)
ok, err := r.UpdateTag(image, upgradeTag)
if err != nil {
log.Fatal(err)
}

View File

@ -7,9 +7,9 @@ import (
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/autocomplete"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/log"
recipePkg "coopcloud.tech/abra/pkg/recipe"
"github.com/olekukonko/tablewriter"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -42,16 +42,16 @@ var recipeVersionCommand = cli.Command{
catl, err := recipePkg.ReadRecipeCatalogue(internal.Offline)
if err != nil {
log.Fatal(err)
logrus.Fatal(err)
}
recipeMeta, ok := catl[recipe.Name]
if !ok {
log.Fatalf("%s is not published on the catalogue?", recipe.Name)
logrus.Fatalf("%s is not published on the catalogue?", recipe.Name)
}
if len(recipeMeta.Versions) == 0 {
log.Fatalf("%s has no catalogue published versions?", recipe.Name)
logrus.Fatalf("%s has no catalogue published versions?", recipe.Name)
}
tableCols := []string{"version", "service", "image", "tag"}