mirror of
https://github.com/docker/compose.git
synced 2025-07-09 14:54:27 +02:00
limit build concurrency according to --parallel
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
dcbd68a102
commit
b96e27e0e7
@ -51,14 +51,16 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
|||||||
opts := map[string]build.Options{}
|
opts := map[string]build.Options{}
|
||||||
args := flatten(options.Args.Resolve(envResolver(project.Environment)))
|
args := flatten(options.Args.Resolve(envResolver(project.Environment)))
|
||||||
|
|
||||||
services, err := project.GetServices(options.Services...)
|
return InDependencyOrder(ctx, project, func(ctx context.Context, name string) error {
|
||||||
|
if len(options.Services) > 0 && !utils.Contains(options.Services, name) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
service, err := project.GetService(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range services {
|
|
||||||
if service.Build == nil {
|
if service.Build == nil {
|
||||||
continue
|
return nil
|
||||||
}
|
}
|
||||||
imageName := api.GetImageNameOrDefault(service, project.Name)
|
imageName := api.GetImageNameOrDefault(service, project.Name)
|
||||||
buildOptions, err := s.toBuildOptions(project, service, imageName, options.SSHs)
|
buildOptions, err := s.toBuildOptions(project, service, imageName, options.SSHs)
|
||||||
@ -91,10 +93,11 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
opts[imageName] = buildOptions
|
opts[imageName] = buildOptions
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.doBuild(ctx, project, opts, options.Progress)
|
_, err = s.doBuild(ctx, project, opts, options.Progress)
|
||||||
return err
|
return err
|
||||||
|
}, func(traversal *graphTraversal) {
|
||||||
|
traversal.maxConcurrency = s.maxConcurrency
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) ensureImagesExists(ctx context.Context, project *types.Project, quietPull bool) error {
|
func (s *composeService) ensureImagesExists(ctx context.Context, project *types.Project, quietPull bool) error {
|
||||||
|
@ -48,6 +48,7 @@ type graphTraversal struct {
|
|||||||
adjacentServiceStatusToSkip ServiceStatus
|
adjacentServiceStatusToSkip ServiceStatus
|
||||||
|
|
||||||
visitorFn func(context.Context, string) error
|
visitorFn func(context.Context, string) error
|
||||||
|
maxConcurrency int
|
||||||
}
|
}
|
||||||
|
|
||||||
func upDirectionTraversal(visitorFn func(context.Context, string) error) *graphTraversal {
|
func upDirectionTraversal(visitorFn func(context.Context, string) error) *graphTraversal {
|
||||||
@ -79,6 +80,9 @@ func InDependencyOrder(ctx context.Context, project *types.Project, fn func(cont
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t := upDirectionTraversal(fn)
|
t := upDirectionTraversal(fn)
|
||||||
|
for _, option := range options {
|
||||||
|
option(t)
|
||||||
|
}
|
||||||
return t.visit(ctx, graph)
|
return t.visit(ctx, graph)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +100,9 @@ func (t *graphTraversal) visit(ctx context.Context, g *Graph) error {
|
|||||||
nodes := t.extremityNodesFn(g)
|
nodes := t.extremityNodesFn(g)
|
||||||
|
|
||||||
eg, ctx := errgroup.WithContext(ctx)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
|
if t.maxConcurrency > 0 {
|
||||||
|
eg.SetLimit(t.maxConcurrency)
|
||||||
|
}
|
||||||
t.run(ctx, g, eg, nodes)
|
t.run(ctx, g, eg, nodes)
|
||||||
|
|
||||||
return eg.Wait()
|
return eg.Wait()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user