MCPcopy Index your code
hub / github.com/ddev/ddev / ComposeFiles

Method ComposeFiles

pkg/ddevapp/ddevapp.go:1308–1347  ·  view source on GitHub ↗

ComposeFiles returns a list of compose files for a project. It has to put the .ddev/docker-compose.*.y*ml first It has to put the .ddev/docker-compose.override.y*ml last

()

Source from the content-addressed store, hash-verified

1306// It has to put the .ddev/docker-compose.*.y*ml first
1307// It has to put the .ddev/docker-compose.override.y*ml last
1308func (app *DdevApp) ComposeFiles() ([]string, error) {
1309 origDir, _ := os.Getwd()
1310 defer func() {
1311 _ = os.Chdir(origDir)
1312 }()
1313 err := os.Chdir(app.AppConfDir())
1314 if err != nil {
1315 return nil, err
1316 }
1317 files, err := filepath.Glob("docker-compose.*.y*ml")
1318 if err != nil {
1319 return []string{}, fmt.Errorf("unable to glob docker-compose.*.y*ml in %s: err=%v", app.AppConfDir(), err)
1320 }
1321
1322 mainFile := app.DockerComposeYAMLPath()
1323 if !fileutil.FileExists(mainFile) {
1324 return nil, fmt.Errorf("failed to find %s", mainFile)
1325 }
1326
1327 overrides, err := filepath.Glob("docker-compose.override.y*ml")
1328 util.CheckErr(err)
1329
1330 orderedFiles := make([]string, 1)
1331
1332 // Make sure the main file goes first
1333 orderedFiles[0] = mainFile
1334
1335 for _, file := range files {
1336 // We already have the main file, and it's not in the list anyway, so skip when we hit it.
1337 // We'll add the override later, so skip it.
1338 if len(overrides) == 1 && file == overrides[0] {
1339 continue
1340 }
1341 orderedFiles = append(orderedFiles, app.GetConfigPath(file))
1342 }
1343 if len(overrides) == 1 {
1344 orderedFiles = append(orderedFiles, app.GetConfigPath(overrides[0]))
1345 }
1346 return orderedFiles, nil
1347}
1348
1349// EnvFiles returns a list of env files for a project.
1350// It has to put the .ddev/.env first

Callers 2

TestMultipleComposeFilesFunction · 0.80

Calls 7

AppConfDirMethod · 0.95
DockerComposeYAMLPathMethod · 0.95
GetConfigPathMethod · 0.95
FileExistsFunction · 0.92
CheckErrFunction · 0.92
ChdirMethod · 0.80
ErrorfMethod · 0.80

Tested by 1

TestMultipleComposeFilesFunction · 0.64