Skip to content

Commit 9941df2

Browse files
Hishamrpardini
Hisham
authored andcommitted
enable caching by sha for blobs
1 parent e3f1eee commit 9941df2

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

entrypoint.sh

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf
115115
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
116116
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
117117
set \$docker_proxy_request_type "manifest-primary";
118+
set \$cache_key \$uri;
118119
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME};
119120
include "/etc/nginx/nginx.manifest.stale.conf";
120121
}
@@ -124,6 +125,7 @@ EOD
124125
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
125126
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
126127
set \$docker_proxy_request_type "manifest-secondary";
128+
set \$cache_key \$uri;
127129
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME};
128130
include "/etc/nginx/nginx.manifest.stale.conf";
129131
}
@@ -133,6 +135,7 @@ EOD
133135
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
134136
location ~ ^/v2/(.*)/manifests/ {
135137
set \$docker_proxy_request_type "manifest-default";
138+
set \$cache_key \$uri;
136139
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME};
137140
include "/etc/nginx/nginx.manifest.stale.conf";
138141
}
@@ -142,6 +145,7 @@ EOD
142145
# Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true
143146
location ~ ^/v2/(.*)/manifests/ {
144147
set \$docker_proxy_request_type "manifest-default-disabled";
148+
set \$cache_key \$uri;
145149
proxy_cache_valid 0s;
146150
include "/etc/nginx/nginx.manifest.stale.conf";
147151
}

nginx.conf

+3
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,15 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
266266
# For blob requests by digest, do cache, and treat redirects.
267267
location ~ ^/v2/(.*)/blobs/sha256:(.*) {
268268
set $docker_proxy_request_type "blob-by-digest";
269+
set $cache_key $2;
269270
include "/etc/nginx/nginx.manifest.common.conf";
270271
}
271272

272273
# For manifest requests by digest, do cache, and treat redirects.
273274
# These are some of the requests that DockerHub will throttle.
274275
location ~ ^/v2/(.*)/manifests/sha256:(.*) {
275276
set $docker_proxy_request_type "manifest-by-digest";
277+
set $cache_key $uri;
276278
include "/etc/nginx/nginx.manifest.common.conf";
277279
}
278280

@@ -285,6 +287,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
285287
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
286288
location ~ ^/v2/(.*)/blobs/ {
287289
set $docker_proxy_request_type "blob-mutable";
290+
set $cache_key $uri;
288291
proxy_cache_valid 0s;
289292
include "/etc/nginx/nginx.manifest.stale.conf";
290293
}

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)