Skip to content

Commit

Permalink
feat: add support for static cache config (#115)
Browse files Browse the repository at this point in the history
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 1df8bc7)
  • Loading branch information
Cristhian Garcia authored Jul 2, 2024
1 parent 102ac77 commit 485a190
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/environments/enabled/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_LMS_WORKER: 50
DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CMS: 50
DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CMS_WORKER: 50
DRYDOCK_MIGRATE_FROM: 13
LMS_HOST: local.edly.io
CMS_HOST: studio.local.edly.io
MFE_HOST: apps.local.edly.io
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: /
port: 8002
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ The following configuration options are available:
- `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_LMS_WORKER` : The minimum available percentage for the LMS WORKER's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`.
- `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CMS` : The minimum available percentage for the CMS's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`.
- `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CMS_WORKER` : The minimum available percentage for the worker's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`.
- `NGINX_STATIC_CACHE_CONFIG`: A list of dictionaries with settings for different services to cache their assets in NGINX.
The following is an example of the expected values:
```yaml
NGINX_STATIC_CACHE_CONFIG:
{{service_name}}:
host: {{service_host}} # e.g: {{LMS_HOST}}
path: /static/ # you can specify a different path
port: {{service_port}} # only needed if you have DRYDOCK_BYPASS_CADDY enabled
```

.. note::
You also need to set `DRYDOCK_INIT_JOBS` to `true` to enable the release-specific upgrade jobs in the case of a platform migration.
Expand Down
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
- plugins/drydock/k8s/ingress/static-cache.yml
{%- endif %}
{% if DRYDOCK_DEBUG -%}
- plugins/drydock/k8s/debug/deployments.yml
Expand Down
Empty file.
1 change: 1 addition & 0 deletions drydock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def get_sync_waves_for_resource(resource_name: str) -> SYNC_WAVES_ORDER_ATTRS_TY
"PDB_MINAVAILABLE_PERCENTAGE_MFE": 0,
"PDB_MINAVAILABLE_PERCENTAGE_FORUM": 0,
"PDB_MINAVAILABLE_PERCENTAGE_CADDY": 0,
"NGINX_STATIC_CACHE_CONFIG": {},
},
# Add here settings that don't have a reasonable default for all users. For
# instance: passwords, secret keys, etc.
Expand Down
33 changes: 33 additions & 0 deletions drydock/templates/drydock/k8s/ingress/static-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{%- 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: |
# 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;
{{ 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 -%}{{ service }}{% else -%}caddy{% endif %}
port:
number: {% if DRYDOCK_BYPASS_CADDY -%}{{ config["port"] }}{% else -%}80{% endif %}
{%- endfor %}

0 comments on commit 485a190

Please sign in to comment.