From ffff87be0375874dd1009df5ff4390dc1f22b7a7 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 9 Apr 2024 14:35:58 +0200 Subject: [PATCH] build: fix stdin handling when building with controller Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- commands/build.go | 36 +++++++++++++++++++++++------------- tests/build.go | 5 ----- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/commands/build.go b/commands/build.go index 36154599..2b7aaaa5 100644 --- a/commands/build.go +++ b/commands/build.go @@ -418,14 +418,22 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro var ref string var retErr error var resp *client.SolveResponse - 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 - }) + + var f *ioset.SingleForwarder + var pr io.ReadCloser + var pw io.WriteCloser + if options.invokeConfig == nil { + pr = dockerCli.In() + } 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) if err != nil { @@ -439,11 +447,13 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro } } - 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 options.invokeConfig != nil { + 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 options.invokeConfig != nil && options.invokeConfig.needsDebug(retErr) { diff --git a/tests/build.go b/tests/build.go index da790fc1..fd4562a1 100644 --- a/tests/build.go +++ b/tests/build.go @@ -69,11 +69,6 @@ func testBuild(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(` FROM busybox:latest AS base COPY foo /etc/foo