3-tier implementation of manifest caching (#57)

* implement manifest caching; refactor config with includes, and generate from ENVs in entrypoint.sh
- disabled by default; enable with -e ENABLE_MANIFEST_CACHE=true
- default times and regexes are a wild guess, make sure to tune for your use case.
-  add manifest caching/anti-ratelimit usage note to README
- add -e ENABLE_MANIFEST_CACHE=true to examples, some wording changes
- add -e ENABLE_MANIFEST_CACHE=true to one the steps in test workflow.
This commit is contained in:
Ricardo Pardini
2020-10-30 18:54:10 +01:00
committed by GitHub
parent 227a397225
commit a726f88049
7 changed files with 138 additions and 47 deletions

View File

@@ -267,57 +267,27 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# For blob requests by digest, do cache, and treat redirects.
location ~ ^/v2/(.*)/blobs/sha256:(.*) {
set $docker_proxy_request_type "blob-by-digest";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects;
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";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects;
include "/etc/nginx/nginx.manifest.common.conf";
}
# Cache manifest requests that are not by digest (e.g. tags)
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
# These are some of the requests that DockerHub will throttle.
location ~ ^/v2/(.*)/manifests/ {
set $docker_proxy_request_type "manifest-mutable";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
proxy_intercept_errors on;
proxy_cache_use_stale error timeout http_500 http_502 http_504 http_429;
proxy_cache_valid 0s;
error_page 301 302 307 = @handle_redirects;
}
# Config for manifest URL caching is generated by the entrypoint based on ENVs.
# Go check it out, entrypoint.sh
include "/etc/nginx/nginx.manifest.caching.config.conf";
# Cache blobs requests that are not by digest
# Since these are mutable, we invalidate them immediately and keep them only in case the backend is down
location ~ ^/v2/(.*)/blobs/ {
set $docker_proxy_request_type "blob-mutable";
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
proxy_pass https://$targetHost;
proxy_cache cache;
proxy_cache_key $uri;
proxy_intercept_errors on;
proxy_cache_use_stale error timeout http_500 http_502 http_504 http_429;
proxy_cache_valid 0s;
error_page 301 302 307 = @handle_redirects;
include "/etc/nginx/nginx.manifest.stale.conf";
}
location @handle_redirects {