(ctx context.Context, name string, services map[string]any, opts *Options, tracker *cycleTracker, post PostProcessor)
| 48 | } |
| 49 | |
| 50 | func applyServiceExtends(ctx context.Context, name string, services map[string]any, opts *Options, tracker *cycleTracker, post PostProcessor) (any, error) { |
| 51 | s := services[name] |
| 52 | if s == nil { |
| 53 | return nil, nil |
| 54 | } |
| 55 | service, ok := s.(map[string]any) |
| 56 | if !ok { |
| 57 | return nil, fmt.Errorf("services.%s must be a mapping", name) |
| 58 | } |
| 59 | extends, ok := service["extends"] |
| 60 | if !ok { |
| 61 | return s, nil |
| 62 | } |
| 63 | filename := ctx.Value(consts.ComposeFileKey{}).(string) |
| 64 | var ( |
| 65 | err error |
| 66 | ref string |
| 67 | file any |
| 68 | ) |
| 69 | switch v := extends.(type) { |
| 70 | case map[string]any: |
| 71 | ref, ok = v["service"].(string) |
| 72 | if !ok { |
| 73 | return nil, fmt.Errorf("extends.%s.service is required", name) |
| 74 | } |
| 75 | file = v["file"] |
| 76 | opts.ProcessEvent("extends", v) |
| 77 | case string: |
| 78 | ref = v |
| 79 | opts.ProcessEvent("extends", map[string]any{"service": ref}) |
| 80 | } |
| 81 | |
| 82 | var ( |
| 83 | base any |
| 84 | processor = post |
| 85 | ) |
| 86 | |
| 87 | if file != nil { |
| 88 | refFilename := file.(string) |
| 89 | services, processor, err = getExtendsBaseFromFile(ctx, name, ref, filename, refFilename, opts, tracker) |
| 90 | if err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | filename = refFilename |
| 94 | } else { |
| 95 | _, ok := services[ref] |
| 96 | if !ok { |
| 97 | return nil, fmt.Errorf("cannot extend service %q in %s: service %q not found", name, filename, ref) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | tracker, err = tracker.Add(filename, name) |
| 102 | if err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | |
| 106 | // recursively apply `extends` |
| 107 | base, err = applyServiceExtends(ctx, ref, services, opts, tracker, processor) |
no test coverage detected
searching dependent graphs…