Skip to content

Commit

Permalink
Merge pull request #777 from sboardwell/add-optional-proxy-bypass
Browse files Browse the repository at this point in the history
Add optional selective cache refresh option
  • Loading branch information
dduportal authored Sep 25, 2023
2 parents 28b6fe7 + 8e43887 commit fd6d098
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/artifact-caching-proxy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
description: artifact-caching-proxy is a Nginx caching proxy in front of repo.jenkins-ci.org
name: artifact-caching-proxy
type: application
version: 0.12.0
version: 0.13.0
14 changes: 14 additions & 0 deletions charts/artifact-caching-proxy/templates/nginx-proxy-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ data:
set $http_x_forwarded_proto $scheme;
}
{{- if .Values.proxy.proxyBypass.enabled -}}
# include bypass option from local ip only
# e.g. curl -H 'Cache-Purge: true' -I http://127.0.0.1:8080/...
# https://bluegrid.io/edu/how-to-purge-the-nginx-cache/
set $bypass 0;
if ($remote_addr ~ "^(127.0.0.1)$") {
set $bypass $http_cache_purge;
}
{{- end }}

# In-memory requests tuning for buffering content
chunked_transfer_encoding on;
client_max_body_size 0;
Expand All @@ -61,6 +71,10 @@ data:

# Default location for cached requests
location / {
{{- if .Values.proxy.proxyBypass.enabled -}}
add_header Cache $upstream_cache_status;
proxy_cache_bypass $bypass;
{{- end }}
proxy_pass https://$remote_repo$request_uri;
proxy_cache_key $uri;
include /etc/nginx/conf.d/common-proxy.conf;
Expand Down
39 changes: 39 additions & 0 deletions charts/artifact-caching-proxy/tests/proxy_cache_bypass_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
suite: Tests using proxyBypass
templates:
- nginx-proxy-configmap.yaml
tests:
- it: Should include proxy_cache_bypass
template: nginx-proxy-configmap.yaml
set:
proxy:
proxyBypass:
enabled: true
asserts:
- hasDocuments:
count: 1
- isKind:
of: ConfigMap
- matchRegex:
path: data["vhost-proxy.conf"]
pattern: proxy_cache_bypass
- matchRegex:
path: data["vhost-proxy.conf"]
pattern: set \$bypass 0;

- it: Should NOT include proxy_cache_bypass
template: nginx-proxy-configmap.yaml
set:
proxy:
proxyBypass:
enabled: false
asserts:
- hasDocuments:
count: 1
- isKind:
of: ConfigMap
- notMatchRegex:
path: data["vhost-proxy.conf"]
pattern: proxy_cache_bypass
- notMatchRegex:
path: data["vhost-proxy.conf"]
pattern: set \$bypass 0;
3 changes: 3 additions & 0 deletions charts/artifact-caching-proxy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ proxy:
proxyPass: "repo.jenkins-ci.org"
proxyCacheValidCode: "200 206"
proxyCacheValidCodeDuration: "1M"
# http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_bypass
proxyBypass:
enabled: false

0 comments on commit fd6d098

Please sign in to comment.