From 47af7fa5d8f856e4f9cc96e4cbb54fa86e9dbe3d Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 4 Aug 2021 09:09:35 +1000 Subject: [PATCH] add options to customise cache timers --- entrypoint.sh | 9 ++++++++- nginx.conf | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 32ba88a..a9988b3 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -99,10 +99,17 @@ echo "error_log /var/log/nginx/error.log warn;" > /etc/nginx/error.log.debug.wa # Set Docker Registry cache size, by default, 32 GB ('32g') CACHE_MAX_SIZE=${CACHE_MAX_SIZE:-32g} +# Set Docker Registry cache max age, by default, 60 days ('60d') +CACHE_MAX_AGE=${CACHE_MAX_AGE:-60d} # The cache directory. This can get huge. Better to use a Docker volume pointing here! # Set to 32gb which should be enough -echo "proxy_cache_path /docker_mirror_cache levels=1:2 max_size=$CACHE_MAX_SIZE inactive=60d keys_zone=cache:10m use_temp_path=off;" > /etc/nginx/conf.d/cache_max_size.conf +echo "proxy_cache_path /docker_mirror_cache levels=1:2 max_size=$CACHE_MAX_SIZE inactive=$CACHE_MAX_AGE keys_zone=cache:10m use_temp_path=off;" > /etc/nginx/conf.d/proxy_cache_path.conf + +# Set Docker Registry cache valid duration, by default, 60 days ('60d') +CACHE_VALIDITY_PERIOD=${CACHE_VALIDITY_PERIOD:-60d} +# Cache all 200, 206 for CACHE_VALIDITY_PERIOD. +echo "proxy_cache_valid 200 206 $CACHE_VALIDITY_PERIOD;" > /etc/nginx/conf.d/proxy_cache_valid.conf # Manifest caching configuration. We generate config based on the environment vars. echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf diff --git a/nginx.conf b/nginx.conf index 897628e..e929190 100644 --- a/nginx.conf +++ b/nginx.conf @@ -79,7 +79,7 @@ http { gzip off; # Entrypoint generates the proxy_cache_path here, so it is configurable externally. - include /etc/nginx/conf.d/cache_max_size.conf; + include /etc/nginx/conf.d/proxy_cache_path.conf; # Just in case you want to rewrite some hosts. Default maps directly. map $host $targetHost { @@ -232,8 +232,8 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/" proxy_cache_lock on; proxy_cache_lock_timeout 880s; - # Cache all 200, 206 for 60 days. - proxy_cache_valid 200 206 60d; + # Entrypoint generates the proxy_cache_valid here, so it is configurable externally. + include /etc/nginx/conf.d/proxy_cache_valid.conf; # Some extra settings to maximize cache hits and efficiency proxy_force_ranges on;