Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the quiet flag behavior in the build command [closes #17623] #17428

Merged
merged 1 commit into from Dec 21, 2015
Merged

Change the quiet flag behavior in the build command [closes #17623] #17428

merged 1 commit into from Dec 21, 2015

Conversation

boaz0
Copy link
Member

@boaz0 boaz0 commented Oct 28, 2015

This PR answers the requirement in #7727 and closes #17623

Closes #17623

Right now, the quiet (-q, --quiet) flag ignores the output
generated from within the container.

However, it ought to be a quiet in a way that all kind
of diagnostic output should be ignored, unless the build
process fails.

This patch makes the quiet flag behave in the following way:
1. If the build process succeeds, stdout contains the image ID
and stderr is empty.
2. If the build process fails, stdout is empty and stderr
has the error message and the diagnostic output of that process.

If the quiet flag is not set, then everything goes to stdout
and error messages, if there are any, go to stderr.

TODO:

  • Change the quiet part in the docker build docs
  • Write a cli-integration test
  • Apparently figure out why the tests fail

@GordonTheTurtle GordonTheTurtle added status/0-triage dco/no Automatically set by a bot when one of the commits lacks proper signature and removed dco/no Automatically set by a bot when one of the commits lacks proper signature labels Oct 28, 2015
@boaz0
Copy link
Member Author

boaz0 commented Oct 28, 2015

Ummm... strange, I don't know why it fails. I'll take a look on it, when I get back from work.
/cc @vieux @tiborvass @duglin - may you shed some light what I did wrong? Thanks 😀

@boaz0
Copy link
Member Author

boaz0 commented Oct 29, 2015

In the console text, this is the failure message I receive:

FAIL: docker_cli_run_test.go:2163: DockerSuite.TestRunVolumesCleanPaths

docker_cli_run_test.go:2188:
c.Fatalf("Volume was not defined for %s/foo\n%q", prefix, out)
... Error: Volume was not defined for /foo
"/var/lib/docker/volumes/eae1f91f83a0117bf546f30f515eae4c92945565aed814652a7aa8174cfa9208/_data"

However, from what I see the DockerSuite.TestRunVolumesCleanPaths test isn't related to the docker build command and thus to my changes.

Am I right? If so, @vdemeester @cpuguy83 can you please restart the Jenkins windows testing job again? Thanks a bunch. 😄

@cpuguy83
Copy link
Member

Correct

@duglin
Copy link
Contributor

duglin commented Nov 2, 2015

Couple of things...
1 - doing a strcmp is a bit worrying since its possible (although unlikely) that the string we look for might appear more than once in the output.
2 - this will only get the docker cli flow, not the REST APIs

Have you considering doing this on the daemon side? Then the only output we'd see on the wire would be the resulting image id, for both the docker cli and REST APIs.

@boaz0
Copy link
Member Author

boaz0 commented Nov 2, 2015

@duglin, thanks for your feedback.
1 - I agree.
2 - I thought of doing this, but I have had a feeling I would have to change the behavior in more than one place. Therefore, I decided to implement this in the client side.

Let me figure out a way to implement that on the daemon side, though. Otherwise, I will get rid of the strcmp-way.

Thanks.

@GordonTheTurtle GordonTheTurtle added dco/no Automatically set by a bot when one of the commits lacks proper signature and removed dco/no Automatically set by a bot when one of the commits lacks proper signature labels Nov 11, 2015
@boaz0
Copy link
Member Author

boaz0 commented Nov 11, 2015

@duglin -- I tried my best here 😄.
Can you give me another code review?

I am not that satisfied with the implementation, though.

@thaJeztah
Copy link
Member

@ripcurld00d can you add "closes #17623" to the top description?

@boaz0 boaz0 changed the title Add the stream-off flag to the client Add the script-mode flag to the client [closes #17623] Nov 15, 2015
@boaz0
Copy link
Member Author

boaz0 commented Nov 15, 2015

@thaJeztah affirmative ;)

@duglin
Copy link
Contributor

duglin commented Nov 15, 2015

First, great name for a branch :-)

I think you may need to tweak the logic when there's an error. Right now if the build fails we'll get the error message but that's it - we only see the error message and not anything else. I think when there's an error you should send the entire buffer along with it. Without that extra text it might be really hard for people to know which line of the Dockerfile caused the issue. Granted we could try to be really smart and only return the last few lines, but I think that's probably overkill and when things go wrong I'd prefer to give as much info as possible to help the user fix it - and for all we know, the true issue could be back on the first step of the Dockerfile. They shouldn't have to rerun again (w/o this flag) just to get the info they need to debug.

I'm not fond of the phrase "script-mode", it feels a bit too focused on one particular usecase. What about just -s and --silent ?

outBuf = cli.out
} else {
// First check whether the Docker daemon supports this feature.
serverResp, err := cli.call("GET", "/version", nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand why you're doing this, I'm not sure its worth it or consistent with the rest of Docker. I can't think of any other check like this for other new flags. In general, there's no guarantee that newer CLIs will ever work with old servers w.r.t. new features, so its not worth adding this check. Unless other @docker/maintainers want to start to add this check for other flags we may have added recently (and going forward).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duglin, no problem. I will remove it. Although, I will propose this check later.

@boaz0
Copy link
Member Author

boaz0 commented Nov 16, 2015

@duglin thanks again for your feedback. I will work on it and do as you suggest.

Thanks.

@duglin
Copy link
Contributor

duglin commented Nov 23, 2015

Hi @ripcurld00d - any update on this? Looks like a rebase is needed too.

@boaz0
Copy link
Member Author

boaz0 commented Nov 23, 2015

Yeah, I have already done git pull --rebase and still working on it. This week I will push a new update. Be watching 😜

cc @duglin

@boaz0 boaz0 changed the title Add the script-mode flag to the client [closes #17623] Add the silent flag to the client [closes #17623] Nov 23, 2015
@boaz0
Copy link
Member Author

boaz0 commented Nov 23, 2015

@duglin - I have done my part. Your feedback, please 🙏 😄
Thanks a lot!

@boxofrox thoughts?

@@ -54,3 +57,75 @@ func ParseServerHeader(hdr string) (*ServerHeader, error) {
OS: strings.TrimSpace(matches[3]),
}, nil
}

// Version represents the Docker version
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I will remove these changes, since we're not making any version-check.

@boxofrox
Copy link

Looks like this will work from the shell like so.

if docker build -st super-cool-project:latest . 2>/dev/null | read IMAGE_ID; then
  docker tag $IMAGE_ID super-cool-project:1.0
fi

I'm happy with that.

@stevvooe
Copy link
Contributor

This functionality is provided by "-q" across other commands. Why the departure from that convention?

@duglin
Copy link
Contributor

duglin commented Nov 25, 2015

@stevvooe because build already has a "-q" option and its not "quite" enough

@boaz0
Copy link
Member Author

boaz0 commented Dec 19, 2015

for heaven sake! when does it end?... i have to re-write another component again... 😭

@thaJeztah
Copy link
Member

sorry @ripcurld00d, let's try to get this merged asap

I noticed build is failing currently;

---> Making bundle: .ensure-httpserver (in bundles/1.10.0-dev/test-integration-cli)
+ go test -test.timeout=120m -check.v github.com/docker/docker/integration-cli
# github.com/docker/docker/integration-cli
./docker_cli_build_test.go:4963: te.StdoutRegexp undefined (type struct { TestName string; BuildCmdsOrURL string } has no field or method StdoutRegexp)
./docker_cli_build_test.go:4971: no new variables on left side of :=
./docker_cli_build_test.go:4971: cannot use []struct { TestName string; BuildCmds string } literal (type []struct { TestName string; BuildCmds string }) as type []struct { TestName string; BuildCmdsOrURL string } in assignment
./docker_cli_build_test.go:4981: te.BuildCmds undefined (type struct { TestName string; BuildCmdsOrURL string } has no field or method BuildCmds)
./docker_cli_build_test.go:4982: te.BuildCmds undefined (type struct { TestName string; BuildCmdsOrURL string } has no field or method BuildCmds)
FAIL    github.com/docker/docker/integration-cli [build failed]

@boaz0
Copy link
Member Author

boaz0 commented Dec 19, 2015

@thaJeztah not giving up yet! ✊

@thaJeztah
Copy link
Member

🤘 sorry it's a really bad time with rebases. we're re-organizing loads of things and moving some packages to separate repositories. I really hope we'll be able to get this merged asap

@boaz0
Copy link
Member Author

boaz0 commented Dec 20, 2015

🏇 let the game begin...
@duglin -- review the code at your free time... :godmode:

@boaz0
Copy link
Member Author

boaz0 commented Dec 20, 2015

grrr windows fails again:

FAIL: docker_cli_build_test.go:1874: DockerSuite.TestBuildCancellationKillsSleep

docker_cli_build_test.go:1945:
c.Fatal("failed to observe build container start in timely fashion")
... Error: failed to observe build container start in timely fashion
[....]
FAIL: docker_cli_events_test.go:217: DockerSuite.TestEventsImageImport

docker_cli_events_test.go:254:
c.Fatal("failed to observe image import in timely fashion")
... Error: failed to observe image import in timely fashion

those aren't related to my changes... 😞

}
}

