MCPcopy Index your code
hub / github.com/docker/cli / Load

Function Load

cli/compose/loader/loader.go:79–141  ·  view source on GitHub ↗

Load reads a ConfigDetails and returns a fully loaded configuration

(configDetails types.ConfigDetails, opt ...func(*Options))

Source from the content-addressed store, hash-verified

77
78// Load reads a ConfigDetails and returns a fully loaded configuration
79func Load(configDetails types.ConfigDetails, opt ...func(*Options)) (*types.Config, error) {
80 if len(configDetails.ConfigFiles) < 1 {
81 return nil, errors.New("no files specified")
82 }
83
84 options := &Options{
85 Interpolate: &interp.Options{
86 Substitute: template.Substitute,
87 LookupValue: configDetails.LookupEnv,
88 TypeCastMapping: interpolateTypeCastMapping,
89 },
90 }
91
92 for _, op := range opt {
93 op(options)
94 }
95
96 configs := []*types.Config{}
97 var err error
98
99 for _, file := range configDetails.ConfigFiles {
100 configDict := file.Config
101 version := schema.Version(configDict)
102 if configDetails.Version == "" {
103 configDetails.Version = version
104 }
105 if configDetails.Version != version {
106 return nil, fmt.Errorf("version mismatched between two composefiles : %v and %v", configDetails.Version, version)
107 }
108
109 if err := validateForbidden(configDict); err != nil {
110 return nil, err
111 }
112
113 if !options.SkipInterpolation {
114 configDict, err = interpolateConfig(configDict, *options.Interpolate)
115 if err != nil {
116 return nil, err
117 }
118 }
119
120 if !options.SkipValidation {
121 if err := schema.Validate(configDict, configDetails.Version); err != nil {
122 return nil, err
123 }
124 }
125
126 cfg, err := loadSections(configDict, configDetails)
127 if err != nil {
128 return nil, err
129 }
130 cfg.Filename = file.Filename
131 if options.discardEnvFiles {
132 for i := range cfg.Services {
133 cfg.Services[i].EnvFile = nil
134 }
135 }
136

Callers 15

TestMarshallConfigFunction · 0.70
TestJSONMarshallConfigFunction · 0.70
loadYAMLWithEnvFunction · 0.70
TestLoadFunction · 0.70
TestDiscardEnvFileOptionFunction · 0.70
TestBuildPropertiesFunction · 0.70
TestDeprecatedPropertiesFunction · 0.70
TestLoadLoggingFunction · 0.70

Calls 4

validateForbiddenFunction · 0.85
interpolateConfigFunction · 0.85
loadSectionsFunction · 0.85
mergeFunction · 0.85

Tested by 15

TestMarshallConfigFunction · 0.56
TestJSONMarshallConfigFunction · 0.56
loadYAMLWithEnvFunction · 0.56
TestLoadFunction · 0.56
TestDiscardEnvFileOptionFunction · 0.56
TestBuildPropertiesFunction · 0.56
TestDeprecatedPropertiesFunction · 0.56
TestLoadLoggingFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…