mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use logs instead of attach for builder
Signed-off-by: Alexandr Morozov <lk4d4@docker.com>
This commit is contained in:
parent
04932e38af
commit
6f09d064bd
2 changed files with 27 additions and 15 deletions
|
@ -24,7 +24,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/log"
|
"github.com/docker/docker/pkg/log"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
"github.com/docker/docker/pkg/promise"
|
|
||||||
"github.com/docker/docker/pkg/symlink"
|
"github.com/docker/docker/pkg/symlink"
|
||||||
"github.com/docker/docker/pkg/system"
|
"github.com/docker/docker/pkg/system"
|
||||||
"github.com/docker/docker/pkg/tarsum"
|
"github.com/docker/docker/pkg/tarsum"
|
||||||
|
@ -512,25 +511,19 @@ func (b *Builder) create() (*daemon.Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) run(c *daemon.Container) error {
|
func (b *Builder) run(c *daemon.Container) error {
|
||||||
var errCh chan error
|
|
||||||
if b.Verbose {
|
|
||||||
errCh = promise.Go(func() error {
|
|
||||||
// FIXME: call the 'attach' job so that daemon.Attach can be made private
|
|
||||||
//
|
|
||||||
// FIXME (LK4D4): Also, maybe makes sense to call "logs" job, it is like attach
|
|
||||||
// but without hijacking for stdin. Also, with attach there can be race
|
|
||||||
// condition because of some output already was printed before it.
|
|
||||||
return <-b.Daemon.Attach(&c.StreamConfig, c.Config.OpenStdin, c.Config.StdinOnce, c.Config.Tty, nil, nil, b.OutStream, b.ErrStream)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
if err := c.Start(); err != nil {
|
if err := c.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if errCh != nil {
|
if b.Verbose {
|
||||||
if err := <-errCh; err != nil {
|
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.Add(b.ErrStream)
|
||||||
|
if err := logsJob.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2752,3 +2752,22 @@ func TestBuildVerifySingleQuoteFails(t *testing.T) {
|
||||||
|
|
||||||
logDone("build - verify single quotes fail")
|
logDone("build - verify single quotes fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildVerboseOut(t *testing.T) {
|
||||||
|
name := "testbuildverboseout"
|
||||||
|
defer deleteImages(name)
|
||||||
|
|
||||||
|
_, out, err := buildImageWithOut(name,
|
||||||
|
`FROM busybox
|
||||||
|
RUN echo 123`,
|
||||||
|
false)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, "\n123\n") {
|
||||||
|
t.Fatalf("Output should contain %q: %q", "123", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("build - verbose output from commands")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue