@@ -10,10 +10,10 @@ import (
10
10
"github.com/docker/buildx/bake"
11
11
"github.com/docker/buildx/build"
12
12
"github.com/docker/buildx/builder"
13
+ cbuild "github.com/docker/buildx/controller/build"
14
+ controllerapi "github.com/docker/buildx/controller/pb"
13
15
"github.com/docker/buildx/util/buildflags"
14
16
"github.com/docker/buildx/util/cobrautil/completion"
15
- "github.com/docker/buildx/util/confutil"
16
- "github.com/docker/buildx/util/dockerutil"
17
17
"github.com/docker/buildx/util/progress"
18
18
"github.com/docker/buildx/util/tracing"
19
19
"github.com/docker/cli/cli/command"
@@ -29,10 +29,8 @@ type bakeOptions struct {
29
29
sbom string
30
30
provenance string
31
31
32
- builder string
33
- metadataFile string
34
- exportPush bool
35
- exportLoad bool
32
+ controllerapi.CommonOptions
33
+ //control.ControlOptions
36
34
}
37
35
38
36
func runBake (dockerCli command.Cli , targets []string , in bakeOptions , cFlags commonFlags ) (err error ) {
@@ -67,12 +65,12 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
67
65
}
68
66
69
67
overrides := in .overrides
70
- if in .exportPush {
71
- if in .exportLoad {
68
+ if in .ExportPush {
69
+ if in .ExportLoad {
72
70
return errors .Errorf ("push and load may not be set together at the moment" )
73
71
}
74
72
overrides = append (overrides , "*.push=true" )
75
- } else if in .exportLoad {
73
+ } else if in .ExportLoad {
76
74
overrides = append (overrides , "*.output=type=docker" )
77
75
}
78
76
if cFlags .noCache != nil {
@@ -100,7 +98,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
100
98
// instance only needed for reading remote bake files or building
101
99
if url != "" || ! in .printOnly {
102
100
b , err := builder .New (dockerCli ,
103
- builder .WithName (in .builder ),
101
+ builder .WithName (in .Builder ),
104
102
builder .WithContextPathHash (contextPathHash ),
105
103
)
106
104
if err != nil {
@@ -166,7 +164,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
166
164
}
167
165
168
166
// this function can update target context string from the input so call before printOnly check
169
- bo , err := bake .TargetsToBuildOpt (tgts , inp )
167
+ opts , err := bake .TargetsToControllerOptions (tgts , inp )
170
168
if err != nil {
171
169
return err
172
170
}
@@ -191,17 +189,17 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
191
189
return nil
192
190
}
193
191
194
- resp , err := build . Build (ctx , nodes , bo , dockerutil . NewClient ( dockerCli ), confutil . ConfigDir ( dockerCli ) , printer )
192
+ resp , _ , err := cbuild . RunBuilds (ctx , dockerCli , in . Builder , opts , os . Stdin , printer , false )
195
193
if err != nil {
196
194
return wrapBuildError (err , true )
197
195
}
198
196
199
- if len (in .metadataFile ) > 0 {
197
+ if len (in .MetadataFile ) > 0 {
200
198
dt := make (map [string ]interface {})
201
199
for t , r := range resp {
202
200
dt [t ] = decodeExporterResponse (r .ExporterResponse )
203
201
}
204
- if err := writeMetadataFile (in .metadataFile , dt ); err != nil {
202
+ if err := writeMetadataFile (in .MetadataFile , dt ); err != nil {
205
203
return err
206
204
}
207
205
}
@@ -225,8 +223,8 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
225
223
if ! cmd .Flags ().Lookup ("pull" ).Changed {
226
224
cFlags .pull = nil
227
225
}
228
- options .builder = rootOpts .builder
229
- options .metadataFile = cFlags .metadataFile
226
+ options .Builder = rootOpts .builder
227
+ options .MetadataFile = cFlags .metadataFile
230
228
// Other common flags (noCache, pull and progress) are processed in runBake function.
231
229
return runBake (dockerCli , args , options , cFlags )
232
230
},
@@ -236,9 +234,9 @@ func bakeCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
236
234
flags := cmd .Flags ()
237
235
238
236
flags .StringArrayVarP (& options .files , "file" , "f" , []string {}, "Build definition file" )
239
- flags .BoolVar (& options .exportLoad , "load" , false , `Shorthand for "--set=*.output=type=docker"` )
237
+ flags .BoolVar (& options .ExportLoad , "load" , false , `Shorthand for "--set=*.output=type=docker"` )
240
238
flags .BoolVar (& options .printOnly , "print" , false , "Print the options without building" )
241
- flags .BoolVar (& options .exportPush , "push" , false , `Shorthand for "--set=*.output=type=registry"` )
239
+ flags .BoolVar (& options .ExportPush , "push" , false , `Shorthand for "--set=*.output=type=registry"` )
242
240
flags .StringVar (& options .sbom , "sbom" , "" , `Shorthand for "--set=*.attest=type=sbom"` )
243
241
flags .StringVar (& options .provenance , "provenance" , "" , `Shorthand for "--set=*.attest=type=provenance"` )
244
242
flags .StringArrayVar (& options .overrides , "set" , nil , `Override target value (e.g., "targetpattern.key=value")` )
0 commit comments