From 52831532ecff8ad5e6036889da8a68386642a87f Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Wed, 29 May 2024 11:35:25 -0500 Subject: [PATCH] feat: add support for static cache config --- drydock/patches/kustomization-resources | 1 + drydock/patches/static-cache-config | 7 +++++ drydock/plugin.py | 17 ++++++++++++ .../drydock/k8s/ingress/static-cache.yml | 26 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 drydock/patches/static-cache-config create mode 100644 drydock/templates/drydock/k8s/ingress/static-cache.yml diff --git a/drydock/patches/kustomization-resources b/drydock/patches/kustomization-resources index de1ffcf1..eb2069cf 100644 --- a/drydock/patches/kustomization-resources +++ b/drydock/patches/kustomization-resources @@ -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 diff --git a/drydock/patches/static-cache-config b/drydock/patches/static-cache-config new file mode 100644 index 00000000..2f2b7fd9 --- /dev/null +++ b/drydock/patches/static-cache-config @@ -0,0 +1,7 @@ +# 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; diff --git a/drydock/plugin.py b/drydock/plugin.py index 3fb468f3..d9dad1bb 100644 --- a/drydock/plugin.py +++ b/drydock/plugin.py @@ -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. diff --git a/drydock/templates/drydock/k8s/ingress/static-cache.yml b/drydock/templates/drydock/k8s/ingress/static-cache.yml new file mode 100644 index 00000000..617ce536 --- /dev/null +++ b/drydock/templates/drydock/k8s/ingress/static-cache.yml @@ -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 %}