forked from coop-cloud/abra
Merge branch 'filter-servers-by-recipe'
This commit is contained in:
commit
521570224b
@ -23,12 +23,12 @@ var statusFlag = &cli.BoolFlag{
|
||||
Destination: &status,
|
||||
}
|
||||
|
||||
var appRecipe string
|
||||
var recipeFilter string
|
||||
var recipeFlag = &cli.StringFlag{
|
||||
Name: "recipe, r",
|
||||
Value: "",
|
||||
Usage: "Show apps of a specific recipe",
|
||||
Destination: &appRecipe,
|
||||
Destination: &recipeFilter,
|
||||
}
|
||||
|
||||
var listAppServer string
|
||||
@ -84,7 +84,7 @@ can take some time.
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
apps, err := config.GetApps(appFiles)
|
||||
apps, err := config.GetApps(appFiles, recipeFilter)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -104,7 +104,7 @@ can take some time.
|
||||
}
|
||||
}
|
||||
|
||||
statuses, err = config.GetAppStatuses(appFiles, internal.MachineReadable)
|
||||
statuses, err = config.GetAppStatuses(apps, internal.MachineReadable)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -124,14 +124,14 @@ can take some time.
|
||||
var ok bool
|
||||
if stats, ok = allStats[app.Server]; !ok {
|
||||
stats = serverStatus{}
|
||||
if appRecipe == "" {
|
||||
if recipeFilter == "" {
|
||||
// count server, no filtering
|
||||
totalServersCount++
|
||||
}
|
||||
}
|
||||
|
||||
if app.Recipe == appRecipe || appRecipe == "" {
|
||||
if appRecipe != "" {
|
||||
if app.Recipe == recipeFilter || recipeFilter == "" {
|
||||
if recipeFilter != "" {
|
||||
// only count server if matches filter
|
||||
totalServersCount++
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func newApp(env AppEnv, name string, appFile AppFile) (App, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// LoadAppFiles gets all app files for a given set of servers or all servers
|
||||
// LoadAppFiles gets all app files for a given set of servers or all servers.
|
||||
func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
appFiles := make(AppFiles)
|
||||
if len(servers) == 1 {
|
||||
@ -194,7 +194,7 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
var err error
|
||||
servers, err = GetAllFoldersInDirectory(SERVERS_DIR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return appFiles, err
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,8 +205,9 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
serverDir := path.Join(SERVERS_DIR, server)
|
||||
files, err := getAllFilesInDirectory(serverDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("server %s doesn't exist? Run \"abra server ls\" to check", server)
|
||||
return appFiles, fmt.Errorf("server %s doesn't exist? Run \"abra server ls\" to check", server)
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
appName := strings.TrimSuffix(file.Name(), ".env")
|
||||
appFilePath := path.Join(SERVERS_DIR, server, file.Name())
|
||||
@ -216,12 +217,13 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return appFiles, nil
|
||||
}
|
||||
|
||||
// GetApp loads an apps settings, reading it from file, in preparation to use it
|
||||
//
|
||||
// ONLY use when ready to use the env file to keep IO down
|
||||
// GetApp loads an apps settings, reading it from file, in preparation to use
|
||||
// it. It should only be used when ready to use the env file to keep IO
|
||||
// operations down.
|
||||
func GetApp(apps AppFiles, name AppName) (App, error) {
|
||||
appFile, exists := apps[name]
|
||||
if !exists {
|
||||
@ -236,8 +238,9 @@ func GetApp(apps AppFiles, name AppName) (App, error) {
|
||||
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) {
|
||||
// GetApps returns a slice of Apps with their env files read from a given
|
||||
// slice of AppFiles.
|
||||
func GetApps(appFiles AppFiles, recipeFilter string) ([]App, error) {
|
||||
var apps []App
|
||||
|
||||
for name := range appFiles {
|
||||
@ -245,7 +248,14 @@ func GetApps(appFiles AppFiles) ([]App, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
apps = append(apps, app)
|
||||
|
||||
if recipeFilter != "" {
|
||||
if app.Recipe == recipeFilter {
|
||||
apps = append(apps, app)
|
||||
}
|
||||
} else {
|
||||
apps = append(apps, app)
|
||||
}
|
||||
}
|
||||
|
||||
return apps, nil
|
||||
@ -292,7 +302,7 @@ func GetAppNames() ([]string, error) {
|
||||
return appNames, err
|
||||
}
|
||||
|
||||
apps, err := GetApps(appFiles)
|
||||
apps, err := GetApps(appFiles, "")
|
||||
if err != nil {
|
||||
return appNames, err
|
||||
}
|
||||
@ -304,7 +314,8 @@ func GetAppNames() ([]string, error) {
|
||||
return appNames, nil
|
||||
}
|
||||
|
||||
// TemplateAppEnvSample copies the example env file for the app into the users env files
|
||||
// TemplateAppEnvSample copies the example env file for the app into the users
|
||||
// env files.
|
||||
func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
|
||||
envSamplePath := path.Join(RECIPES_DIR, recipeName, ".env.sample")
|
||||
envSample, err := ioutil.ReadFile(envSamplePath)
|
||||
@ -339,21 +350,20 @@ func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SanitiseAppName makes a app name usable with Docker by replacing illegal characters
|
||||
// SanitiseAppName makes a app name usable with Docker by replacing illegal
|
||||
// characters.
|
||||
func SanitiseAppName(name string) string {
|
||||
return strings.ReplaceAll(name, ".", "_")
|
||||
}
|
||||
|
||||
// GetAppStatuses queries servers to check the deployment status of given apps
|
||||
func GetAppStatuses(appFiles AppFiles, MachineReadable bool) (map[string]map[string]string, error) {
|
||||
// GetAppStatuses queries servers to check the deployment status of given apps.
|
||||
func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]string, error) {
|
||||
statuses := make(map[string]map[string]string)
|
||||
|
||||
var unique []string
|
||||
servers := make(map[string]struct{})
|
||||
for _, appFile := range appFiles {
|
||||
if _, ok := servers[appFile.Server]; !ok {
|
||||
servers[appFile.Server] = struct{}{}
|
||||
unique = append(unique, appFile.Server)
|
||||
for _, app := range apps {
|
||||
if _, ok := servers[app.Server]; !ok {
|
||||
servers[app.Server] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,6 +372,7 @@ func GetAppStatuses(appFiles AppFiles, MachineReadable bool) (map[string]map[str
|
||||
if !MachineReadable {
|
||||
bar = formatter.CreateProgressbar(len(servers), "querying remote servers...")
|
||||
}
|
||||
|
||||
ch := make(chan stack.StackStatus, len(servers))
|
||||
for server := range servers {
|
||||
go func(s string) {
|
||||
|
Loading…
Reference in New Issue
Block a user