func (s *DockerSuite) TestBuildNotVerboseFailureRemote(c *check.C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the 4 variants at https://github.com/docker/docker/pull/17428/files#diff-3a1632a75e011091e0bae6f8c8435fd2L93 can we add a test for when the URL points to a github repo and for when the Dockerfile comes from stdin ?

Aside from that I think this is ready to go!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duglin w/o using FakeGit? like giving a real github repo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would using FakeGit be bad for the happy-path case? Could use a bogus git repo URL for the failure case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duglin why using git repo or stdin in the happy-path case? we know it generates an image ID. I thought that it would be useful for the sad-path case, to confirm that the output is similar to when the verbose mode is uesd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that since we have four different code paths we might run into four different ways that output could be sent to the screen, and we should make sure -q caught all 4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duglin uh huh. I see. OK. Let me figure out how to do a test with stdin, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duglin looking at the integration-cli/docker_utils.go, we are already passing the "Dockerfile" through stdin.

Therefore, I am going to add the FakeGit and the FakeContext methods.

@ewindisch
Copy link
Contributor

If there is an error, is the exit status set to non-zero? It's not clear on a read-through if this is true (I'd have to dig through the cli package more perhaps to figure this out).

Otherwise looks good.

@duglin
Copy link
Contributor

duglin commented Dec 20, 2015

