(ctx context.Context, project *types.Project, options api.BuildOptions, localImages map[string]api.ImageSummary)
| 50 | } |
| 51 | |
| 52 | func (s *composeService) build(ctx context.Context, project *types.Project, options api.BuildOptions, localImages map[string]api.ImageSummary) (map[string]string, error) { |
| 53 | imageIDs := map[string]string{} |
| 54 | serviceToBuild := types.Services{} |
| 55 | |
| 56 | var policy types.DependencyOption = types.IgnoreDependencies |
| 57 | if options.Deps { |
| 58 | policy = types.IncludeDependencies |
| 59 | } |
| 60 | |
| 61 | if len(options.Services) == 0 { |
| 62 | options.Services = project.ServiceNames() |
| 63 | } |
| 64 | |
| 65 | // also include services used as additional_contexts with service: prefix |
| 66 | options.Services = addBuildDependencies(options.Services, project) |
| 67 | |
| 68 | // Some build dependencies we just introduced may not be enabled |
| 69 | var err error |
| 70 | project, err = project.WithServicesEnabled(options.Services...) |
| 71 | if err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | |
| 75 | project, err = project.WithSelectedServices(options.Services) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | |
| 80 | err = project.ForEachService(options.Services, func(serviceName string, service *types.ServiceConfig) error { |
| 81 | if service.Build == nil { |
| 82 | return nil |
| 83 | } |
| 84 | image := api.GetImageNameOrDefault(*service, project.Name) |
| 85 | _, localImagePresent := localImages[image] |
| 86 | if localImagePresent && service.PullPolicy != types.PullPolicyBuild { |
| 87 | return nil |
| 88 | } |
| 89 | serviceToBuild[serviceName] = *service |
| 90 | return nil |
| 91 | }, policy) |
| 92 | if err != nil { |
| 93 | return imageIDs, err |
| 94 | } |
| 95 | |
| 96 | if len(serviceToBuild) == 0 { |
| 97 | return imageIDs, nil |
| 98 | } |
| 99 | |
| 100 | bake, err := buildWithBake(s.dockerCli) |
| 101 | if err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | if bake { |
| 105 | return s.doBuildBake(ctx, project, serviceToBuild, options) |
| 106 | } |
| 107 | return s.doBuildClassic(ctx, project, serviceToBuild, options) |
| 108 | } |
| 109 |
no test coverage detected