Skip to content

Commit dbad57c

Browse files
committed
Exclude registry from manifest cache
ENABLE_MANIFEST_CACHING make it impossible to do roolups more freq than once per manifest cache interval. Add exclude list, so that manifest caching isn't applied for registries in this list.
1 parent fcf8fc1 commit dbad57c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Since version `0.6.0`, this proxy can be configured with the env var `ENABLE_MAN
2222
configurable caching of the manifest requests that DockerHub throttles. You can then fine-tune other parameters to your needs.
2323
Together with the possibility to centrally inject authentication (since 0.3x), this is probably one of the best ways to bring relief to your distressed cluster, while at the same time saving lots of bandwidth and time.
2424

25+
It is possible to disable manifest caching for your own private registry, see this [example](#exclude-registry-from-manifest-caching)
26+
2527
Note: enabling manifest caching, in its default config, effectively makes some tags **immutable**. Use with care. The configuration ENVs are explained in the [Dockerfile](./Dockerfile), relevant parts included below.
2628

2729
```dockerfile
@@ -261,6 +263,19 @@ EOF
261263
k3d cluster create --config /etc/k3d-proxy-config.yaml
262264
```
263265

266+
### Exclude registry from manifest caching
267+
268+
In some cases you may want to disable manifest caching for some registries (most preferably, for your private registry):
269+
270+
```bash
271+
docker run --rm --name docker_registry_proxy -it \
272+
-p 0.0.0.0:3128:3128 -e ENABLE_MANIFEST_CACHE=true \
273+
-e MANIFEST_CACHE_EXCLUDE_HOSTS="private-0.registry.tld private-1.registry.tld" \
274+
-v $(pwd)/docker_mirror_cache:/docker_mirror_cache \
275+
-v $(pwd)/docker_mirror_certs:/ca \
276+
rpardini/docker-registry-proxy:0.6.2
277+
```
278+
264279
## Configuring the Docker clients using Docker Desktop for Mac
265280

266281
Separate instructions for Mac clients available in [this dedicated Doc Desktop for Mac document](Docker-for-Mac.md).

entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf
111111
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
112112
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
113113
set \$docker_proxy_request_type "manifest-primary";
114+
proxy_no_cache \$manifestcacheExclude;
115+
proxy_cache_bypass \$manifestcacheExclude;
114116
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME};
115117
include "/etc/nginx/nginx.manifest.stale.conf";
116118
}
@@ -120,6 +122,8 @@ EOD
120122
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
121123
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
122124
set \$docker_proxy_request_type "manifest-secondary";
125+
proxy_no_cache \$manifestcacheExclude;
126+
proxy_cache_bypass \$manifestcacheExclude;
123127
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME};
124128
include "/etc/nginx/nginx.manifest.stale.conf";
125129
}
@@ -129,6 +133,8 @@ EOD
129133
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
130134
location ~ ^/v2/(.*)/manifests/ {
131135
set \$docker_proxy_request_type "manifest-default";
136+
proxy_no_cache \$manifestcacheExclude;
137+
proxy_cache_bypass \$manifestcacheExclude;
132138
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME};
133139
include "/etc/nginx/nginx.manifest.stale.conf";
134140
}
@@ -170,6 +176,17 @@ else
170176
EOF
171177
fi
172178

179+
# Manifest cache exclude per host basis:
180+
## default 0 should always be here:
181+
echo "default 0;" > /etc/nginx/nginx.manifest.cache.exclude.map;
182+
if [[ "x$MANIFEST_CACHE_EXCLUDE_HOSTS" != "x" ]]; then
183+
MANIFEST_CACHE_EXCLUDE_LIST=( $MANIFEST_CACHE_EXCLUDE_HOSTS )
184+
for index in "${!MANIFEST_CACHE_EXCLUDE_LIST[@]}"; do
185+
echo "\"${MANIFEST_CACHE_EXCLUDE_LIST[$index]}\" 1;";
186+
done >> /etc/nginx/nginx.manifest.cache.exclude.map;
187+
fi
188+
189+
173190
# normally use non-debug version of nginx
174191
NGINX_BIN="/usr/sbin/nginx"
175192

nginx.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ http {
129129
default "DID_NOT_MATCH_PATH";
130130
}
131131

132+
# Do not use manifest caching for hosts in MANIFEST_CACHE_EXCLUDE_HOSTS
133+
map $host $manifestcacheExclude {
134+
include /etc/nginx/nginx.manifest.cache.exclude.map;
135+
}
136+
132137

133138
# The proxy director layer, listens on 3128
134139
server {

0 commit comments

Comments
 (0)