forked from toolshed/abra
refactor(recipe): move GetComposeFiles to new struct
This commit is contained in:
@ -188,6 +188,7 @@ func Get2(name string) Recipe2 {
|
||||
Dir: dir,
|
||||
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
|
||||
|
||||
ComposePath: path.Join(dir, "compose.yml"),
|
||||
ReadmePath: path.Join(dir, "README.md"),
|
||||
SampleEnvPath: path.Join(dir, ".env.sample"),
|
||||
}
|
||||
@ -198,6 +199,7 @@ type Recipe2 struct {
|
||||
Dir string
|
||||
SSHURL string
|
||||
|
||||
ComposePath string
|
||||
ReadmePath string
|
||||
SampleEnvPath string
|
||||
}
|
||||
@ -776,50 +778,3 @@ func ensurePathExists(path string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetComposeFiles gets the list of compose files for an app (or recipe if you
|
||||
// don't already have an app) which should be merged into a composetypes.Config
|
||||
// while respecting the COMPOSE_FILE env var.
|
||||
func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error) {
|
||||
var composeFiles []string
|
||||
|
||||
composeFileEnvVar, ok := appEnv["COMPOSE_FILE"]
|
||||
if !ok {
|
||||
path := fmt.Sprintf("%s/%s/compose.yml", config.RECIPES_DIR, recipe)
|
||||
if err := ensurePathExists(path); err != nil {
|
||||
return composeFiles, err
|
||||
}
|
||||
log.Debugf("no COMPOSE_FILE detected, loading default: %s", path)
|
||||
composeFiles = append(composeFiles, path)
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
||||
if !strings.Contains(composeFileEnvVar, ":") {
|
||||
path := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, recipe, composeFileEnvVar)
|
||||
if err := ensurePathExists(path); err != nil {
|
||||
return composeFiles, err
|
||||
}
|
||||
log.Debugf("COMPOSE_FILE detected, loading %s", path)
|
||||
composeFiles = append(composeFiles, path)
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
||||
numComposeFiles := strings.Count(composeFileEnvVar, ":") + 1
|
||||
envVars := strings.SplitN(composeFileEnvVar, ":", numComposeFiles)
|
||||
if len(envVars) != numComposeFiles {
|
||||
return composeFiles, fmt.Errorf("COMPOSE_FILE (=\"%s\") parsing failed?", composeFileEnvVar)
|
||||
}
|
||||
|
||||
for _, file := range envVars {
|
||||
path := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, recipe, file)
|
||||
if err := ensurePathExists(path); err != nil {
|
||||
return composeFiles, err
|
||||
}
|
||||
composeFiles = append(composeFiles, path)
|
||||
}
|
||||
|
||||
log.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
|
||||
log.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
|
||||
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user