move GetComposeFiles
This commit is contained in:
parent
f18c642226
commit
37aff723c0
@ -478,61 +478,6 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// ensurePathExists ensures that a path exists.
|
||||
func ensurePathExists(path string) error {
|
||||
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
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 AppEnv) ([]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
|
||||
}
|
||||
logrus.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
|
||||
}
|
||||
logrus.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)
|
||||
}
|
||||
|
||||
logrus.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
|
||||
logrus.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
|
||||
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
||||
// GetAppComposeConfig retrieves a compose specification for a recipe. This
|
||||
// specification is the result of a merge of all the compose.**.yml files in
|
||||
// the recipe repository.
|
||||
|
@ -1055,3 +1055,58 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error {
|
||||
func getReposTopicUrl(repoName string) string {
|
||||
return fmt.Sprintf("https://git.coopcloud.tech/api/v1/repos/coop-cloud/%s/topics", repoName)
|
||||
}
|
||||
|
||||
// ensurePathExists ensures that a path exists.
|
||||
func ensurePathExists(path string) error {
|
||||
if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
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
|
||||
}
|
||||
logrus.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
|
||||
}
|
||||
logrus.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)
|
||||
}
|
||||
|
||||
logrus.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
|
||||
logrus.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
|
||||
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user