浏览代码

Merge pull request #2341 from dotcloud/1327-race_build_verbose-fix

fix race condition in docker build with verbose + cleanup hostIntegration debug
Victor Vieux 11 年之前
父节点
当前提交
8ff7b70c91
共有 2 个文件被更改,包括 15 次插入7 次删除
  1. 10 3
      buildfile.go
  2. 5 4
      container.go

+ 10 - 3
buildfile.go

@@ -378,15 +378,22 @@ func (b *buildFile) run() (string, error) {
 	c.Path = b.config.Cmd[0]
 	c.Args = b.config.Cmd[1:]
 
+	var errCh chan error
+
+	if b.verbose {
+		errCh = utils.Go(func() error {
+			return <-c.Attach(nil, nil, b.out, b.out)
+		})
+	}
+
 	//start the container
 	hostConfig := &HostConfig{}
 	if err := c.Start(hostConfig); err != nil {
 		return "", err
 	}
 
-	if b.verbose {
-		err = <-c.Attach(nil, nil, b.out, b.out)
-		if err != nil {
+	if errCh != nil {
+		if err := <-errCh; err != nil {
 			return "", err
 		}
 	}

+ 5 - 4
container.go

@@ -1,6 +1,7 @@
 package docker
 
 import (
+	"bytes"
 	"encoding/json"
 	"errors"
 	"flag"
@@ -847,15 +848,15 @@ func (container *Container) Start(hostConfig *HostConfig) (err error) {
 	// Note: The container can run and finish correctly before
 	//       the end of this loop
 	for now := time.Now(); time.Since(now) < 5*time.Second; {
-		// If the container dies while waiting for it, just reutrn
+		// If the container dies while waiting for it, just return
 		if !container.State.Running {
 			return nil
 		}
-		output, err := exec.Command("lxc-info", "-n", container.ID).CombinedOutput()
+		output, err := exec.Command("lxc-info", "-s", "-n", container.ID).CombinedOutput()
 		if err != nil {
 			utils.Debugf("Error with lxc-info: %s (%s)", err, output)
 
-			output, err = exec.Command("lxc-info", "-n", container.ID).CombinedOutput()
+			output, err = exec.Command("lxc-info", "-s", "-n", container.ID).CombinedOutput()
 			if err != nil {
 				utils.Debugf("Second Error with lxc-info: %s (%s)", err, output)
 				return err
@@ -865,7 +866,7 @@ func (container *Container) Start(hostConfig *HostConfig) (err error) {
 		if strings.Contains(string(output), "RUNNING") {
 			return nil
 		}
-		utils.Debugf("Waiting for the container to start (running: %v): %s\n", container.State.Running, output)
+		utils.Debugf("Waiting for the container to start (running: %v): %s", container.State.Running, bytes.TrimSpace(output))
 		time.Sleep(50 * time.Millisecond)
 	}