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

Method ReadConfig

pkg/ddevapp/config.go:362–418  ·  view source on GitHub ↗

ReadConfig reads project configuration from the config.yaml file It does not attempt to set default values; that's NewApp's job. returns the list of config files read

(includeOverrides bool)

Source from the content-addressed store, hash-verified

360// It does not attempt to set default values; that's NewApp's job.
361// returns the list of config files read
362func (app *DdevApp) ReadConfig(includeOverrides bool) ([]string, error) {
363 if app.ConfigPath == "" {
364 app.ConfigPath = app.GetConfigPath("config.yaml")
365 }
366
367 configOverrides := []string{}
368 var err error
369 // Load config.*.y*ml after in glob order
370 if includeOverrides {
371 glob := filepath.Join(filepath.Dir(app.ConfigPath), "config.*.y*ml")
372 configOverrides, err = filepath.Glob(glob)
373 if err != nil {
374 return []string{}, err
375 }
376 }
377
378 allFiles := append([]string{app.ConfigPath}, configOverrides...)
379 fileContents := make(map[string][]byte)
380
381 // Add Pre-Load Validation (Hook Checks)
382 for _, file := range allFiles {
383 source, err := os.ReadFile(file)
384 if err != nil {
385 return []string{}, fmt.Errorf("unable to read config file %s: %v", file, err)
386 }
387 err = validateHookYAML(source)
388 if err != nil {
389 return []string{}, fmt.Errorf("invalid configuration in %s: %v", file, err)
390 }
391 fileContents[file] = source
392 }
393
394 // Sort WebExtraExposedPorts so the entry matching configured router ports comes first
395 SortWebExtraExposedPorts(app)
396
397 // Determine overrides and their contents in correct order
398 var overrides []settings.OverrideConfig
399 var overrideKeys []string
400 for _, f := range configOverrides {
401 if f != app.ConfigPath {
402 overrides = append(overrides, settings.OverrideConfig{
403 Path: f,
404 Content: fileContents[f],
405 })
406 overrideKeys = append(overrideKeys, f)
407 }
408 }
409
410 err = settings.LoadProjectConfigFromContents(fileContents[app.ConfigPath], overrides, app)
411 if err != nil {
412 return []string{}, fmt.Errorf("failed to load project config: %v", err)
413 }
414
415 app.ConfigPostLoadCleanup()
416
417 return append([]string{app.ConfigPath}, overrideKeys...), nil
418}
419

Callers 7

TestLoadConfigYamlFileFunction · 0.95
TestReadConfigFunction · 0.95
TestReadConfigCRLFFunction · 0.95
NewAppFunction · 0.95
HasConfigNameOverrideMethod · 0.95

Calls 6

GetConfigPathMethod · 0.95
ConfigPostLoadCleanupMethod · 0.95
validateHookYAMLFunction · 0.85
SortWebExtraExposedPortsFunction · 0.85
ErrorfMethod · 0.80

Tested by 4

TestLoadConfigYamlFileFunction · 0.76
TestReadConfigFunction · 0.76
TestReadConfigCRLFFunction · 0.76