@@ -5,10 +5,10 @@ import (
55 "io"
66 "path/filepath"
77 "strings"
8- "sync"
98
109 "github.com/docker/buildx/build"
1110 "github.com/docker/buildx/builder"
11+ "github.com/docker/buildx/controller/errdefs"
1212 controllerapi "github.com/docker/buildx/controller/pb"
1313 "github.com/docker/buildx/store"
1414 "github.com/docker/buildx/store/storeutil"
@@ -34,9 +34,9 @@ const defaultTargetName = "default"
3434// NOTE: When an error happens during the build and this function acquires the debuggable *build.ResultHandle,
3535// this function returns it in addition to the error (i.e. it does "return nil, res, err"). The caller can
3636// inspect the result and debug the cause of that error.
37- func RunBuild (ctx context.Context , dockerCli command.Cli , in * Options , inStream io.Reader , progress progress.Writer , generateResult bool ) (* client.SolveResponse , * build. ResultHandle , * build.Inputs , error ) {
37+ func RunBuild (ctx context.Context , dockerCli command.Cli , in * Options , inStream io.Reader , progress progress.Writer , bh * build. Handler ) (* client.SolveResponse , * build.Inputs , error ) {
3838 if in .NoCache && len (in .NoCacheFilter ) > 0 {
39- return nil , nil , nil , errors .Errorf ("--no-cache and --no-cache-filter cannot currently be used together" )
39+ return nil , nil , errors .Errorf ("--no-cache and --no-cache-filter cannot currently be used together" )
4040 }
4141
4242 contexts := map [string ]build.NamedContext {}
@@ -70,7 +70,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream
7070
7171 platforms , err := platformutil .Parse (in .Platforms )
7272 if err != nil {
73- return nil , nil , nil , err
73+ return nil , nil , err
7474 }
7575 opts .Platforms = platforms
7676
@@ -81,7 +81,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream
8181
8282 secrets , err := controllerapi .CreateSecrets (in .Secrets )
8383 if err != nil {
84- return nil , nil , nil , err
84+ return nil , nil , err
8585 }
8686 opts .Session = append (opts .Session , secrets )
8787
@@ -91,13 +91,13 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream
9191 }
9292 ssh , err := controllerapi .CreateSSH (sshSpecs )
9393 if err != nil {
94- return nil , nil , nil , err
94+ return nil , nil , err
9595 }
9696 opts .Session = append (opts .Session , ssh )
9797
9898 outputs , _ , err := controllerapi .CreateExports (in .Exports )
9999 if err != nil {
100- return nil , nil , nil , err
100+ return nil , nil , err
101101 }
102102 if in .ExportPush {
103103 var pushUsed bool
@@ -136,7 +136,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream
136136
137137 annotations , err := buildflags .ParseAnnotations (in .Annotations )
138138 if err != nil {
139- return nil , nil , nil , errors .Wrap (err , "parse annotations" )
139+ return nil , nil , errors .Wrap (err , "parse annotations" )
140140 }
141141
142142 for _ , o := range outputs {
@@ -156,7 +156,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream
156156
157157 allow , err := buildflags .ParseEntitlements (in .Allow )
158158 if err != nil {
159- return nil , nil , nil , err
159+ return nil , nil , err
160160 }
161161 opts .Allow = allow
162162
@@ -180,56 +180,40 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream
180180 builder .WithContextPathHash (contextPathHash ),
181181 )
182182 if err != nil {
183- return nil , nil , nil , err
183+ return nil , nil , err
184184 }
185185 if err = updateLastActivity (dockerCli , b .NodeGroup ); err != nil {
186- return nil , nil , nil , errors .Wrapf (err , "failed to update builder last activity time" )
186+ return nil , nil , errors .Wrapf (err , "failed to update builder last activity time" )
187187 }
188188 nodes , err := b .LoadNodes (ctx )
189189 if err != nil {
190- return nil , nil , nil , err
190+ return nil , nil , err
191191 }
192192
193193 var inputs * build.Inputs
194194 buildOptions := map [string ]build.Options {defaultTargetName : opts }
195- resp , res , err := buildTargets (ctx , dockerCli , nodes , buildOptions , progress , generateResult )
195+ resp , err := buildTargets (ctx , dockerCli , nodes , buildOptions , progress , bh )
196196 err = wrapBuildError (err , false )
197197 if err != nil {
198- // NOTE: buildTargets can return *build.ResultHandle even on error.
199- return nil , res , nil , err
198+ return nil , nil , errdefs .WrapBuild (err )
200199 }
201200 if i , ok := buildOptions [defaultTargetName ]; ok {
202201 inputs = & i .Inputs
203202 }
204- return resp , res , inputs , nil
203+ return resp , inputs , nil
205204}
206205
207206// buildTargets runs the specified build and returns the result.
208207//
209208// NOTE: When an error happens during the build and this function acquires the debuggable *build.ResultHandle,
210209// this function returns it in addition to the error (i.e. it does "return nil, res, err"). The caller can
211210// inspect the result and debug the cause of that error.
212- func buildTargets (ctx context.Context , dockerCli command.Cli , nodes []builder.Node , opts map [string ]build.Options , progress progress.Writer , generateResult bool ) (* client.SolveResponse , * build.ResultHandle , error ) {
213- var res * build.ResultHandle
214- var resp map [string ]* client.SolveResponse
215- var err error
216- if generateResult {
217- var mu sync.Mutex
218- var idx int
219- resp , err = build .BuildWithResultHandler (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .NewConfig (dockerCli ), progress , func (driverIndex int , gotRes * build.ResultHandle ) {
220- mu .Lock ()
221- defer mu .Unlock ()
222- if res == nil || driverIndex < idx {
223- idx , res = driverIndex , gotRes
224- }
225- })
226- } else {
227- resp , err = build .Build (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .NewConfig (dockerCli ), progress )
228- }
211+ func buildTargets (ctx context.Context , dockerCli command.Cli , nodes []builder.Node , opts map [string ]build.Options , progress progress.Writer , bh * build.Handler ) (* client.SolveResponse , error ) {
212+ resp , err := build .BuildWithResultHandler (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .NewConfig (dockerCli ), progress , bh )
229213 if err != nil {
230- return nil , res , err
214+ return nil , err
231215 }
232- return resp [defaultTargetName ], res , err
216+ return resp [defaultTargetName ], err
233217}
234218
235219func wrapBuildError (err error , bake bool ) error {
0 commit comments