1
0
mirror of https://github.com/docker/compose.git synced 2025-04-08 17:05:13 +02:00

capture error message reported by bake and forward to compose

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-01-30 11:36:25 +01:00 committed by Guillaume Lours
parent 8d68ef587f
commit f14c15fa57
2 changed files with 15 additions and 8 deletions

@ -17,12 +17,12 @@
package compose
import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
@ -272,18 +272,23 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
return nil, err
}
var errMessage string
scanner := bufio.NewScanner(pipe)
scanner.Split(bufio.ScanLines)
err = cmd.Start()
if err != nil {
return nil, err
}
eg.Go(cmd.Wait)
for {
decoder := json.NewDecoder(pipe)
for scanner.Scan() {
line := scanner.Text()
decoder := json.NewDecoder(strings.NewReader(line))
var status client.SolveStatus
err := decoder.Decode(&status)
if err != nil {
if errors.Is(err, io.EOF) {
break
if strings.HasPrefix(line, "ERROR: ") {
errMessage = line[7:]
}
continue
}
@ -293,7 +298,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
err = eg.Wait()
if err != nil {
return nil, err
if errMessage != "" {
return nil, errors.New(errMessage)
}
return nil, fmt.Errorf("failed to execute bake: %w", err)
}
b, err = os.ReadFile(metadata.Name())

@ -403,8 +403,7 @@ func TestBuildPlatformsStandardErrors(t *testing.T) {
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "build")
res.Assert(t, icmd.Expected{
ExitCode: 1,
Err: `Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.`,
Err: "Multi-platform build is not supported for the docker driver.",
})
})