refactor(recipe): remove remaining usage of old recipe struct

This commit is contained in:
2024-07-08 13:15:20 +02:00
parent c1b03bcbd7
commit 5617a9ba07
24 changed files with 167 additions and 189 deletions

View File

@ -70,7 +70,7 @@ func GetApps(appFiles AppFiles, recipeFilter string) ([]App, error) {
}
if recipeFilter != "" {
if app.Recipe == recipeFilter {
if app.Recipe.Name == recipeFilter {
apps = append(apps, app)
}
} else {
@ -84,7 +84,7 @@ func GetApps(appFiles AppFiles, recipeFilter string) ([]App, error) {
// App reprents an app with its env file read into memory
type App struct {
Name AppName
Recipe string
Recipe recipe.Recipe2
Domain string
Env envfile.AppEnv
Server string
@ -161,14 +161,13 @@ func (a App) Filters(appendServiceNames, exactMatch bool, services ...string) (f
return filters, nil
}
r := recipe.Get2(a.Recipe)
composeFiles, err := r.GetComposeFiles(a.Env)
composeFiles, err := a.Recipe.GetComposeFiles(a.Env)
if err != nil {
return filters, err
}
opts := stack.Deploy{Composefiles: composeFiles}
compose, err := GetAppComposeConfig(a.Recipe, opts, a.Env)
compose, err := GetAppComposeConfig(a.Recipe.Name, opts, a.Env)
if err != nil {
return filters, err
}
@ -207,7 +206,7 @@ func (a ByServerAndRecipe) Len() int { return len(a) }
func (a ByServerAndRecipe) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByServerAndRecipe) Less(i, j int) bool {
if a[i].Server == a[j].Server {
return strings.ToLower(a[i].Recipe) < strings.ToLower(a[j].Recipe)
return strings.ToLower(a[i].Recipe.Name) < strings.ToLower(a[j].Recipe.Name)
}
return strings.ToLower(a[i].Server) < strings.ToLower(a[j].Server)
}
@ -218,7 +217,7 @@ type ByRecipe []App
func (a ByRecipe) Len() int { return len(a) }
func (a ByRecipe) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByRecipe) Less(i, j int) bool {
return strings.ToLower(a[i].Recipe) < strings.ToLower(a[j].Recipe)
return strings.ToLower(a[i].Recipe.Name) < strings.ToLower(a[j].Recipe.Name)
}
// ByName sort a slice of Apps
@ -250,9 +249,9 @@ func ReadAppEnvFile(appFile AppFile, name AppName) (App, error) {
func NewApp(env envfile.AppEnv, name string, appFile AppFile) (App, error) {
domain := env["DOMAIN"]
recipe, exists := env["RECIPE"]
recipeName, exists := env["RECIPE"]
if !exists {
recipe, exists = env["TYPE"]
recipeName, exists = env["TYPE"]
if !exists {
return App{}, fmt.Errorf("%s is missing the TYPE env var?", name)
}
@ -261,7 +260,7 @@ func NewApp(env envfile.AppEnv, name string, appFile AppFile) (App, error) {
return App{
Name: name,
Domain: domain,
Recipe: recipe,
Recipe: recipe.Get2(recipeName),
Env: env,
Server: appFile.Server,
Path: appFile.Path,
@ -318,14 +317,13 @@ func GetAppServiceNames(appName string) ([]string, error) {
return serviceNames, err
}
r := recipe.Get2(app.Recipe)
composeFiles, err := r.GetComposeFiles(app.Env)
composeFiles, err := app.Recipe.GetComposeFiles(app.Env)
if err != nil {
return serviceNames, err
}
opts := stack.Deploy{Composefiles: composeFiles}
compose, err := GetAppComposeConfig(app.Recipe, opts, app.Env)
compose, err := GetAppComposeConfig(app.Recipe.Name, opts, app.Env)
if err != nil {
return serviceNames, err
}
@ -512,8 +510,7 @@ func ExposeAllEnv(stackName string, compose *composetypes.Config, appEnv envfile
func CheckEnv(app App) ([]envfile.EnvVar, error) {
var envVars []envfile.EnvVar
r := recipe.Get2(app.Recipe)
envSample, err := r.SampleEnv()
envSample, err := app.Recipe.SampleEnv()
if err != nil {
return envVars, err
}

View File

@ -47,8 +47,8 @@ func TestGetApp(t *testing.T) {
}
func TestGetComposeFiles(t *testing.T) {
offline := true
r, err := recipe.Get("abra-test-recipe", offline)
r := recipe.Get2("abra-test-recipe")
err := r.EnsureExists()
if err != nil {
t.Fatal(err)
}
@ -95,8 +95,8 @@ func TestGetComposeFiles(t *testing.T) {
}
func TestGetComposeFilesError(t *testing.T) {
offline := true
r, err := recipe.Get("abra-test-recipe", offline)
r := recipe.Get2("abra-test-recipe")
err := r.EnsureExists()
if err != nil {
t.Fatal(err)
}