Right now 'docker build' will send:
Sending build context to Docker daemon
to stderr, instead of stdout. This PR fixes that.
I looked in the rest of api/client/commands.go for other cases
that might do this and only one jumped out at me:
https://github.com/docker/docker/blob/master/api/client/commands.go#L2202
but I think if I changed that to go to stdout then it'll mess people up
who are expecting just the container ID to be printed to the screen and
there is no --quiet type of flag we can check.
Closes #9404
Signed-off-by: Doug Davis <dug@us.ibm.com>
| ... | ... |
@@ -180,7 +180,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
| 180 | 180 |
// FIXME: ProgressReader shouldn't be this annoying to use |
| 181 | 181 |
if context != nil {
|
| 182 | 182 |
sf := utils.NewStreamFormatter(false) |
| 183 |
- body = utils.ProgressReader(context, 0, cli.err, sf, true, "", "Sending build context to Docker daemon") |
|
| 183 |
+ body = utils.ProgressReader(context, 0, cli.out, sf, true, "", "Sending build context to Docker daemon") |
|
| 184 | 184 |
} |
| 185 | 185 |
// Send the build context |
| 186 | 186 |
v := &url.Values{}
|
| ... | ... |
@@ -3523,3 +3523,19 @@ func TestBuildWithTabs(t *testing.T) {
|
| 3523 | 3523 |
} |
| 3524 | 3524 |
logDone("build - with tabs")
|
| 3525 | 3525 |
} |
| 3526 |
+ |
|
| 3527 |
+func TestBuildStderr(t *testing.T) {
|
|
| 3528 |
+ // This test just makes sure that no non-error output goes |
|
| 3529 |
+ // to stderr |
|
| 3530 |
+ name := "testbuildstderr" |
|
| 3531 |
+ defer deleteImages(name) |
|
| 3532 |
+ _, _, stderr, err := buildImageWithStdoutStderr(name, |
|
| 3533 |
+ "FROM busybox\nRUN echo one", true) |
|
| 3534 |
+ if err != nil {
|
|
| 3535 |
+ t.Fatal(err) |
|
| 3536 |
+ } |
|
| 3537 |
+ if stderr != "" {
|
|
| 3538 |
+ t.Fatal("Stderr should have been empty, instead its: %q", stderr)
|
|
| 3539 |
+ } |
|
| 3540 |
+ logDone("build - testing stderr")
|
|
| 3541 |
+} |
| ... | ... |
@@ -596,6 +596,25 @@ func buildImageWithOut(name, dockerfile string, useCache bool) (string, string, |
| 596 | 596 |
return id, out, nil |
| 597 | 597 |
} |
| 598 | 598 |
|
| 599 |
+func buildImageWithStdoutStderr(name, dockerfile string, useCache bool) (string, string, string, error) {
|
|
| 600 |
+ args := []string{"build", "-t", name}
|
|
| 601 |
+ if !useCache {
|
|
| 602 |
+ args = append(args, "--no-cache") |
|
| 603 |
+ } |
|
| 604 |
+ args = append(args, "-") |
|
| 605 |
+ buildCmd := exec.Command(dockerBinary, args...) |
|
| 606 |
+ buildCmd.Stdin = strings.NewReader(dockerfile) |
|
| 607 |
+ stdout, stderr, exitCode, err := runCommandWithStdoutStderr(buildCmd) |
|
| 608 |
+ if err != nil || exitCode != 0 {
|
|
| 609 |
+ return "", stdout, stderr, fmt.Errorf("failed to build the image: %s", stdout)
|
|
| 610 |
+ } |
|
| 611 |
+ id, err := getIDByName(name) |
|
| 612 |
+ if err != nil {
|
|
| 613 |
+ return "", stdout, stderr, err |
|
| 614 |
+ } |
|
| 615 |
+ return id, stdout, stderr, nil |
|
| 616 |
+} |
|
| 617 |
+ |
|
| 599 | 618 |
func buildImage(name, dockerfile string, useCache bool) (string, error) {
|
| 600 | 619 |
id, _, err := buildImageWithOut(name, dockerfile, useCache) |
| 601 | 620 |
return id, err |