@@ -21,7 +21,6 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"os"
24
- "path/filepath"
25
24
26
25
"github.com/compose-spec/compose-go/v2/types"
27
26
"github.com/containerd/platforms"
@@ -38,7 +37,6 @@ import (
38
37
"github.com/docker/compose/v2/pkg/progress"
39
38
"github.com/docker/compose/v2/pkg/utils"
40
39
"github.com/docker/docker/api/types/container"
41
- "github.com/docker/docker/builder/remotecontext/urlutil"
42
40
bclient "github.com/moby/buildkit/client"
43
41
"github.com/moby/buildkit/session"
44
42
"github.com/moby/buildkit/session/auth/authprovider"
@@ -64,26 +62,16 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
64
62
}, s .stdinfo (), "Building" )
65
63
}
66
64
67
- type serviceToBuild struct {
68
- name string
69
- service types.ServiceConfig
70
- }
71
-
72
65
//nolint:gocyclo
73
66
func (s * composeService ) build (ctx context.Context , project * types.Project , options api.BuildOptions , localImages map [string ]string ) (map [string ]string , error ) {
74
- buildkitEnabled , err := s .dockerCli .BuildKitEnabled ()
75
- if err != nil {
76
- return nil , err
77
- }
78
-
79
67
imageIDs := map [string ]string {}
80
- serviceToBeBuild := map [ string ] serviceToBuild {}
68
+ serviceToBuild := types. Services {}
81
69
82
70
var policy types.DependencyOption = types .IgnoreDependencies
83
71
if options .Deps {
84
72
policy = types .IncludeDependencies
85
73
}
86
- err = project .ForEachService (options .Services , func (serviceName string , service * types.ServiceConfig ) error {
74
+ err : = project .ForEachService (options .Services , func (serviceName string , service * types.ServiceConfig ) error {
87
75
if service .Build == nil {
88
76
return nil
89
77
}
@@ -92,14 +80,26 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
92
80
if localImagePresent && service .PullPolicy != types .PullPolicyBuild {
93
81
return nil
94
82
}
95
- serviceToBeBuild [serviceName ] = serviceToBuild { name : serviceName , service : * service }
83
+ serviceToBuild [serviceName ] = * service
96
84
return nil
97
85
}, policy )
98
- if err != nil || len (serviceToBeBuild ) == 0 {
86
+ if err != nil || len (serviceToBuild ) == 0 {
99
87
return imageIDs , err
100
88
}
101
89
90
+ bake , err := buildWithBake (s .dockerCli )
91
+ if err != nil {
92
+ return nil , err
93
+ }
94
+ if bake {
95
+ return s .doBuildBake (ctx , project , serviceToBuild , options )
96
+ }
97
+
102
98
// Initialize buildkit nodes
99
+ buildkitEnabled , err := s .dockerCli .BuildKitEnabled ()
100
+ if err != nil {
101
+ return nil , err
102
+ }
103
103
var (
104
104
b * builder.Builder
105
105
nodes []builder.Node
@@ -152,12 +152,10 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
152
152
return - 1
153
153
}
154
154
err = InDependencyOrder (ctx , project , func (ctx context.Context , name string ) error {
155
- serviceToBuild , ok := serviceToBeBuild [name ]
155
+ service , ok := serviceToBuild [name ]
156
156
if ! ok {
157
157
return nil
158
158
}
159
- service := serviceToBuild .service
160
-
161
159
cw := progress .ContextWriter (ctx )
162
160
serviceName := fmt .Sprintf ("Service %s" , name )
163
161
@@ -211,7 +209,8 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
211
209
212
210
for i , imageDigest := range builtDigests {
213
211
if imageDigest != "" {
214
- imageRef := api .GetImageNameOrDefault (project.Services [names [i ]], project .Name )
212
+ service := project.Services [names [i ]]
213
+ imageRef := api .GetImageNameOrDefault (service , project .Name )
215
214
imageIDs [imageRef ] = imageDigest
216
215
}
217
216
}
@@ -334,12 +333,7 @@ func (s *composeService) getLocalImagesDigests(ctx context.Context, project *typ
334
333
//
335
334
// Finally, standard proxy variables based on the Docker client configuration are added, but will not overwrite
336
335
// any values if already present.
337
- func resolveAndMergeBuildArgs (
338
- dockerCli command.Cli ,
339
- project * types.Project ,
340
- service types.ServiceConfig ,
341
- opts api.BuildOptions ,
342
- ) types.MappingWithEquals {
336
+ func resolveAndMergeBuildArgs (dockerCli command.Cli , project * types.Project , service types.ServiceConfig , opts api.BuildOptions ) types.MappingWithEquals {
343
337
result := make (types.MappingWithEquals ).
344
338
OverrideBy (service .Build .Args ).
345
339
OverrideBy (opts .Args ).
@@ -479,16 +473,6 @@ func flatten(in types.MappingWithEquals) types.Mapping {
479
473
return out
480
474
}
481
475
482
- func dockerFilePath (ctxName string , dockerfile string ) string {
483
- if dockerfile == "" {
484
- return ""
485
- }
486
- if urlutil .IsGitURL (ctxName ) || filepath .IsAbs (dockerfile ) {
487
- return dockerfile
488
- }
489
- return filepath .Join (ctxName , dockerfile )
490
- }
491
-
492
476
func sshAgentProvider (sshKeys types.SSHConfig ) (session.Attachable , error ) {
493
477
sshConfig := make ([]sshprovider.AgentConfig , 0 , len (sshKeys ))
494
478
for _ , sshKey := range sshKeys {
0 commit comments