@@ -11,11 +11,11 @@ import (
11
11
"github.com/docker/buildx/bake"
12
12
"github.com/docker/buildx/build"
13
13
"github.com/docker/buildx/builder"
14
+ cbuild "github.com/docker/buildx/controller/build"
15
+ controllerapi "github.com/docker/buildx/controller/pb"
14
16
"github.com/docker/buildx/util/buildflags"
15
17
"github.com/docker/buildx/util/cobrautil/completion"
16
- "github.com/docker/buildx/util/confutil"
17
18
"github.com/docker/buildx/util/desktop"
18
- "github.com/docker/buildx/util/dockerutil"
19
19
"github.com/docker/buildx/util/progress"
20
20
"github.com/docker/buildx/util/tracing"
21
21
"github.com/docker/cli/cli/command"
@@ -31,10 +31,8 @@ type bakeOptions struct {
31
31
sbom string
32
32
provenance string
33
33
34
- builder string
35
- metadataFile string
36
- exportPush bool
37
- exportLoad bool
34
+ controllerapi.CommonOptions
35
+ //control.ControlOptions
38
36
}
39
37
40
38
func runBake (dockerCli command.Cli , targets []string , in bakeOptions , cFlags commonFlags ) (err error ) {
@@ -69,12 +67,12 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
69
67
}
70
68
71
69
overrides := in .overrides
72
- if in .exportPush {
73
- if in .exportLoad {
70
+ if in .ExportPush {
71
+ if in .ExportLoad {
74
72
return errors .Errorf ("push and load may not be set together at the moment" )
75
73
}
76
74
overrides = append (overrides , "*.push=true" )
77
- } else if in .exportLoad {
75
+ } else if in .ExportLoad {
78
76
overrides = append (overrides , "*.output=type=docker" )
79
77
}
80
78
if cFlags .noCache != nil {
@@ -102,7 +100,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
102
100
// instance only needed for reading remote bake files or building
103
101
if url != "" || ! in .printOnly {
104
102
b , err := builder .New (dockerCli ,
105
- builder .WithName (in .builder ),
103
+ builder .WithName (in .Builder ),
106
104
builder .WithContextPathHash (contextPathHash ),
107
105
)
108
106
if err != nil {
@@ -176,11 +174,19 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
176
174
}
177
175
178
176
// this function can update target context string from the input so call before printOnly check
179
- bo , err := bake .TargetsToBuildOpt (tgts , inp )
177
+ opts , err := bake .TargetsToControllerOptions (tgts , inp )
180
178
if err != nil {
181
179
return err
182
180
}
183
181
182
+ // set builder name and context hash for all targets
183
+ updatedOpts := make (map [string ]controllerapi.BuildOptions , len (opts ))
184
+ for i , opt := range opts {
185
+ opt .Opts .Builder = in .Builder
186
+ opt .Inputs .ContextPathHash = contextPathHash
187
+ updatedOpts [i ] = opt
188
+ }
189
+
184
190
if in .printOnly {
185
191
dt , err := json .MarshalIndent (struct {
186
192
Group map [string ]* bake.Group `json:"group,omitempty"`
@@ -201,17 +207,17 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
201
207
return nil
202
208
}
203
209
204
- resp , err := build . Build (ctx , nodes , bo , dockerutil . NewClient ( dockerCli ), confutil . ConfigDir ( dockerCli ), printer )
210
+ resp , _ , err := cbuild . RunBuilds (ctx , dockerCli , updatedOpts , os . Stdin , printer , false )
205
211
if err != nil {
206
212
return wrapBuildError (err , true )
207
213
}
208
214
209
- if len (in .metadataFile ) > 0 {
215
+ if len (in .MetadataFile ) > 0 {
210
216
dt := make (map [string ]interface {})
211
217
for t , r := range resp {
212
218
dt [t ] = decodeExporterResponse (r .ExporterResponse )
213
219
}
214
- if err := writeMetadataFile (in .metadataFile , dt ); err != nil {
220
+ if err := writeMetadataFile (in .MetadataFile , dt ); err != nil {
215
221
return err
216
222
}
217
223
}
@@ -235,8 +241,8 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
235
241
if ! cmd .Flags ().Lookup ("pull" ).Changed {
236
242
cFlags .pull = nil
237
243
}
238
- options .builder = rootOpts .builder
239
- options .metadataFile = cFlags .metadataFile
244
+ options .Builder = rootOpts .builder
245
+ options .MetadataFile = cFlags .metadataFile
240
246
// Other common flags (noCache, pull and progress) are processed in runBake function.
241
247
return runBake (dockerCli , args , options , cFlags )
242
248
},
@@ -246,9 +252,9 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
246
252
flags := cmd .Flags ()
247
253
248
254
flags .StringArrayVarP (& options .files , "file" , "f" , []string {}, "Build definition file" )
249
- flags .BoolVar (& options .exportLoad , "load" , false , `Shorthand for "--set=*.output=type=docker"` )
255
+ flags .BoolVar (& options .ExportLoad , "load" , false , `Shorthand for "--set=*.output=type=docker"` )
250
256
flags .BoolVar (& options .printOnly , "print" , false , "Print the options without building" )
251
- flags .BoolVar (& options .exportPush , "push" , false , `Shorthand for "--set=*.output=type=registry"` )
257
+ flags .BoolVar (& options .ExportPush , "push" , false , `Shorthand for "--set=*.output=type=registry"` )
252
258
flags .StringVar (& options .sbom , "sbom" , "" , `Shorthand for "--set=*.attest=type=sbom"` )
253
259
flags .StringVar (& options .provenance , "provenance" , "" , `Shorthand for "--set=*.attest=type=provenance"` )
254
260
flags .StringArrayVar (& options .overrides , "set" , nil , `Override target value (e.g., "targetpattern.key=value")` )
0 commit comments