Merge branch 'feature/shared-digest-caching' of https://github.com/hishamanver/docker-registry-proxy into feature/configure-blob-caching

pull/105/head
Hisham 2021-08-13 09:36:13 +10:00
commit 5266f053e4
3 changed files with 8 additions and 1 deletions

View File

@ -118,6 +118,7 @@ echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME # First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} { location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
set \$docker_proxy_request_type "manifest-primary"; set \$docker_proxy_request_type "manifest-primary";
set \$cache_key \$uri;
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME}; proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME};
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }
@ -127,6 +128,7 @@ EOD
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME # Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} { location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
set \$docker_proxy_request_type "manifest-secondary"; set \$docker_proxy_request_type "manifest-secondary";
set \$cache_key \$uri;
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME}; proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME};
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }
@ -136,6 +138,7 @@ EOD
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME) # Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
location ~ ^/v2/(.*)/manifests/ { location ~ ^/v2/(.*)/manifests/ {
set \$docker_proxy_request_type "manifest-default"; set \$docker_proxy_request_type "manifest-default";
set \$cache_key \$uri;
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME}; proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME};
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }
@ -145,6 +148,7 @@ EOD
# Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true # Manifest caching is disabled. Enable it with ENABLE_MANIFEST_CACHE=true
location ~ ^/v2/(.*)/manifests/ { location ~ ^/v2/(.*)/manifests/ {
set \$docker_proxy_request_type "manifest-default-disabled"; set \$docker_proxy_request_type "manifest-default-disabled";
set \$cache_key \$uri;
proxy_cache_valid 0s; proxy_cache_valid 0s;
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }

View File

@ -262,6 +262,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# For blob requests by digest, do cache, and treat redirects. # For blob requests by digest, do cache, and treat redirects.
location ~ ^/v2/(.*)/blobs/sha256:(.*) { location ~ ^/v2/(.*)/blobs/sha256:(.*) {
set $docker_proxy_request_type "blob-by-digest"; set $docker_proxy_request_type "blob-by-digest";
set $cache_key $2;
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }
@ -269,6 +270,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# These are some of the requests that DockerHub will throttle. # These are some of the requests that DockerHub will throttle.
location ~ ^/v2/(.*)/manifests/sha256:(.*) { location ~ ^/v2/(.*)/manifests/sha256:(.*) {
set $docker_proxy_request_type "manifest-by-digest"; set $docker_proxy_request_type "manifest-by-digest";
set $cache_key $uri;
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }
@ -281,6 +283,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down # Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
location ~ ^/v2/(.*)/blobs/ { location ~ ^/v2/(.*)/blobs/ {
set $docker_proxy_request_type "blob-mutable"; set $docker_proxy_request_type "blob-mutable";
set $cache_key $uri;
proxy_cache_valid 0s; proxy_cache_valid 0s;
include "/etc/nginx/nginx.manifest.common.conf"; include "/etc/nginx/nginx.manifest.common.conf";
} }

View File

@ -3,7 +3,7 @@
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type"; add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost; proxy_pass https://$targetHost;
proxy_cache cache; proxy_cache cache;
proxy_cache_key $uri; proxy_cache_key $cache_key;
proxy_cache_use_stale error timeout http_500 http_502 http_504 http_429; proxy_cache_use_stale error timeout http_500 http_502 http_504 http_429;
proxy_intercept_errors on; proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects; error_page 301 302 307 = @handle_redirects;