mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +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:
parent
8d68ef587f
commit
f14c15fa57
@ -17,12 +17,12 @@
|
|||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -272,18 +272,23 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errMessage string
|
||||||
|
scanner := bufio.NewScanner(pipe)
|
||||||
|
scanner.Split(bufio.ScanLines)
|
||||||
|
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eg.Go(cmd.Wait)
|
eg.Go(cmd.Wait)
|
||||||
for {
|
for scanner.Scan() {
|
||||||
decoder := json.NewDecoder(pipe)
|
line := scanner.Text()
|
||||||
|
decoder := json.NewDecoder(strings.NewReader(line))
|
||||||
var status client.SolveStatus
|
var status client.SolveStatus
|
||||||
err := decoder.Decode(&status)
|
err := decoder.Decode(&status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, io.EOF) {
|
if strings.HasPrefix(line, "ERROR: ") {
|
||||||
break
|
errMessage = line[7:]
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -293,7 +298,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
|
|||||||
|
|
||||||
err = eg.Wait()
|
err = eg.Wait()
|
||||||
if err != nil {
|
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())
|
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 := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "build")
|
||||||
res.Assert(t, icmd.Expected{
|
res.Assert(t, icmd.Expected{
|
||||||
ExitCode: 1,
|
ExitCode: 1,
|
||||||
Err: `Multi-platform build is not supported for the docker driver.
|
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.`,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user