refactor: add config.GetAppComposeFiles

This commit is contained in:
decentral1se 2021-08-06 19:38:06 +02:00
parent 11ef64ead3
commit 828417c92b
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 22 additions and 19 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"text/template"
@ -13,10 +12,8 @@ import (
"coopcloud.tech/abra/catalogue"
"coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
loader "coopcloud.tech/abra/client/stack"
"coopcloud.tech/abra/config"
"github.com/docker/cli/cli/command/stack/options"
"github.com/docker/distribution/reference"
"github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
@ -165,14 +162,7 @@ var recipeUpgradeCommand = &cli.Command{
RecipeSkipTags map[string]string
}
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
logrus.Fatal(err)
}
opts := options.Deploy{Composefiles: composeFiles}
compose, err := loader.LoadComposefile(opts)
compose, err := config.GetAppComposeFiles(recipe)
if err != nil {
logrus.Fatal(err)
}
@ -226,14 +216,7 @@ var recipeLintCommand = &cli.Command{
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
logrus.Fatal(err)
}
opts := options.Deploy{Composefiles: composeFiles}
compose, err := loader.LoadComposefile(opts)
compose, err := config.GetAppComposeFiles(recipe)
if err != nil {
logrus.Fatal(err)
}

View File

@ -6,10 +6,14 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"coopcloud.tech/abra/client/convert"
"coopcloud.tech/abra/client/stack"
loader "coopcloud.tech/abra/client/stack"
"github.com/docker/cli/cli/command/stack/options"
composetypes "github.com/docker/cli/cli/compose/types"
)
// Type aliases to make code hints easier to understand
@ -221,3 +225,19 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) {
return statuses, nil
}
func GetAppComposeFiles(recipe string) (*composetypes.Config, error) {
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
return &composetypes.Config{}, err
}
opts := options.Deploy{Composefiles: composeFiles}
compose, err := loader.LoadComposefile(opts)
if err != nil {
return &composetypes.Config{}, err
}
return compose, nil
}