@@ -14,6 +14,7 @@ import (
1414 "strings"
1515
1616 "github.com/containerd/console"
17+ "github.com/docker/buildx/build"
1718 "github.com/docker/buildx/controller"
1819 cbuild "github.com/docker/buildx/controller/build"
1920 "github.com/docker/buildx/controller/control"
@@ -35,6 +36,7 @@ import (
3536 "github.com/moby/buildkit/exporter/containerimage/exptypes"
3637 "github.com/moby/buildkit/util/appcontext"
3738 "github.com/moby/buildkit/util/grpcerrors"
39+ "github.com/moby/buildkit/util/progress/progressui"
3840 "github.com/pkg/errors"
3941 "github.com/sirupsen/logrus"
4042 "github.com/spf13/cobra"
@@ -75,7 +77,13 @@ type buildOptions struct {
7577 progress string
7678 quiet bool
7779
78- controllerapi.CommonOptions
80+ builder string
81+ metadataFile string
82+ noCache bool
83+ pull bool
84+ exportPush bool
85+ exportLoad bool
86+
7987 control.ControlOptions
8088}
8189
@@ -97,7 +105,12 @@ func (o *buildOptions) toControllerOptions() (controllerapi.BuildOptions, error)
97105 Tags : o .tags ,
98106 Target : o .target ,
99107 Ulimits : dockerUlimitToControllerUlimit (o .ulimits ),
100- Opts : & o .CommonOptions ,
108+ Builder : o .builder ,
109+ MetadataFile : o .metadataFile ,
110+ NoCache : o .noCache ,
111+ Pull : o .pull ,
112+ ExportPush : o .exportPush ,
113+ ExportLoad : o .exportLoad ,
101114 }
102115
103116 inAttests := append ([]string {}, o .attests ... )
@@ -179,7 +192,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
179192 if err != nil {
180193 return err
181194 }
182- progress , err := in .toProgress ()
195+ progressMode , err := in .toProgress ()
183196 if err != nil {
184197 return err
185198 }
@@ -190,7 +203,20 @@ func runBuild(dockerCli command.Cli, in buildOptions) error {
190203 return errors .Wrap (err , "removing image ID file" )
191204 }
192205 }
193- resp , _ , err := cbuild .RunBuild (ctx , dockerCli , opts , os .Stdin , progress , nil )
206+ resp , _ , err := cbuild .RunBuild (ctx , dockerCli , opts , os .Stdin , cbuild.ProgressConfig {
207+ Printer : func (ctx2 context.Context , ng * store.NodeGroup ) (* progress.Printer , error ) {
208+ return progress .NewPrinter (ctx2 , os .Stderr , os .Stderr , progressMode , progressui .WithDesc (
209+ fmt .Sprintf ("building with %q instance using %s driver" , ng .Name , ng .Driver ),
210+ fmt .Sprintf ("%s:%s" , ng .Driver , ng .Name ),
211+ ))
212+ },
213+ PrintWarningsFunc : func (warnings []client.VertexWarning ) {
214+ cbuild .PrintWarnings (os .Stderr , warnings , progressMode )
215+ },
216+ PrintResultFunc : func (f * build.PrintFunc , res map [string ]string ) error {
217+ return cbuild .PrintResult (os .Stdout , f , res )
218+ },
219+ })
194220 if err != nil {
195221 return err
196222 }
@@ -218,15 +244,15 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
218244 Args : cli .ExactArgs (1 ),
219245 RunE : func (cmd * cobra.Command , args []string ) error {
220246 options .contextPath = args [0 ]
221- options .Builder = rootOpts .builder
222- options .MetadataFile = cFlags .metadataFile
223- options .NoCache = false
247+ options .builder = rootOpts .builder
248+ options .metadataFile = cFlags .metadataFile
249+ options .noCache = false
224250 if cFlags .noCache != nil {
225- options .NoCache = * cFlags .noCache
251+ options .noCache = * cFlags .noCache
226252 }
227- options .Pull = false
253+ options .pull = false
228254 if cFlags .pull != nil {
229- options .Pull = * cFlags .pull
255+ options .pull = * cFlags .pull
230256 }
231257 options .progress = cFlags .progress
232258 cmd .Flags ().VisitAll (checkWarnedFlags )
@@ -267,7 +293,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
267293
268294 flags .StringArrayVar (& options .labels , "label" , []string {}, "Set metadata for an image" )
269295
270- flags .BoolVar (& options .ExportLoad , "load" , false , `Shorthand for "--output=type=docker"` )
296+ flags .BoolVar (& options .exportLoad , "load" , false , `Shorthand for "--output=type=docker"` )
271297
272298 flags .StringVar (& options .networkMode , "network" , "default" , `Set the networking mode for the "RUN" instructions during build` )
273299
@@ -281,7 +307,7 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
281307 flags .StringVar (& options .printFunc , "print" , "" , "Print result of information request (e.g., outline, targets) [experimental]" )
282308 }
283309
284- flags .BoolVar (& options .ExportPush , "push" , false , `Shorthand for "--output=type=registry"` )
310+ flags .BoolVar (& options .exportPush , "push" , false , `Shorthand for "--output=type=registry"` )
285311
286312 flags .BoolVarP (& options .quiet , "quiet" , "q" , false , "Suppress the build output and print image ID on success" )
287313
@@ -523,7 +549,7 @@ func launchControllerAndRunBuild(dockerCli command.Cli, options buildOptions) er
523549 return err
524550 }
525551 opts = * optsP
526- ref , resp , err := c .Build (ctx , opts , pr , os .Stdout , os .Stderr , progress )
552+ ref , resp , err := control .Build (ctx , c , opts , pr , os .Stdout , os .Stderr , progress )
527553 if err != nil {
528554 return errors .Wrapf (err , "failed to build" ) // TODO: allow invoke even on error
529555 }
@@ -805,8 +831,8 @@ func resolvePaths(options *controllerapi.BuildOptions) (_ *controllerapi.BuildOp
805831 }
806832 options .SSH = ssh
807833
808- if options .Opts != nil && options . Opts . MetadataFile != "" {
809- options .Opts . MetadataFile , err = filepath .Abs (options . Opts .MetadataFile )
834+ if options .MetadataFile != "" {
835+ options .MetadataFile , err = filepath .Abs (options .MetadataFile )
810836 if err != nil {
811837 return nil , err
812838 }
0 commit comments