Skip to content

Commit

Permalink
feat: add support for static cache config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed May 29, 2024
1 parent 7bd3266 commit 4370dfb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions drydock/patches/kustomization-resources
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- plugins/drydock/k8s/ingress/cms.yml
- plugins/drydock/k8s/ingress/mfe.yml
- plugins/drydock/k8s/ingress/extra-hosts.yml
{% if DRYDOCK_NGINX_STATIC_CACHE_CONFIG %}- plugins/drydock/k8s/ingress/static-cache.yml{%- endif %}
{%- endif %}
{% if DRYDOCK_DEBUG -%}
- plugins/drydock/k8s/debug/deployments.yml
Expand Down
33 changes: 33 additions & 0 deletions drydock/patches/static-cache-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Compression settings
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
# Cache settings
proxy_cache_valid 404 10m;
proxy_cache_use_stale error timeout updating http_404 http_500 http_502 http_503 http_504;
proxy_cache static-cache;
proxy_cache_valid any 120m;
proxy_cache_bypass $http_x_purge;
add_header X-Cache-Status $upstream_cache_status;
17 changes: 17 additions & 0 deletions drydock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ def get_sync_waves_for_resource(resource_name: str) -> SYNC_WAVES_ORDER_ATTRS_TY
"lms-worker",
"cms-worker",
],
"NGINX_STATIC_CACHE_CONFIG": {
"lms": {
"host": "{{ LMS_HOST }}",
"path": "/static/",
"port": 8000,
},
"cms": {
"host": "{{ CMS_HOST }}",
"path": "/static/",
"port": 8000,
},
"mfe": {
"host": "{{ MFE_HOST }}",
"path": "/static/",
"port": 8002,
},
},
},
# Add here settings that don't have a reasonable default for all users. For
# instance: passwords, secret keys, etc.
Expand Down
26 changes: 26 additions & 0 deletions drydock/templates/drydock/k8s/ingress/static-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{%- for service, config in DRYDOCK_NGINX_STATIC_CACHE_CONFIG.items() %}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-static-{{ service }}
namespace: {{ K8S_NAMESPACE }}
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 8m
nginx.ingress.kubernetes.io/proxy-buffering: "on"
nginx.ingress.kubernetes.io/configuration-snippet: |
{{ patch("static-cache-config") | indent(6)}}
spec:
ingressClassName: nginx
rules:
- host: {{ config["host"] }}
http:
paths:
- pathType: Prefix
path: {{ config["path"]}}
backend:
service:
name: {% if DRYDOCK_BYPASS_CADDY -%}{% else -%}caddy{% endif %}
port:
number: {% if DRYDOCK_BYPASS_CADDY -%}{{ config["port"] }}{% else -%}80{% endif %}
{%- endfor %}

0 comments on commit 4370dfb

Please sign in to comment.