MCPcopy
hub / github.com/hashicorp/packer / loadConfig

Function loadConfig

main.go:331–389  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

329}
330
331func loadConfig() (*config, error) {
332 pluginDir, err := packer.PluginFolder()
333 if err != nil {
334 return nil, err
335 }
336
337 var config config
338 config.Plugins = &packer.PluginConfig{
339 PluginMinPort: 10000,
340 PluginMaxPort: 25000,
341 PluginDirectory: pluginDir,
342 Builders: packer.MapOfBuilder{},
343 Provisioners: packer.MapOfProvisioner{},
344 PostProcessors: packer.MapOfPostProcessor{},
345 DataSources: packer.MapOfDatasource{},
346 }
347
348 // Finally, try to use an internal plugin. Note that this will not override
349 // any previously-loaded plugins.
350 if err := config.discoverInternalComponents(); err != nil {
351 return nil, err
352 }
353
354 // start by loading from PACKER_CONFIG if available
355 configFilePath := os.Getenv("PACKER_CONFIG")
356 if configFilePath == "" {
357 var err error
358 log.Print("[INFO] PACKER_CONFIG env var not set; checking the default config file path")
359 configFilePath, err = pathing.ConfigFile()
360 if err != nil {
361 log.Printf("Error detecting default config file path: %s", err)
362 }
363 }
364 if configFilePath == "" {
365 return &config, nil
366 }
367 log.Printf("[INFO] PACKER_CONFIG env var set; attempting to open config file: %s", configFilePath)
368 f, err := os.Open(configFilePath)
369 if err != nil {
370 if !os.IsNotExist(err) {
371 return nil, err
372 }
373
374 log.Printf("[WARN] Config file doesn't exist: %s", configFilePath)
375 return &config, nil
376 }
377 defer f.Close()
378
379 // This loads a json config, defined in packer/config.go
380 if err := decodeConfig(f, &config); err != nil {
381 return nil, err
382 }
383
384 if err := config.LoadExternalComponentsFromConfig(); err != nil {
385 return nil, fmt.Errorf("%s: %s", configFilePath, err)
386 }
387
388 return &config, nil

Callers 2

realMainFunction · 0.85
wrappedMainFunction · 0.85

Calls 6

PluginFolderFunction · 0.92
decodeConfigFunction · 0.85
CloseMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…