Skip to content

Commit 8f88039

Browse files
HishamHisham
Hisham
authored and
Hisham
committed
enable caching by sha for blobs
1 parent 2456b35 commit 8f88039

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Diff for: entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf
111111
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
112112
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
113113
set \$docker_proxy_request_type "manifest-primary";
114+
set \$cache_key \$uri;
114115
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME};
115116
include "/etc/nginx/nginx.manifest.stale.conf";
116117
}
@@ -120,6 +121,7 @@ EOD
120121
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
121122
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
122123
set \$docker_proxy_request_type "manifest-secondary";
124+
set \$cache_key \$uri;
123125
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME};
124126
include "/etc/nginx/nginx.manifest.stale.conf";
125127
}
@@ -129,6 +131,7 @@ EOD
129131
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
130132
location ~ ^/v2/(.*)/manifests/ {
131133
set \$docker_proxy_request_type "manifest-default";
134+
set \$cache_key \$uri;
132135
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME};
133136
include "/etc/nginx/nginx.manifest.stale.conf";
134137
}
@@ -138,6 +141,7 @@ EOD
138141
# Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true
139142
location ~ ^/v2/(.*)/manifests/ {
140143
set \$docker_proxy_request_type "manifest-default-disabled";
144+
set \$cache_key \$uri;
141145
proxy_cache_valid 0s;
142146
include "/etc/nginx/nginx.manifest.stale.conf";
143147
}

Diff for: nginx.conf

+3
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,15 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
262262
# For blob requests by digest, do cache, and treat redirects.
263263
location ~ ^/v2/(.*)/blobs/sha256:(.*) {
264264
set $docker_proxy_request_type "blob-by-digest";
265+
set $cache_key $2;
265266
include "/etc/nginx/nginx.manifest.common.conf";
266267
}
267268

268269
# For manifest requests by digest, do cache, and treat redirects.
269270
# These are some of the requests that DockerHub will throttle.
270271
location ~ ^/v2/(.*)/manifests/sha256:(.*) {
271272
set $docker_proxy_request_type "manifest-by-digest";
273+
set $cache_key $uri;
272274
include "/etc/nginx/nginx.manifest.common.conf";
273275
}
274276

@@ -281,6 +283,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
281283
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
282284
location ~ ^/v2/(.*)/blobs/ {
283285
set $docker_proxy_request_type "blob-mutable";
286+
set $cache_key $uri;
284287
proxy_cache_valid 0s;
285288
include "/etc/nginx/nginx.manifest.stale.conf";
286289
}

Diff for: nginx.manifest.common.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
44
proxy_pass https://$targetHost;
55
proxy_cache cache;
6-
proxy_cache_key $uri;
6+
proxy_cache_key $cache_key;
77
proxy_intercept_errors on;
88
error_page 301 302 307 = @handle_redirects;

0 commit comments

Comments
 (0)