rpardini / docker-registry-proxy

An HTTPS Proxy for Docker providing centralized configuration and caching of any registry (quay.io, DockerHub, k8s.gcr.io)
Apache License 2.0
912 stars 170 forks source link

Use SHA as proxy cache KEY #97

Open yamarane opened 3 years ago

yamarane commented 3 years ago

Problem:

            # For blob requests by digest, do cache, and treat redirects.
        location ~ ^/v2/(.*)/blobs/sha256:(.*) {
            set $docker_proxy_request_type "blob-by-digest";
            include "/etc/nginx/nginx.manifest.common.conf";
        }

        # For manifest requests by digest, do cache, and treat redirects.
        # These are some of the requests that DockerHub will throttle.
        location ~ ^/v2/(.*)/manifests/sha256:(.*) {
            set $docker_proxy_request_type "manifest-by-digest";
            include "/etc/nginx/nginx.manifest.common.conf";
        }
    In these two cases ,  cache key is URI :(`proxy_cache_key   $uri;`) and this treats below 2 blobs as different and consumes extra storage!

    1. my.docker.host/v2/someDockerImage1/blobs/sha256:74924e75d64523f42420d9b0617430fa955e49d835e663e6c838f0ed5209c8da
    2. my.docker.host/v2/someDockerImage2/blobs/sha256:74924e75d64523f42420d9b0617430fa955e49d835e663e6c838f0ed5209c8da

Solution:

Use SHA as KEY

```
 location ~ ^/v2/(.*)/blobs/(.*) {
        set $cache_key $2;
        proxy_pass https://$host;
        proxy_cache cache;
        proxy_cache_key $cache_key;
 ```
hishamanver commented 3 years ago

i definitely think this should be implemented. this allows the cache to use dockers inherent ability to reuse layers