mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 10:03:42 +08:00 
			
		
		
		
	Merge pull request #2394 from crazy-max/fix-stdin-controller
build: fix stdin handling when building with controller
This commit is contained in:
		@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user