GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.68k stars 1.44k forks source link

Work around Google HTTP client giving null content for HEAD requests. #21

Open coollog opened 6 years ago

coollog commented 6 years ago

From https://github.com/GoogleCloudPlatform/minikube-build-tools-for-java/issues/116

The Google HTTP client gives null content for HEAD requests. Docker registry can return useful content for HEAD responses. In BlobChecker, this content can contain useful registry error codes to parse.

Proposed solution: Do a HEAD, then a GET

chanseokoh commented 5 years ago

I'm starting to question if the proposed do-HEAD-then-GET is needed for practical purposes (although I haven't looked into the Docker registry protocol.) If HEAD does not return 2xx for the given digest, it can never mean the registry has the blob in question. I think the only gain with the second GET is that we can verify if the server is really saying the given digest is absent or the server is not well-behaving. But even when the server is not well-behaving, we are checking the code 404, so we will halt and surface other non-404 and 2xx responses immediately. Not to mention 404 seems enough to over-approximate the absence of the blob. Even if 404 was due to a server malfunctioning, the subsequent pushBlob() will surface a problem.

chanseokoh commented 5 years ago

However, this might matter if we are going to have a complete registry client library. I don't know.

chanseokoh commented 3 years ago

As I said earlier, I think we are fine to not implement the proposed do-HEAD-then-GET in practice.

However, we have some code around this including a TODO, so we need to clean them up.

https://github.com/GoogleContainerTools/jib/blob/37e37b67a65d8ff00a4106d14315757c1e6d27ee/jib-core/src/main/java/com/google/cloud/tools/jib/registry/BlobChecker.java#L69-L82