forked from toolshed/abra
@ -13,6 +13,7 @@ import (
|
||||
loader "coopcloud.tech/abra/pkg/client/stack"
|
||||
stack "coopcloud.tech/abra/pkg/client/stack"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Type aliases to make code hints easier to understand
|
||||
@ -93,10 +94,14 @@ func readAppEnvFile(appFile AppFile, name AppName) (App, error) {
|
||||
if err != nil {
|
||||
return App{}, fmt.Errorf("env file for '%s' couldn't be read: %s", name, err.Error())
|
||||
}
|
||||
|
||||
logrus.Debugf("read env '%s' from '%s'", env, appFile.Path)
|
||||
|
||||
app, err := newApp(env, name, appFile)
|
||||
if err != nil {
|
||||
return App{}, fmt.Errorf("env file for '%s' has issues: %s", name, err.Error())
|
||||
}
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
||||
@ -108,6 +113,7 @@ func newApp(env AppEnv, name string, appFile AppFile) (App, error) {
|
||||
if !ok {
|
||||
return App{}, errors.New("missing TYPE variable")
|
||||
}
|
||||
|
||||
return App{
|
||||
Name: name,
|
||||
Domain: domain,
|
||||
@ -131,6 +137,9 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("collecting metadata from '%v' servers: '%s'", len(servers), servers)
|
||||
|
||||
for _, server := range servers {
|
||||
serverDir := path.Join(ABRA_SERVER_FOLDER, server)
|
||||
files, err := getAllFilesInDirectory(serverDir)
|
||||
@ -157,16 +166,19 @@ func GetApp(apps AppFiles, name AppName) (App, error) {
|
||||
if !exists {
|
||||
return App{}, fmt.Errorf("cannot find app with name '%s'", name)
|
||||
}
|
||||
|
||||
app, err := readAppEnvFile(appFile, name)
|
||||
if err != nil {
|
||||
return App{}, err
|
||||
}
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
||||
// GetApps returns a slice of Apps with their env files read from a given slice of AppFiles
|
||||
func GetApps(appFiles AppFiles) ([]App, error) {
|
||||
var apps []App
|
||||
|
||||
for name := range appFiles {
|
||||
app, err := GetApp(appFiles, name)
|
||||
if err != nil {
|
||||
@ -174,14 +186,17 @@ func GetApps(appFiles AppFiles) ([]App, error) {
|
||||
}
|
||||
apps = append(apps, app)
|
||||
}
|
||||
|
||||
return apps, nil
|
||||
}
|
||||
|
||||
// GetAppNames retrieves a list of app names.
|
||||
func GetAppNames() ([]string, error) {
|
||||
appFiles, err := LoadAppFiles("")
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
|
||||
apps, err := GetApps(appFiles)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
@ -213,6 +228,8 @@ func CopyAppEnvSample(appType, appName, server string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("copied '%s' to '%s'", envSamplePath, appEnvPath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -240,6 +257,8 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved app statuses: '%s'", statuses)
|
||||
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
@ -261,6 +280,9 @@ func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) {
|
||||
path := fmt.Sprintf("%s/%s/%s", APPS_DIR, recipe, file)
|
||||
composeFiles = append(composeFiles, path)
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved '%s' configs for '%s'", strings.Join(composeFiles, ", "), recipe)
|
||||
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
||||
@ -272,5 +294,8 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv AppEnv) (*comp
|
||||
if err != nil {
|
||||
return &composetypes.Config{}, err
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved '%s' for '%s'", compose, recipe)
|
||||
|
||||
return compose, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user