(ctx context.Context, project *types.Project, serviceToBuild types.Services, options api.BuildOptions)
| 46 | ) |
| 47 | |
| 48 | func (s *composeService) doBuildClassic(ctx context.Context, project *types.Project, serviceToBuild types.Services, options api.BuildOptions) (map[string]string, error) { |
| 49 | imageIDs := map[string]string{} |
| 50 | |
| 51 | // Not using bake, additional_context: service:xx is implemented by building images in dependency order |
| 52 | project, err := project.WithServicesTransform(func(serviceName string, service types.ServiceConfig) (types.ServiceConfig, error) { |
| 53 | if service.Build != nil { |
| 54 | for _, c := range service.Build.AdditionalContexts { |
| 55 | if t, found := strings.CutPrefix(c, types.ServicePrefix); found { |
| 56 | if service.DependsOn == nil { |
| 57 | service.DependsOn = map[string]types.ServiceDependency{} |
| 58 | } |
| 59 | service.DependsOn[t] = types.ServiceDependency{ |
| 60 | Condition: "build", // non-canonical, but will force dependency graph ordering |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return service, nil |
| 66 | }) |
| 67 | if err != nil { |
| 68 | return imageIDs, err |
| 69 | } |
| 70 | |
| 71 | // we use a pre-allocated []string to collect build digest by service index while running concurrent goroutines |
| 72 | builtDigests := make([]string, len(project.Services)) |
| 73 | names := project.ServiceNames() |
| 74 | getServiceIndex := func(name string) int { |
| 75 | for idx, n := range names { |
| 76 | if n == name { |
| 77 | return idx |
| 78 | } |
| 79 | } |
| 80 | return -1 |
| 81 | } |
| 82 | |
| 83 | err = InDependencyOrder(ctx, project, func(ctx context.Context, name string) error { |
| 84 | trace.SpanFromContext(ctx).SetAttributes(attribute.String("builder", "classic")) |
| 85 | service, ok := serviceToBuild[name] |
| 86 | if !ok { |
| 87 | return nil |
| 88 | } |
| 89 | |
| 90 | image := api.GetImageNameOrDefault(service, project.Name) |
| 91 | s.events.On(buildingEvent(image)) |
| 92 | id, err := s.doBuildImage(ctx, project, service, options) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | s.events.On(builtEvent(image)) |
| 97 | builtDigests[getServiceIndex(name)] = id |
| 98 | |
| 99 | if options.Push { |
| 100 | return s.push(ctx, project, api.PushOptions{}) |
| 101 | } |
| 102 | return nil |
| 103 | }, func(traversal *graphTraversal) { |
| 104 | traversal.maxConcurrency = s.maxConcurrency |
| 105 | }) |
no test coverage detected