11package build
22
33import (
4- "bytes"
54 "context"
65 "encoding/base64"
76 "encoding/csv"
87 "encoding/json"
9- "fmt"
108 "io"
119 "os"
1210 "path/filepath"
@@ -30,12 +28,8 @@ import (
3028 "github.com/docker/go-units"
3129 "github.com/moby/buildkit/client"
3230 "github.com/moby/buildkit/session/auth/authprovider"
33- "github.com/moby/buildkit/solver/errdefs"
3431 "github.com/moby/buildkit/util/grpcerrors"
35- "github.com/moby/buildkit/util/progress/progressui"
36- "github.com/morikuni/aec"
3732 "github.com/pkg/errors"
38- "github.com/sirupsen/logrus"
3933 "google.golang.org/grpc/codes"
4034)
4135
@@ -46,7 +40,7 @@ const defaultTargetName = "default"
4640// NOTE: When an error happens during the build and this function acquires the debuggable *build.ResultContext,
4741// this function returns it in addition to the error (i.e. it does "return nil, res, err"). The caller can
4842// inspect the result and debug the cause of that error.
49- func RunBuild (ctx context.Context , dockerCli command.Cli , in controllerapi.BuildOptions , inStream io.Reader , progressMode string , statusChan chan * client. SolveStatus , generateResult bool ) (* client.SolveResponse , * build.ResultContext , error ) {
43+ func RunBuild (ctx context.Context , dockerCli command.Cli , in controllerapi.BuildOptions , inStream io.Reader , progress progress. Writer , generateResult bool ) (* client.SolveResponse , * build.ResultContext , error ) {
5044 if in .NoCache && len (in .NoCacheFilter ) > 0 {
5145 return nil , nil , errors .Errorf ("--no-cache and --no-cache-filter cannot currently be used together" )
5246 }
@@ -164,6 +158,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
164158 contextPathHash = in .ContextPath
165159 }
166160
161+ // TODO: this should not be loaded this side of the controller api
167162 b , err := builder .New (dockerCli ,
168163 builder .WithName (in .Builder ),
169164 builder .WithContextPathHash (contextPathHash ),
@@ -179,7 +174,7 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
179174 return nil , nil , err
180175 }
181176
182- resp , res , err := buildTargets (ctx , dockerCli , b .NodeGroup , nodes , map [string ]build.Options {defaultTargetName : opts }, progressMode , in .MetadataFile , statusChan , generateResult )
177+ resp , res , err := buildTargets (ctx , dockerCli , b .NodeGroup , nodes , map [string ]build.Options {defaultTargetName : opts }, progress , in .MetadataFile , generateResult )
183178 err = wrapBuildError (err , false )
184179 if err != nil {
185180 // NOTE: buildTargets can return *build.ResultContext even on error.
@@ -193,36 +188,22 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in controllerapi.Build
193188// NOTE: When an error happens during the build and this function acquires the debuggable *build.ResultContext,
194189// this function returns it in addition to the error (i.e. it does "return nil, res, err"). The caller can
195190// inspect the result and debug the cause of that error.
196- func buildTargets (ctx context.Context , dockerCli command.Cli , ng * store.NodeGroup , nodes []builder.Node , opts map [string ]build.Options , progressMode string , metadataFile string , statusChan chan * client.SolveStatus , generateResult bool ) (* client.SolveResponse , * build.ResultContext , error ) {
197- ctx2 , cancel := context .WithCancel (context .TODO ())
198- defer cancel ()
199-
200- printer , err := progress .NewPrinter (ctx2 , os .Stderr , os .Stderr , progressMode , progressui .WithDesc (
201- fmt .Sprintf ("building with %q instance using %s driver" , ng .Name , ng .Driver ),
202- fmt .Sprintf ("%s:%s" , ng .Driver , ng .Name ),
203- ))
204- if err != nil {
205- return nil , nil , err
206- }
207-
191+ func buildTargets (ctx context.Context , dockerCli command.Cli , ng * store.NodeGroup , nodes []builder.Node , opts map [string ]build.Options , progress progress.Writer , metadataFile string , generateResult bool ) (* client.SolveResponse , * build.ResultContext , error ) {
208192 var res * build.ResultContext
209193 var resp map [string ]* client.SolveResponse
194+ var err error
210195 if generateResult {
211196 var mu sync.Mutex
212197 var idx int
213- resp , err = build .BuildWithResultHandler (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .ConfigDir (dockerCli ), progress . Tee ( printer , statusChan ) , func (driverIndex int , gotRes * build.ResultContext ) {
198+ resp , err = build .BuildWithResultHandler (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .ConfigDir (dockerCli ), progress , func (driverIndex int , gotRes * build.ResultContext ) {
214199 mu .Lock ()
215200 defer mu .Unlock ()
216201 if res == nil || driverIndex < idx {
217202 idx , res = driverIndex , gotRes
218203 }
219204 })
220205 } else {
221- resp , err = build .Build (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .ConfigDir (dockerCli ), progress .Tee (printer , statusChan ))
222- }
223- err1 := printer .Wait ()
224- if err == nil {
225- err = err1
206+ resp , err = build .Build (ctx , nodes , opts , dockerutil .NewClient (dockerCli ), confutil .ConfigDir (dockerCli ), progress )
226207 }
227208 if err != nil {
228209 return nil , res , err
@@ -234,8 +215,6 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, ng *store.NodeGrou
234215 }
235216 }
236217
237- printWarnings (os .Stderr , printer .Warnings (), progressMode )
238-
239218 for k := range resp {
240219 if opts [k ].PrintFunc != nil {
241220 if err := printResult (opts [k ].PrintFunc , resp [k ].ExporterResponse ); err != nil {
@@ -247,46 +226,6 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, ng *store.NodeGrou
247226 return resp [defaultTargetName ], res , err
248227}
249228
250- func printWarnings (w io.Writer , warnings []client.VertexWarning , mode string ) {
251- if len (warnings ) == 0 || mode == progress .PrinterModeQuiet {
252- return
253- }
254- fmt .Fprintf (w , "\n " )
255- sb := & bytes.Buffer {}
256- if len (warnings ) == 1 {
257- fmt .Fprintf (sb , "1 warning found" )
258- } else {
259- fmt .Fprintf (sb , "%d warnings found" , len (warnings ))
260- }
261- if logrus .GetLevel () < logrus .DebugLevel {
262- fmt .Fprintf (sb , " (use --debug to expand)" )
263- }
264- fmt .Fprintf (sb , ":\n " )
265- fmt .Fprint (w , aec .Apply (sb .String (), aec .YellowF ))
266-
267- for _ , warn := range warnings {
268- fmt .Fprintf (w , " - %s\n " , warn .Short )
269- if logrus .GetLevel () < logrus .DebugLevel {
270- continue
271- }
272- for _ , d := range warn .Detail {
273- fmt .Fprintf (w , "%s\n " , d )
274- }
275- if warn .URL != "" {
276- fmt .Fprintf (w , "More info: %s\n " , warn .URL )
277- }
278- if warn .SourceInfo != nil && warn .Range != nil {
279- src := errdefs.Source {
280- Info : warn .SourceInfo ,
281- Ranges : warn .Range ,
282- }
283- src .Print (w )
284- }
285- fmt .Fprintf (w , "\n " )
286-
287- }
288- }
289-
290229func parsePrintFunc (str string ) (* build.PrintFunc , error ) {
291230 if str == "" {
292231 return nil , nil
0 commit comments