( ctx context.Context, name, ref string, path, refPath string, opts *Options, ct *cycleTracker, )
| 134 | } |
| 135 | |
| 136 | func getExtendsBaseFromFile( |
| 137 | ctx context.Context, |
| 138 | name, ref string, |
| 139 | path, refPath string, |
| 140 | opts *Options, |
| 141 | ct *cycleTracker, |
| 142 | ) (map[string]any, PostProcessor, error) { |
| 143 | for _, loader := range opts.ResourceLoaders { |
| 144 | if !loader.Accept(refPath) { |
| 145 | continue |
| 146 | } |
| 147 | local, err := loader.Load(ctx, refPath) |
| 148 | if err != nil { |
| 149 | return nil, nil, err |
| 150 | } |
| 151 | localdir := filepath.Dir(local) |
| 152 | relworkingdir := loader.Dir(refPath) |
| 153 | |
| 154 | extendsOpts := opts.clone() |
| 155 | // replace localResourceLoader with a new flavour, using extended file base path |
| 156 | extendsOpts.ResourceLoaders = append(opts.RemoteResourceLoaders(), localResourceLoader{ |
| 157 | WorkingDir: localdir, |
| 158 | }) |
| 159 | extendsOpts.ResolvePaths = false // we do relative path resolution after file has been loaded |
| 160 | extendsOpts.SkipNormalization = true |
| 161 | extendsOpts.SkipConsistencyCheck = true |
| 162 | extendsOpts.SkipInclude = true |
| 163 | extendsOpts.SkipExtends = true // we manage extends recursively based on raw service definition |
| 164 | extendsOpts.SkipValidation = true // we validate the merge result |
| 165 | extendsOpts.SkipDefaultValues = true |
| 166 | source, processor, err := loadYamlFile(ctx, types.ConfigFile{Filename: local}, |
| 167 | extendsOpts, relworkingdir, nil, ct, map[string]any{}, nil) |
| 168 | if err != nil { |
| 169 | return nil, nil, err |
| 170 | } |
| 171 | m, ok := source["services"] |
| 172 | if !ok { |
| 173 | return nil, nil, fmt.Errorf("cannot extend service %q in %s: no services section", name, local) |
| 174 | } |
| 175 | services, ok := m.(map[string]any) |
| 176 | if !ok { |
| 177 | return nil, nil, fmt.Errorf("cannot extend service %q in %s: services must be a mapping", name, local) |
| 178 | } |
| 179 | _, ok = services[ref] |
| 180 | if !ok { |
| 181 | return nil, nil, fmt.Errorf( |
| 182 | "cannot extend service %q in %s: service %q not found in %s", |
| 183 | name, |
| 184 | path, |
| 185 | ref, |
| 186 | refPath, |
| 187 | ) |
| 188 | } |
| 189 | |
| 190 | var remotes []paths.RemoteResource |
| 191 | for _, loader := range opts.RemoteResourceLoaders() { |
| 192 | remotes = append(remotes, loader.Accept) |
| 193 | } |
no test coverage detected
searching dependent graphs…