diff --git a/.github/environments/enabled/config.yml b/.github/environments/enabled/config.yml index 35ba58a1..f29ac007 100644 --- a/.github/environments/enabled/config.yml +++ b/.github/environments/enabled/config.yml @@ -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 diff --git a/README.md b/README.md index 526d6347..7aa50ec9 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,15 @@ The following configuration options are available: - `DRYDOCK_ENABLE_SENTRY`: Whether to enable sentry. Defaults to `true`. - `DRYDOCK_SENTRY_DSN`: The sentry DSN. Defaults to `""`. - `DRYDOCK_POD_LIFECYCLE`: Whether to enable pod lifecycle. Defaults to `true`. +- `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 + ``` - `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_MFE`: The minimum available percentage for the MFE's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`. - `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_FORUM`: The minimum available percentage for the FORUM's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`. - `DRYDOCK_PDB_MINAVAILABLE_PERCENTAGE_CADDY`: The minimum available percentage for the CADDY's PodDisruptionBudget. To disable the PodDisruptionBudget, set `0`. Defaults to `0`. diff --git a/drydock/patches/kustomization-resources b/drydock/patches/kustomization-resources index de1ffcf1..291028b8 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 +- plugins/drydock/k8s/ingress/static-cache.yml {%- 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..e69de29b diff --git a/drydock/plugin.py b/drydock/plugin.py index 3fb468f3..dcb56003 100644 --- a/drydock/plugin.py +++ b/drydock/plugin.py @@ -162,6 +162,7 @@ def get_sync_waves_for_resource(resource_name: str) -> SYNC_WAVES_ORDER_ATTRS_TY "lms-worker", "cms-worker", ], + "NGINX_STATIC_CACHE_CONFIG": {}, }, # 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..fea9bcaf --- /dev/null +++ b/drydock/templates/drydock/k8s/ingress/static-cache.yml @@ -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 %}