From aac0355183a14f1f774b7ce6884b052eafe147c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Gonz=C3=A1lez?= Date: Fri, 24 Feb 2023 23:01:35 -0400 Subject: [PATCH] feat: configure uwsgi through an ini file --- ...21412_moises.gonzalez_configurable_uwsgi.md | 12 ++++++++++++ docs/reference/patches.rst | 11 +++++++++++ tutor/templates/apps/openedx/uwsgi.ini | 3 +++ tutor/templates/build/openedx/Dockerfile | 17 +++++++---------- .../templates/build/openedx/settings/uwsgi.ini | 10 ++++++++++ tutor/templates/k8s/deployments.yml | 18 ++++++++++++++++++ tutor/templates/kustomization.yml | 6 ++++++ tutor/templates/local/docker-compose.yml | 2 ++ 8 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 changelog.d/20230310_021412_moises.gonzalez_configurable_uwsgi.md create mode 100644 tutor/templates/apps/openedx/uwsgi.ini create mode 100644 tutor/templates/build/openedx/settings/uwsgi.ini diff --git a/changelog.d/20230310_021412_moises.gonzalez_configurable_uwsgi.md b/changelog.d/20230310_021412_moises.gonzalez_configurable_uwsgi.md new file mode 100644 index 0000000..904c765 --- /dev/null +++ b/changelog.d/20230310_021412_moises.gonzalez_configurable_uwsgi.md @@ -0,0 +1,12 @@ + + + + +- [Improvement] Make it possible to extend or override the configuration of the uWSGI server. (by @MoisesGSalas) diff --git a/docs/reference/patches.rst b/docs/reference/patches.rst index c5f0baa..4cc86ca 100644 --- a/docs/reference/patches.rst +++ b/docs/reference/patches.rst @@ -356,3 +356,14 @@ Python-formatted LMS settings in development. Values defined here override the v File: ``apps/openedx/settings/lms/production.py`` Python-formatted LMS settings in production. Values defined here override the values from :patch:`openedx-lms-common-settings`. + +``uwsgi-config`` +================ + +File: ``apps/openedx/settings/uwsgi.ini`` + +A .INI formatted file used to extend or override the uWSGI configuration. + +Check the uWSGI documentation for more details about the `.INI format `__ and the `list of available options `__. + +.. patch:: uwsgi-config diff --git a/tutor/templates/apps/openedx/uwsgi.ini b/tutor/templates/apps/openedx/uwsgi.ini new file mode 100644 index 0000000..8ff0484 --- /dev/null +++ b/tutor/templates/apps/openedx/uwsgi.ini @@ -0,0 +1,3 @@ +{% include "build/openedx/settings/uwsgi.ini" %} +{{ patch("uwsgi-config") }} + diff --git a/tutor/templates/build/openedx/Dockerfile b/tutor/templates/build/openedx/Dockerfile index a78863e..3e00fec 100644 --- a/tutor/templates/build/openedx/Dockerfile +++ b/tutor/templates/build/openedx/Dockerfile @@ -251,17 +251,14 @@ CMD ./manage.py $SERVICE_VARIANT runserver 0.0.0.0:8000 ###### Final image with production cmd FROM production as final +# Default amount of uWSGI processes +ENV UWSGI_WORKERS=2 + +# Copy the default uWSGI configuration +COPY --chown=app:app settings/uwsgi.ini . + # Run server -CMD uwsgi \ - --static-map /static=/openedx/staticfiles/ \ - --static-map /media=/openedx/media/ \ - --http 0.0.0.0:8000 \ - --thunder-lock \ - --single-interpreter \ - --enable-threads \ - --processes=${UWSGI_WORKERS:-2} \ - --buffer-size=8192 \ - --wsgi-file $SERVICE_VARIANT/wsgi.py +CMD uwsgi uwsgi.ini {{ patch("openedx-dockerfile-final") }} diff --git a/tutor/templates/build/openedx/settings/uwsgi.ini b/tutor/templates/build/openedx/settings/uwsgi.ini new file mode 100644 index 0000000..a716d48 --- /dev/null +++ b/tutor/templates/build/openedx/settings/uwsgi.ini @@ -0,0 +1,10 @@ +[uwsgi] +static-map = /static=/openedx/staticfiles/ +static-map = /media=/openedx/media/ +http = 0.0.0.0:8000 +buffer-size = 8192 +wsgi-file = $(SERVICE_VARIANT)/wsgi.py +processes = $(UWSGI_WORKERS) +thunder-lock = true +single-interpreter = true +enable-threads = true diff --git a/tutor/templates/k8s/deployments.yml b/tutor/templates/k8s/deployments.yml index 4d86d47..7571ae5 100644 --- a/tutor/templates/k8s/deployments.yml +++ b/tutor/templates/k8s/deployments.yml @@ -96,6 +96,9 @@ spec: name: settings-cms - mountPath: /openedx/config name: config + - mountPath: /openedx/edx-platform/uwsgi.ini + name: uwsgi-config + subPath: uwsgi.ini resources: requests: memory: 2Gi @@ -111,6 +114,12 @@ spec: - name: config configMap: name: openedx-config + - name: uwsgi-config + configMap: + name: openedx-uwsgi-config + items: + - key: uwsgi.ini + path: uwsgi.ini --- apiVersion: apps/v1 kind: Deployment @@ -198,6 +207,9 @@ spec: name: settings-cms - mountPath: /openedx/config name: config + - mountPath: /openedx/edx-platform/uwsgi.ini + name: uwsgi-config + subPath: uwsgi.ini resources: requests: memory: 2Gi @@ -213,6 +225,12 @@ spec: - name: config configMap: name: openedx-config + - name: uwsgi-config + configMap: + name: openedx-uwsgi-config + items: + - key: uwsgi.ini + path: uwsgi.ini --- apiVersion: apps/v1 kind: Deployment diff --git a/tutor/templates/kustomization.yml b/tutor/templates/kustomization.yml index 63c2404..f29fea1 100644 --- a/tutor/templates/kustomization.yml +++ b/tutor/templates/kustomization.yml @@ -51,6 +51,12 @@ configMapGenerator: options: labels: app.kubernetes.io/name: openedx +- name: openedx-uwsgi-config + files: + - apps/openedx/uwsgi.ini + options: + labels: + app.kubernetes.io/name: openedx - name: redis-config files: - apps/redis/redis.conf diff --git a/tutor/templates/local/docker-compose.yml b/tutor/templates/local/docker-compose.yml index c2834c2..36e0368 100644 --- a/tutor/templates/local/docker-compose.yml +++ b/tutor/templates/local/docker-compose.yml @@ -111,6 +111,7 @@ services: - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro - ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro - ../apps/openedx/config:/openedx/config:ro + - ../apps/openedx/uwsgi.ini:/openedx/edx-platform/uwsgi.ini:ro - ../../data/lms:/openedx/data - ../../data/openedx-media:/openedx/media depends_on: @@ -142,6 +143,7 @@ services: - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro - ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro - ../apps/openedx/config:/openedx/config:ro + - ../apps/openedx/uwsgi.ini:/openedx/edx-platform/uwsgi.ini:ro - ../../data/cms:/openedx/data - ../../data/openedx-media:/openedx/media depends_on: