@@ -289,15 +289,11 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
289289 _ = os .Remove (metadataFile )
290290 }()
291291
292- buildx , err := manager . GetPlugin ( "buildx" , s . dockerCli , & cobra. Command {} )
292+ buildx , err := s . getBuildxPlugin ( )
293293 if err != nil {
294294 return nil , err
295295 }
296296
297- if versions .LessThan (buildx .Version [1 :], "0.17.0" ) {
298- return nil , fmt .Errorf ("compose build requires buildx 0.17 or later" )
299- }
300-
301297 args := []string {"bake" , "--file" , "-" , "--progress" , "rawjson" , "--metadata-file" , metadataFile }
302298 // FIXME we should prompt user about this, but this is a breaking change in UX
303299 for _ , path := range read {
@@ -414,6 +410,27 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
414410 return results , nil
415411}
416412
413+ func (s * composeService ) getBuildxPlugin () (* manager.Plugin , error ) {
414+ buildx , err := manager .GetPlugin ("buildx" , s .dockerCli , & cobra.Command {})
415+ if err != nil {
416+ return nil , err
417+ }
418+
419+ if buildx .Err != nil {
420+ return nil , buildx .Err
421+ }
422+
423+ if buildx .Version == "" {
424+ return nil , fmt .Errorf ("failed to get version of buildx" )
425+ }
426+
427+ if versions .LessThan (buildx .Version [1 :], "0.17.0" ) {
428+ return nil , fmt .Errorf ("compose build requires buildx 0.17 or later" )
429+ }
430+
431+ return buildx , nil
432+ }
433+
417434// makeConsole wraps the provided writer to match [containerd.File] interface if it is of type *streams.Out.
418435// buildkit's NewDisplay doesn't actually require a [io.Reader], it only uses the [containerd.Console] type to
419436// benefits from ANSI capabilities, but only does writes.
0 commit comments