Skip to content

Commit cd0cbc6

Browse files
feat(entrypoint): add support for slow caching tier (#31)
Allow caching of specified targets to a separate caching location URIs are provided in nginx regex location format and semi-colon separate in env var e.g `SLOW_TIER_URIS="~^/v2/coreweave/(.*);~^/v2/nvidia/(.+)"`
1 parent 885ea68 commit cd0cbc6

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ ENV DEBUG="false"
7575
ENV DEBUG_HUB="false"
7676
# Enable nginx debugging mode; this uses nginx-debug binary and enabled debug logging, which is VERY verbose so separate setting
7777
ENV DEBUG_NGINX="false"
78+
# Enable slow caching tier; this allows caching in a secondary cache path on e.g a larger slower disk; for known URIs defined in SLOW_TIER_URIS
79+
ENV SLOW_TIER_ENABLED="false"
7880

7981
# Manifest caching tiers. Disabled by default, to mimick 0.4/0.5 behaviour.
8082
# Setting it to true enables the processing of the ENVs below.

entrypoint.sh

+22-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,28 @@ CACHE_DIRECTORY=${CACHE_DIRECTORY:-/docker_mirror_cache}
105105

106106
# The cache directory. This can get huge. Better to use a Docker volume pointing here!
107107
# Set to 32gb which should be enough
108-
echo "proxy_cache_path ${CACHE_DIRECTORY} levels=1:2 max_size=$CACHE_MAX_SIZE min_free=${CACHE_MIN_FREE:-1g} inactive=${CACHE_INACTIVE_TIME:-60d} keys_zone=cache:15m use_temp_path=off manager_threshold=${CACHE_MANAGER_THRESHOLD:-1000ms} manager_sleep=${CACHE_MANAGER_SLEEP:-250ms} manager_files=${CACHE_MANAGER_FILES:-100} loader_files=${CACHE_LOADER_FILES:-100} loader_threshold=${CACHE_LOADER_THRESHOLD:-200ms} loader_sleep=${CACHE_LOADER_SLEEP:-50ms};" > /etc/nginx/conf.d/cache_max_size.conf
108+
echo "proxy_cache_path ${CACHE_DIRECTORY} levels=1:2 max_size=${CACHE_MAX_SIZE:-15g} min_free=${CACHE_MIN_FREE:-1g} inactive=${CACHE_INACTIVE_TIME:-60d} keys_zone=cache:${CACHE_KEYS_ZONE:-15m} use_temp_path=off manager_threshold=${CACHE_MANAGER_THRESHOLD:-1000ms} manager_sleep=${CACHE_MANAGER_SLEEP:-250ms} manager_files=${CACHE_MANAGER_FILES:-100} loader_files=${CACHE_LOADER_FILES:-100} loader_threshold=${CACHE_LOADER_THRESHOLD:-200ms} loader_sleep=${CACHE_LOADER_SLEEP:-50ms};" > /etc/nginx/conf.d/cache_max_size.conf
109+
110+
if [[ "a${SLOW_TIER_ENABLED}" == "atrue" ]]; then
111+
{
112+
echo ""
113+
echo "proxy_cache_path ${SLOW_CACHE_DIRECTORY} levels=1:2 max_size=${SLOW_CACHE_MAX_SIZ:-15g} min_free=${SLOW_CACHE_MIN_FREE:-1g} inactive=${SLOW_CACHE_INACTIVE_TIME:-120d} keys_zone=slow_cache:${SLOW_CACHE_KEYS_ZONE:-150m} use_temp_path=off manager_threshold=${SLOW_CACHE_MANAGER_THRESHOLD:-1000ms} manager_sleep=${SLOW_CACHE_MANAGER_SLEEP:-250ms} manager_files=${SLOW_CACHE_MANAGER_FILES:-100} loader_files=${SLOW_CACHE_LOADER_FILES:-100} loader_threshold=${SLOW_CACHE_LOADER_THRESHOLD:-200ms} loader_sleep=${SLOW_CACHE_LOADER_SLEEP:-50ms};"
114+
echo ""
115+
echo "map \$request_uri \$cache {"
116+
echo " ${SLOW_TIER_URIS%;};" | sed 's/;/ slow_cache;\n /g'
117+
echo " default cache;"
118+
echo "}"
119+
echo ""
120+
} >> /etc/nginx/conf.d/cache_max_size.conf; else
121+
122+
{
123+
echo ""
124+
echo "map \$request_uri \$cache {"
125+
echo " default cache;"
126+
echo "}"
127+
echo ""
128+
} >> /etc/nginx/conf.d/cache_max_size.conf;
129+
fi
109130

110131
# Clear the cache directory if the free space is less than the threshold
111132
# Get the available space in the directory

nginx.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
316316

317317
# nginx goes to fetch the value from the upstream Location header
318318
proxy_pass $orig_loc;
319-
proxy_cache cache;
319+
proxy_cache $cache;
320320
# But we store the result with the cache key of the original request URI
321321
# so that future clients don't need to follow the redirect too
322322
proxy_cache_key $original_uri$slice_range;

nginx.manifest.common.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
add_header X-Docker-Registry-Proxy-Cache-Upstream-Status "$upstream_cache_status";
33
add_header X-Docker-Registry-Proxy-Cache-Type "$docker_proxy_request_type";
44
proxy_pass https://$targetHost;
5-
proxy_cache cache;
5+
proxy_cache $cache;
66
slice 4m;
77
proxy_cache_key $uri$slice_range;
88
proxy_set_header Range $slice_range;

0 commit comments

Comments
 (0)