Skip to content

Commit 52b6e9d

Browse files
author
Cristhian Garcia
authored
feat: add support for static cache config (#116)
fix: address PR suggestions fix: address PR suggestions fix: address PR suggestions fix: address PR suggestions build: correct port and path for mfe tests (cherry picked from commit e331e29)
1 parent 693c91b commit 52b6e9d

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

.github/environments/enabled/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_LMS_WORKER: 50
3030
DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CMS: 50
3131
DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CMS_WORKER: 50
3232
DRYDOCK_MIGRATE_FROM: 13
33+
LMS_HOST: local.edly.io
34+
CMS_HOST: studio.local.edly.io
35+
MFE_HOST: apps.local.edly.io
36+
NGINX_STATIC_CACHE_CONFIG:
37+
lms:
38+
host: "{{LMS_HOST}}"
39+
path: /static/
40+
port: 8000
41+
cms:
42+
host: "{{CMS_HOST}}"
43+
path: /static/
44+
port: 8000
45+
mfe:
46+
host: "{{MFE_HOST}}"
47+
path: /
48+
port: 8002

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ The following configuration options are available:
5656
- `DRYDOCK_ENABLE_SENTRY`: Whether to enable sentry. Defaults to `true`.
5757
- `DRYDOCK_SENTRY_DSN`: The sentry DSN. Defaults to `""`.
5858
- `DRYDOCK_POD_LIFECYCLE`: Whether to enable pod lifecycle. Defaults to `true`.
59+
- `NGINX_STATIC_CACHE_CONFIG`: A list of dictionaries with settings for different services to cache their assets in NGINX.
60+
The following is an example of the expected values:
61+
```yaml
62+
NGINX_STATIC_CACHE_CONFIG:
63+
{{service_name}}:
64+
host: {{service_host}} # e.g: {{LMS_HOST}}
65+
path: /static/ # you can specify a different path
66+
port: {{service_port}} # only needed if you have DRYDOCK_BYPASS_CADDY enabled
67+
```
5968
- `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_MFE`: The minimum available percentage for the MFE's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`.
6069
- `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_FORUM`: The minimum available percentage for the FORUM's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`.
6170
- `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CADDY`: The minimum available percentage for the CADDY's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`.

drydock/patches/kustomization-resources

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- plugins/drydock/k8s/ingress/cms.yml
1313
- plugins/drydock/k8s/ingress/mfe.yml
1414
- plugins/drydock/k8s/ingress/extra-hosts.yml
15+
- plugins/drydock/k8s/ingress/static-cache.yml
1516
{%- endif %}
1617
{% if DRYDOCK_DEBUG -%}
1718
- plugins/drydock/k8s/debug/deployments.yml

drydock/patches/static-cache-config

Whitespace-only changes.

drydock/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def get_sync_waves_for_resource(resource_name: str) -> SYNC_WAVES_ORDER_ATTRS_TY
162162
"lms-worker",
163163
"cms-worker",
164164
],
165+
"NGINX_STATIC_CACHE_CONFIG": {},
165166
},
166167
# Add here settings that don't have a reasonable default for all users. For
167168
# instance: passwords, secret keys, etc.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{%- for service, config in DRYDOCK_NGINX_STATIC_CACHE_CONFIG.items() %}
2+
---
3+
apiVersion: networking.k8s.io/v1
4+
kind: Ingress
5+
metadata:
6+
name: ingress-static-{{ service }}
7+
namespace: {{ K8S_NAMESPACE }}
8+
annotations:
9+
nginx.ingress.kubernetes.io/proxy-body-size: 8m
10+
nginx.ingress.kubernetes.io/proxy-buffering: "on"
11+
nginx.ingress.kubernetes.io/configuration-snippet: |
12+
# Cache settings
13+
proxy_cache_valid 404 10m;
14+
proxy_cache_use_stale error timeout updating http_404 http_500 http_502 http_503 http_504;
15+
proxy_cache static-cache;
16+
proxy_cache_valid any 120m;
17+
proxy_cache_bypass $http_x_purge;
18+
add_header X-Cache-Status $upstream_cache_status;
19+
{{ patch("static-cache-config") | indent(6)}}
20+
spec:
21+
ingressClassName: nginx
22+
rules:
23+
- host: {{ config["host"] }}
24+
http:
25+
paths:
26+
- pathType: Prefix
27+
path: {{ config["path"]}}
28+
backend:
29+
service:
30+
name: {% if DRYDOCK_BYPASS_CADDY -%}{{ service }}{% else -%}caddy{% endif %}
31+
port:
32+
number: {% if DRYDOCK_BYPASS_CADDY -%}{{ config["port"] }}{% else -%}80{% endif %}
33+
{%- endfor %}

0 commit comments

Comments
 (0)