Refactor resource configuration:

- Introduce new resource_filter plugin (mandatory hard_default, auto entity_name fallback)
- Replace get_app_conf calls with resource_filter in resource.yml.j2
- Add WEBSERVER_CPUS_EFFECTIVE, WEBSERVER_WORKER_PROCESSES, WEBSERVER_WORKER_CONNECTIONS to 05_webserver.yml
- Update Nginx templates (sys-svc-webserver, web-app-magento, web-app-nextcloud) to use new vars
- Extend svc-prx-openresty config with cpus/mem limits
- Add unit tests for resource_filter

Details: https://chatgpt.com/share/68d3a493-9a5c-800f-8cd2-bd2e7a3e3fda
This commit is contained in:
2025-09-24 09:58:30 +02:00
parent 9bf77e1e35
commit 9ba0efc1a1
8 changed files with 180 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
cpus: {{ applications | get_app_conf( application_id, [ 'docker', 'services', service_name | default(application_id | get_entity_name ), 'cpus' ] |join('.'), False, RESOURCE_CPUS) }}
mem_reservation: {{ applications | get_app_conf( application_id, [ 'docker', 'services', service_name | default(application_id | get_entity_name ), 'mem_reservation' ] |join('.'), False, RESOURCE_MEM_RESERVATION) }}
mem_limit: {{ applications | get_app_conf( application_id, [ 'docker', 'services', service_name | default(application_id | get_entity_name ), 'mem_limit' ] |join('.'), False, RESOURCE_MEM_LIMIT) }}
pids_limit: {{ applications | get_app_conf( application_id, [ 'docker', 'services', service_name | default(application_id | get_entity_name ), 'pids_limit' ] |join('.'), False, RESOURCE_PIDS_LIMIT) }}
cpus: {{ applications | resource_filter(application_id, 'cpus', service_name | default(''), RESOURCE_CPUS) }}
mem_reservation: {{ applications | resource_filter(application_id, 'mem_reservation', service_name | default(''), RESOURCE_MEM_RESERVATION) }}
mem_limit: {{ applications | resource_filter(application_id, 'mem_limit', service_name | default(''), RESOURCE_MEM_LIMIT) }}
pids_limit: {{ applications | resource_filter(application_id, 'pids_limit', service_name | default(''), RESOURCE_PIDS_LIMIT) }}

View File

@@ -1,7 +1,10 @@
docker:
services:
openresty:
name: "openresty"
name: "openresty"
cpus: 0.5
mem_reservation: 1g
mem_limit: 2g
volumes:
www: "/var/www/"
nginx: "/etc/nginx/"

View File

@@ -1,8 +1,8 @@
worker_processes auto;
worker_processes {{ WEBSERVER_WORKER_PROCESSES }};
events
{
worker_connections 1024;
worker_connections {{ WEBSERVER_WORKER_CONNECTIONS }};
}
http

View File

@@ -1,6 +1,6 @@
worker_processes auto;
worker_processes {{ WEBSERVER_WORKER_PROCESSES }};
events { worker_connections 1024; }
events { worker_connections {{ WEBSERVER_WORKER_CONNECTIONS }}; }
http {
include /etc/nginx/mime.types;

View File

@@ -2,7 +2,7 @@
# Verify time by time, that this rules are valid:
# https://docs.nextcloud.com/server/latest/admin_manual/installation/nginx.html
worker_processes auto;
worker_processes {{ WEBSERVER_WORKER_PROCESSES }};
# @see https://chatgpt.com/share/67aa3ce9-eea0-800f-85e8-ac54a3810b13
error_log /proc/self/fd/2 {% if MODE_DEBUG | bool %}debug{% else %}warn{% endif %};
@@ -10,7 +10,7 @@ pid /var/run/nginx.pid;
events {
worker_connections 1024;
worker_connections {{ WEBSERVER_WORKER_CONNECTIONS }};
}