From 96703b69812ac9bcd61c00fe58e4304613cf24bc Mon Sep 17 00:00:00 2001 From: yangfeiyu Date: Wed, 3 Dec 2025 21:45:23 +0800 Subject: [PATCH] check buildx version before comparing it Signed-off-by: yangfeiyu --- pkg/compose/build_bake.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/compose/build_bake.go b/pkg/compose/build_bake.go index 0bdfc5cfffb..da7c12256d7 100644 --- a/pkg/compose/build_bake.go +++ b/pkg/compose/build_bake.go @@ -289,15 +289,11 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project _ = os.Remove(metadataFile) }() - buildx, err := manager.GetPlugin("buildx", s.dockerCli, &cobra.Command{}) + buildx, err := s.getBuildxPlugin() if err != nil { return nil, err } - if versions.LessThan(buildx.Version[1:], "0.17.0") { - return nil, fmt.Errorf("compose build requires buildx 0.17 or later") - } - args := []string{"bake", "--file", "-", "--progress", "rawjson", "--metadata-file", metadataFile} // FIXME we should prompt user about this, but this is a breaking change in UX for _, path := range read { @@ -414,6 +410,27 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project return results, nil } +func (s *composeService) getBuildxPlugin() (*manager.Plugin, error) { + buildx, err := manager.GetPlugin("buildx", s.dockerCli, &cobra.Command{}) + if err != nil { + return nil, err + } + + if buildx.Err != nil { + return nil, buildx.Err + } + + if buildx.Version == "" { + return nil, fmt.Errorf("failed to get version of buildx") + } + + if versions.LessThan(buildx.Version[1:], "0.17.0") { + return nil, fmt.Errorf("compose build requires buildx 0.17 or later") + } + + return buildx, nil +} + // makeConsole wraps the provided writer to match [containerd.File] interface if it is of type *streams.Out. // buildkit's NewDisplay doesn't actually require a [io.Reader], it only uses the [containerd.Console] type to // benefits from ANSI capabilities, but only does writes.