@ewindisch yes it does, that part hasn't changed.

@boaz0
Copy link
Member Author

boaz0 commented Dec 21, 2015

@duglin done!

EDIT: docker-ps' unit-tests failed. After looking at it, it seems unrelated to my changes. -- #18820 resolves it.

@boaz0
Copy link
Member Author

boaz0 commented Dec 21, 2015

@thaJeztah can you restart experimental, janky and windows tests, pllz? thanks 🍧

@thaJeztah
Copy link
Member

@ripcurld00d done! did you rebase, to get the fix #18820 in?

Right now, the quiet (-q, --quiet) flag ignores the output
generated from within the container.

However, it ought to be quiet in a way that all kind
of diagnostic output should be ignored, unless the build
process fails.

This patch makes the quiet flag behave in the following way:
 1. If the build process succeeds, stdout contains the image ID
    and stderr is empty.
 2. If the build process fails, stdout is empty and stderr
    has the error message and the diagnostic output of that process.

If the quiet flag is not set, then everything goes to stdout
and error messages, if there are any, go to stderr.

Signed-off-by: Boaz Shuster <ripcurld.github@gmail.com>
@boaz0
Copy link
Member Author

boaz0 commented Dec 21, 2015

Now I did 😊

@duglin
Copy link
Contributor

duglin commented Dec 21, 2015

LGTM
thanks for the hard work/patience!

@duglin
Copy link
Contributor

duglin commented Dec 21, 2015

ping @cpuguy83 @tiborvass

@vdemeester
Copy link
Member

LGTM 😉

@thaJeztah
Copy link
Member

Alright!! Looks like we have 2 LGTM's on code, and docs didn't change and already had 2 LGTM's. In my world that means merge 🎉 💃

thaJeztah added a commit that referenced this pull request Dec 21, 2015
Change the quiet flag behavior in the build command [closes #17623]
@thaJeztah thaJeztah merged commit f4ea3b2 into moby:master Dec 21, 2015
@thaJeztah
Copy link
Member

Thanks so much @ripcurld00d!

I added impact/changelog; although it can be seen as a bug fix, this flag was currently not really useful, now that it is, I think it's nice to inform people that they can use it again 😄

@boaz0
Copy link
Member Author

boaz0 commented Dec 21, 2015

👯 💃 OMG OMG OMG OMG 🎉 🎈 👏
I got merged!!!
Thank you all!!! @vdemeester @duglin @thaJeztah @moxiegirl @tiborvass @boxofrox
I couldn't do it w/o you guys. Kudos! 👍

@thaJeztah
Copy link
Member

group hug

@jessfraz
Copy link
Contributor

@vdemeester
Copy link
Member

🎉

@boxofrox
Copy link

Congrats @ripcurld00d and thank you for all the work you put into this. I'm looking forward to using this in my shell scripts. My appreciation goes out to the docker team, too. You're doing a great job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: docker-build flag that displays only the image ID