Skip to content

Commit 256a3ba

Browse files
alexdev-wbrpardini
authored andcommitted
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 e3f1eee commit 256a3ba

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
@@ -30,6 +30,8 @@ This proxy can be configured with the env var `ENABLE_MANIFEST_CACHE=true` which
3030
configurable caching of the manifest requests that DockerHub throttles. You can then fine-tune other parameters to your needs.
3131
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.
3232

33+
It is possible to disable manifest caching for your own private registry, see this [example](#exclude-registry-from-manifest-caching)
34+
3335
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.
3436

3537
```dockerfile
@@ -266,6 +268,19 @@ EOF
266268
k3d cluster create --config /etc/k3d-proxy-config.yaml
267269
```
268270

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

271286
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
@@ -115,6 +115,8 @@ echo -n "" >/etc/nginx/nginx.manifest.caching.config.conf
115115
# First tier caching of manifests; configure via MANIFEST_CACHE_PRIMARY_REGEX and MANIFEST_CACHE_PRIMARY_TIME
116116
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_PRIMARY_REGEX} {
117117
set \$docker_proxy_request_type "manifest-primary";
118+
proxy_no_cache \$manifestcacheExclude;
119+
proxy_cache_bypass \$manifestcacheExclude;
118120
proxy_cache_valid ${MANIFEST_CACHE_PRIMARY_TIME};
119121
include "/etc/nginx/nginx.manifest.stale.conf";
120122
}
@@ -124,6 +126,8 @@ EOD
124126
# Secondary tier caching of manifests; configure via MANIFEST_CACHE_SECONDARY_REGEX and MANIFEST_CACHE_SECONDARY_TIME
125127
location ~ ^/v2/(.*)/manifests/${MANIFEST_CACHE_SECONDARY_REGEX} {
126128
set \$docker_proxy_request_type "manifest-secondary";
129+
proxy_no_cache \$manifestcacheExclude;
130+
proxy_cache_bypass \$manifestcacheExclude;
127131
proxy_cache_valid ${MANIFEST_CACHE_SECONDARY_TIME};
128132
include "/etc/nginx/nginx.manifest.stale.conf";
129133
}
@@ -133,6 +137,8 @@ EOD
133137
# Default tier caching for manifests. Caches for ${MANIFEST_CACHE_DEFAULT_TIME} (from MANIFEST_CACHE_DEFAULT_TIME)
134138
location ~ ^/v2/(.*)/manifests/ {
135139
set \$docker_proxy_request_type "manifest-default";
140+
proxy_no_cache \$manifestcacheExclude;
141+
proxy_cache_bypass \$manifestcacheExclude;
136142
proxy_cache_valid ${MANIFEST_CACHE_DEFAULT_TIME};
137143
include "/etc/nginx/nginx.manifest.stale.conf";
138144
}
@@ -174,6 +180,17 @@ else
174180
EOF
175181
fi
176182

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

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)