build: fix stdin handling when building with controller

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2024-04-09 14:35:58 +02:00
parent 0a3e5e5257
commit ffff87be03
No known key found for this signature in database
GPG Key ID: ADE44D8C9D44FBE4
2 changed files with 23 additions and 18 deletions

View File

@ -418,14 +418,22 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro
var ref string var ref string
var retErr error var retErr error
var resp *client.SolveResponse var resp *client.SolveResponse
f := ioset.NewSingleForwarder()
f.SetReader(dockerCli.In()) var f *ioset.SingleForwarder
pr, pw := io.Pipe() var pr io.ReadCloser
f.SetWriter(pw, func() io.WriteCloser { var pw io.WriteCloser
pw.Close() // propagate EOF if options.invokeConfig == nil {
logrus.Debug("propagating stdin close") pr = dockerCli.In()
return nil } else {
}) f = ioset.NewSingleForwarder()
f.SetReader(dockerCli.In())
pr, pw = io.Pipe()
f.SetWriter(pw, func() io.WriteCloser {
pw.Close() // propagate EOF
logrus.Debug("propagating stdin close")
return nil
})
}
ref, resp, err = c.Build(ctx, *opts, pr, printer) ref, resp, err = c.Build(ctx, *opts, pr, printer)
if err != nil { if err != nil {
@ -439,11 +447,13 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro
} }
} }
if err := pw.Close(); err != nil { if options.invokeConfig != nil {
logrus.Debug("failed to close stdin pipe writer") if err := pw.Close(); err != nil {
} logrus.Debug("failed to close stdin pipe writer")
if err := pr.Close(); err != nil { }
logrus.Debug("failed to close stdin pipe reader") if err := pr.Close(); err != nil {
logrus.Debug("failed to close stdin pipe reader")
}
} }
if options.invokeConfig != nil && options.invokeConfig.needsDebug(retErr) { if options.invokeConfig != nil && options.invokeConfig.needsDebug(retErr) {

View File

@ -69,11 +69,6 @@ func testBuild(t *testing.T, sb integration.Sandbox) {
} }
func testBuildStdin(t *testing.T, sb integration.Sandbox) { func testBuildStdin(t *testing.T, sb integration.Sandbox) {
if isExperimental() {
// FIXME: https://github.com/docker/buildx/issues/2368
t.Skip("build from stdin hangs in experimental mode: https://github.com/docker/buildx/issues/2368")
}
dockerfile := []byte(` dockerfile := []byte(`
FROM busybox:latest AS base FROM busybox:latest AS base
COPY foo /etc/foo COPY foo /etc/foo