Skip to content

Api client lib#18472

Merged
tiborvass merged 53 commits intomoby:masterfrom
calavera:api_client_lib
Dec 9, 2015
Merged

Api client lib#18472
tiborvass merged 53 commits intomoby:masterfrom
calavera:api_client_lib

Conversation

@calavera
Copy link
Contributor

@calavera calavera commented Dec 7, 2015

⚠️ Too big to review, go to my fork and navigate the api/client package ⚠️

I extracted a standalone client library from the cli that can be used outside of docker. In the process of doing that I end up removing a bunch of code from the cli.

Why do you do this to us??!!

We should own the main go library to interact with docker. This makes the docker cli be the first consumer of this library.

How did you do this??!

I extracted all the calls the client needs into an interface, you can see it here:
https://github.com/calavera/docker/blob/api_client_lib/api/client/client.go#L19

Functions are very well defined but there are a couple things to consider.

I removed cli.stream and cli.hijack entirely.

After reading every single line in the client, I believe nobody knows how those two functions work and they made our code very complicated. You can compare the start command, no need for a diff:

Master: https://github.com/docker/docker/blob/master/api/client/start.go
My branch: https://github.com/calavera/docker/blob/api_client_lib/api/client/start.go

Every response in the new library that can be streamed returns an io.ReadCloser. It's up to the caller to implement streaming. This makes the intention of the caller much more clear. Compare the image create functions:

Master: https://github.com/docker/docker/blob/master/api/client/create.go#L53-L70
My branch: https://github.com/calavera/docker/blob/api_client_lib/api/client/create.go#L51-L63

did you know that the response of that function was always a json message that we stream in the client?

Breaking changes

Of course there are always consequences. I introduced what can be considered as a breaking change. In my opinion, the new behavior is more correct 😸

Until now, docker inspect continued evaluating containers if you typed a wrong id, see this example:

$ docker run -d --name test alpine true
$ docker inspect this_container_does_not_exist test

The message about this_container_does_not_exist not existing would be followed by the test container output, a json payload of about 100 lines. This makes almost impossible to see the error.

With the new behavior, the cli stops execution as soon as it finds an error. This is a more predictable behavior. Users know sooner and more clear that there is a problem with the command they just executed.

The code in inspect has also been highly simplified. Compare both files:

Master: https://github.com/docker/docker/blob/master/api/client/inspect.go
My branch: https://github.com/calavera/docker/blob/api_client_lib/api/client/inspect.go
https://github.com/calavera/docker/blob/api_client_lib/api/client/inspect/inspector.go

This is impossible to review

I'm afraid so too. I tried very hard to keep changes very well defined. But the best way to review this change might be to browse my branch directly, and to play with the cli.

The new client library is in https://github.com/calavera/docker/blob/api_client_lib/api/client/lib

@LK4D4
Copy link
Contributor

LK4D4 commented Dec 7, 2015

I think probably inspect should fail if any of containers doesn't exist :)

@icecrime
Copy link
Contributor

icecrime commented Dec 7, 2015

Oh my 😍 That looks pretty impressive!

@LK4D4
Copy link
Contributor

LK4D4 commented Dec 7, 2015

Everything failed 🎆

@LK4D4
Copy link
Contributor

LK4D4 commented Dec 7, 2015

Haha, seems like tests fixing won't be easy

@duglin
Copy link
Contributor

duglin commented Dec 7, 2015

Its kind of disturbing that the change in semantics you mentioned didn't result in a change to a testcase. Aside from squashing this down :-) can we get a new testcase for that?

btw - I really like the idea of a cli lib!

@vdemeester
Copy link
Member

😻 Will have to take a look but \o/.

@calavera calavera force-pushed the api_client_lib branch 2 times, most recently from 3737202 to b77aed4 Compare December 7, 2015 19:40
Copy link
Member

Choose a reason for hiding this comment

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

Do we need both ImageCreate and ImagePull? Their implementation looks the same and ImageCreate is only called by pull helper. Also Parent in ImageCreate looks misleading as it is still just a reference to pull(together with tag).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we probably don't need both, it's something to consider. I agree that the implementation is very similar.

