mirror of https://github.com/docker/compose.git
Improve buildkit node creation (#10843)
Move builder and nodes initialization code up, avoiding to recreate/load them for every service build. Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This commit is contained in:
parent
3b0742fd57
commit
7c42776770
|
@ -22,6 +22,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/docker/buildx/builder"
|
||||||
"github.com/docker/compose/v2/internal/tracing"
|
"github.com/docker/compose/v2/internal/tracing"
|
||||||
|
|
||||||
"github.com/docker/buildx/controller/pb"
|
"github.com/docker/buildx/controller/pb"
|
||||||
|
@ -68,6 +69,27 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize buildkit nodes
|
||||||
|
var (
|
||||||
|
b *builder.Builder
|
||||||
|
nodes []builder.Node
|
||||||
|
)
|
||||||
|
if buildkitEnabled {
|
||||||
|
builderName := options.Builder
|
||||||
|
if builderName == "" {
|
||||||
|
builderName = os.Getenv("BUILDX_BUILDER")
|
||||||
|
}
|
||||||
|
b, err = builder.New(s.dockerCli, builder.WithName(builderName))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes, err = b.LoadNodes(ctx, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Progress needs its own context that lives longer than the
|
// Progress needs its own context that lives longer than the
|
||||||
// build one otherwise it won't read all the messages from
|
// build one otherwise it won't read all the messages from
|
||||||
// build and will lock
|
// build and will lock
|
||||||
|
@ -118,7 +140,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
||||||
}
|
}
|
||||||
buildOptions.BuildArgs = mergeArgs(buildOptions.BuildArgs, flatten(args))
|
buildOptions.BuildArgs = mergeArgs(buildOptions.BuildArgs, flatten(args))
|
||||||
|
|
||||||
digest, err := s.doBuildBuildkit(ctx, service.Name, buildOptions, w, options.Builder)
|
digest, err := s.doBuildBuildkit(ctx, service.Name, buildOptions, w, nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,18 +34,11 @@ import (
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) doBuildBuildkit(ctx context.Context, service string, opts build.Options, p *buildx.Printer, builderName string) (string, error) {
|
func (s *composeService) doBuildBuildkit(ctx context.Context, service string, opts build.Options, p *buildx.Printer, nodes []builder.Node) (string, error) {
|
||||||
b, err := builder.New(s.dockerCli, builder.WithName(builderName))
|
var (
|
||||||
if err != nil {
|
response map[string]*client.SolveResponse
|
||||||
return "", err
|
err error
|
||||||
}
|
)
|
||||||
|
|
||||||
nodes, err := b.LoadNodes(ctx, false)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
var response map[string]*client.SolveResponse
|
|
||||||
if s.dryRun {
|
if s.dryRun {
|
||||||
response = s.dryRunBuildResponse(ctx, service, opts)
|
response = s.dryRunBuildResponse(ctx, service, opts)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue