@@ -95,7 +95,7 @@ func (bm *BuildManager) Build(ctx context.Context, config backend.BuildConfig) (
9595 if err != nil {
9696 return nil , err
9797 }
98- return b .build (source , dockerfile )
98+ return b .build (ctx , source , dockerfile )
9999}
100100
101101// builderOptions are the dependencies required by the builder
@@ -136,6 +136,11 @@ func newBuilder(clientCtx context.Context, options builderOptions) (*Builder, er
136136 config = new (types.ImageBuildOptions )
137137 }
138138
139+ imageProber , err := newImageProber (clientCtx , options .Backend , config .CacheFrom , config .NoCache )
140+ if err != nil {
141+ return nil , err
142+ }
143+
139144 b := & Builder {
140145 clientCtx : clientCtx ,
141146 options : config ,
@@ -147,7 +152,7 @@ func newBuilder(clientCtx context.Context, options builderOptions) (*Builder, er
147152 idMapping : options .IDMapping ,
148153 imageSources : newImageSources (clientCtx , options ),
149154 pathCache : options .PathCache ,
150- imageProber : newImageProber ( options . Backend , config . CacheFrom , config . NoCache ) ,
155+ imageProber : imageProber ,
151156 containerManager : newContainerManager (options .Backend ),
152157 }
153158
@@ -181,7 +186,7 @@ func buildLabelOptions(labels map[string]string, stages []instructions.Stage) {
181186
182187// Build runs the Dockerfile builder by parsing the Dockerfile and executing
183188// the instructions from the file.
184- func (b * Builder ) build (source builder.Source , dockerfile * parser.Result ) (* builder.Result , error ) {
189+ func (b * Builder ) build (ctx context. Context , source builder.Source , dockerfile * parser.Result ) (* builder.Result , error ) {
185190 defer b .imageSources .Unmount ()
186191
187192 stages , metaArgs , err := instructions .Parse (dockerfile .AST )
@@ -205,7 +210,7 @@ func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*buil
205210 buildLabelOptions (b .options .Labels , stages )
206211
207212 dockerfile .PrintWarnings (b .Stderr )
208- dispatchState , err := b .dispatchDockerfileWithCancellation (stages , metaArgs , dockerfile .EscapeToken , source )
213+ dispatchState , err := b .dispatchDockerfileWithCancellation (ctx , stages , metaArgs , dockerfile .EscapeToken , source )
209214 if err != nil {
210215 return nil , err
211216 }
@@ -244,7 +249,7 @@ func printCommand(out io.Writer, currentCommandIndex int, totalCommands int, cmd
244249 return currentCommandIndex + 1
245250}
246251
247- func (b * Builder ) dispatchDockerfileWithCancellation (parseResult []instructions.Stage , metaArgs []instructions.ArgCommand , escapeToken rune , source builder.Source ) (* dispatchState , error ) {
252+ func (b * Builder ) dispatchDockerfileWithCancellation (ctx context. Context , parseResult []instructions.Stage , metaArgs []instructions.ArgCommand , escapeToken rune , source builder.Source ) (* dispatchState , error ) {
248253 dispatchRequest := dispatchRequest {}
249254 buildArgs := NewBuildArgs (b .options .BuildArgs )
250255 totalCommands := len (metaArgs ) + len (parseResult )
@@ -272,7 +277,7 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions.
272277 dispatchRequest = newDispatchRequest (b , escapeToken , source , buildArgs , stagesResults )
273278
274279 currentCommandIndex = printCommand (b .Stdout , currentCommandIndex , totalCommands , stage .SourceCode )
275- if err := initializeStage (dispatchRequest , & stage ); err != nil {
280+ if err := initializeStage (ctx , dispatchRequest , & stage ); err != nil {
276281 return nil , err
277282 }
278283 dispatchRequest .state .updateRunConfig ()
@@ -290,7 +295,7 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions.
290295
291296 currentCommandIndex = printCommand (b .Stdout , currentCommandIndex , totalCommands , cmd )
292297
293- if err := dispatch (dispatchRequest , cmd ); err != nil {
298+ if err := dispatch (ctx , dispatchRequest , cmd ); err != nil {
294299 return nil , err
295300 }
296301 dispatchRequest .state .updateRunConfig ()
@@ -317,7 +322,7 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions.
317322// coming from the query parameter of the same name.
318323//
319324// TODO: Remove?
320- func BuildFromConfig (config * container.Config , changes []string , os string ) (* container.Config , error ) {
325+ func BuildFromConfig (ctx context. Context , config * container.Config , changes []string , os string ) (* container.Config , error ) {
321326 if len (changes ) == 0 {
322327 return config , nil
323328 }
@@ -327,7 +332,7 @@ func BuildFromConfig(config *container.Config, changes []string, os string) (*co
327332 return nil , errdefs .InvalidParameter (err )
328333 }
329334
330- b , err := newBuilder (context . Background () , builderOptions {
335+ b , err := newBuilder (ctx , builderOptions {
331336 Options : & types.ImageBuildOptions {NoCache : true },
332337 })
333338 if err != nil {
@@ -360,7 +365,7 @@ func BuildFromConfig(config *container.Config, changes []string, os string) (*co
360365 dispatchRequest .state .imageID = config .Image
361366 dispatchRequest .state .operatingSystem = os
362367 for _ , cmd := range commands {
363- err := dispatch (dispatchRequest , cmd )
368+ err := dispatch (ctx , dispatchRequest , cmd )
364369 if err != nil {
365370 return nil , errdefs .InvalidParameter (err )
366371 }
0 commit comments