Skip to content

Commit

Permalink
build: fix stdin handling when building with controller
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Apr 9, 2024
1 parent 0a3e5e5 commit ffff87b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
36 changes: 23 additions & 13 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions tests/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffff87b

Please sign in to comment.