Copy link
Member

Choose a reason for hiding this comment

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

Does this have to return pointer? + few other places (ExecStartCheck, ExecConfig). I think if there is no strict requirement for it we should be consistent with other methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed these references to be consistent.

Copy link
Member

Choose a reason for hiding this comment

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

should still check for all flag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch! thank you.

@tonistiigi
Copy link
Member

docker cp seems to be broken. I get http: read on closed response body when copying from container and Error response from daemon: Untar re-exec error: exit status 1: output: unexpected EOF when copying to container. May need to add more tests if this is the case(maybe they only check API atm). edit: sorry for double post, janky has same error

@calavera
Copy link
Contributor Author

calavera commented Dec 7, 2015

@tonistiigi yep, there are still a few tests failing that I'm currently fixing. docker cp included.

@tianon
Copy link
Member

tianon commented Dec 7, 2015 via email

@jessfraz
Copy link
Contributor

jessfraz commented Dec 8, 2015

nice love the description definitely helps :)

@calavera
Copy link
Contributor Author

calavera commented Dec 8, 2015

@duglin I totally agree with you, I was very suspicious about not seen inspect test failing. I've added some in my last commit. All inspects commands are implemented exactly in the same way, so all of them behave alike 🙌

19cdcd1

@tianon
Copy link
Member

tianon commented Dec 9, 2015 via email

@calavera
Copy link
Contributor Author

calavera commented Dec 9, 2015

okay, I'll remove that call and go back to the ugly workaround 😔

Thanks for checking!

@LK4D4
Copy link
Contributor

LK4D4 commented Dec 9, 2015

@calavera You can use version build tags! Like +build !go1.5

@calavera
Copy link
Contributor Author

calavera commented Dec 9, 2015

@LK4D4 indeed. Doing that.

@lowenna
Copy link
Member

lowenna commented Dec 9, 2015

@calavera Hang fire - I'll update the CI nodes, shouldn't take too long. I have already updated node 1 as I'm playing with Windows CI on it. @mikedougherty I assume you're OK me updating 2..9?

@brahmaroutu
Copy link
Contributor

gccgo master builds failed because of this. I think the best would be to add gccgo PR builds to catch go1.5 related breakage earlier?
@tianon go1.5 support is on main branch, can we build gcc:6.0 image from master and use it for x86, Power and Z?

@tianon
Copy link
Member

tianon commented Dec 9, 2015 via email

@lowenna
Copy link
Member

lowenna commented Dec 9, 2015

We have to move to 1.5.2 on those machines anyway. I just accelerated the update. All nodes are updated with the exception of Jenkins-prs-3. @mikedougherty I sent you an email about that node - I was unable to logon to it, even after a restart through the portal.

@WeiZhang555
Copy link
Contributor

Wow, this is really amazing!! 👍

@mikedougherty
Copy link
Contributor

@jhowardmsft just got host 3 back up and running. sent you an email with details. thanks for the ping

thaJeztah added a commit to thaJeztah/cli that referenced this pull request Sep 5, 2025
relates to:

- moby/moby#11397
- moby/moby#18472

This warning was added in [moby@4a8b3ca] to print a warning when building
Linux images from a Windows client. Window's filesystem does not have an
"executable" bit, which mean that, for example, copying a shell script
to an image during build would lose the executable bit. So for Windows
clients, the executable bit would be set on all files, unconditionally.

Originally this was detected in the client, which had direct access to
the API response headers, but when refactoring the client to use a common
library in [moby@535c4c9], this was refactored into a `ImageBuildResponse`
wrapper, deconstructing the API response into an `io.Reader` and a string
field containing only the `OSType` header.

This was the only use and only purpose of the `OSType` field, and now that
BuildKit is the default builder for Linux images, this warning didn't get
printed unless BuildKit was explicitly disabled.

This patch removes the warning, so that we can potentially remove the
field, or the `ImageBuildResponse` type altogether.

[moby@4a8b3ca]: moby/moby@4a8b3ca
[moby@535c4c9]: moby/moby@535c4c9

Signed-off-by: Sebastiaan van Stijn <[email protected]>
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.