From 1095d5e5e43654aa27952f131b71c55f18fedc4b Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Wed, 4 Feb 2015 15:37:14 -0800 Subject: [PATCH] Change verbose builder out back to attach This is sort of "revert" of #8415. There is some problems with using logs: * Non-live progressbars * Races when you can try to get logs before it was written(there was occasional errors in tests) Signed-off-by: Alexander Morozov --- builder/internals.go | 17 +++++++---------- daemon/attach.go | 4 ++-- daemon/exec.go | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/builder/internals.go b/builder/internals.go index ddbef108a0..d966f55c71 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -545,21 +545,18 @@ func (b *Builder) create() (*daemon.Container, error) { } func (b *Builder) run(c *daemon.Container) error { + var errCh chan error + if b.Verbose { + errCh = b.Daemon.Attach(&c.StreamConfig, c.Config.OpenStdin, c.Config.StdinOnce, c.Config.Tty, nil, b.OutStream, b.ErrStream) + } + //start the container if err := c.Start(); err != nil { return err } - if b.Verbose { - logsJob := b.Engine.Job("logs", c.ID) - logsJob.Setenv("follow", "1") - logsJob.Setenv("stdout", "1") - logsJob.Setenv("stderr", "1") - logsJob.Stdout.Add(b.OutStream) - logsJob.Stderr.Set(b.ErrStream) - if err := logsJob.Run(); err != nil { - return err - } + if err := <-errCh; err != nil { + return err } // Wait for it to finish diff --git a/daemon/attach.go b/daemon/attach.go index 881b021e17..0571612530 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -101,7 +101,7 @@ func (daemon *Daemon) ContainerAttach(job *engine.Job) engine.Status { cStderr = job.Stderr } - <-daemon.attach(&container.StreamConfig, container.Config.OpenStdin, container.Config.StdinOnce, container.Config.Tty, cStdin, cStdout, cStderr) + <-daemon.Attach(&container.StreamConfig, container.Config.OpenStdin, container.Config.StdinOnce, container.Config.Tty, cStdin, cStdout, cStderr) // If we are in stdinonce mode, wait for the process to end // otherwise, simply return if container.Config.StdinOnce && !container.Config.Tty { @@ -111,7 +111,7 @@ func (daemon *Daemon) ContainerAttach(job *engine.Job) engine.Status { return engine.StatusOK } -func (daemon *Daemon) attach(streamConfig *StreamConfig, openStdin, stdinOnce, tty bool, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) chan error { +func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, tty bool, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) chan error { var ( cStdout, cStderr io.ReadCloser cStdin io.WriteCloser diff --git a/daemon/exec.go b/daemon/exec.go index 8bb4e72d13..e35b96d67d 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -219,7 +219,7 @@ func (d *Daemon) ContainerExecStart(job *engine.Job) engine.Status { execConfig.StreamConfig.stdinPipe = ioutils.NopWriteCloser(ioutil.Discard) // Silently drop stdin } - attachErr := d.attach(&execConfig.StreamConfig, execConfig.OpenStdin, true, execConfig.ProcessConfig.Tty, cStdin, cStdout, cStderr) + attachErr := d.Attach(&execConfig.StreamConfig, execConfig.OpenStdin, true, execConfig.ProcessConfig.Tty, cStdin, cStdout, cStderr) execErr := make(chan error)