From 4b14d20c5eca923346e4a515cbb0ffbbb3a51692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Mon, 30 Jan 2023 11:31:38 +0100 Subject: [PATCH] feat: overridable lms/cms max upload size Users want to be able to override the request `max_size` to upload larger files. But they will not be able to if the patch is placed after the `request` directive. So we move the patch statement before the directive. Also, we wrap the `request_body` directives within `handle` statements. If not, then different sizes are not managed properly. To override the max upload size in the cms, add the following to the "caddyfile-cms" patch: handle_path /import/* { request_body { max_size 500MB } } See discussion: https://discuss.openedx.org/t/how-to-update-caddyfile-using-tutor-plugin/8944 --- ...2932_regis_overridable_caddy_max_upload.md | 1 + docs/configuration.rst | 2 +- tutor/templates/apps/caddy/Caddyfile | 25 ++++++++++++------- tutor/templates/config/defaults.yml | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 changelog.d/20230130_112932_regis_overridable_caddy_max_upload.md diff --git a/changelog.d/20230130_112932_regis_overridable_caddy_max_upload.md b/changelog.d/20230130_112932_regis_overridable_caddy_max_upload.md new file mode 100644 index 0000000..7a92a51 --- /dev/null +++ b/changelog.d/20230130_112932_regis_overridable_caddy_max_upload.md @@ -0,0 +1 @@ +- [Improvement] Make it possible to override the max upload size in the LMS and the CMS. This is achieved by moving the "caddyfile-lms" and "caddyfile-cms" patches just before the `import proxy` declarations. We also wrap the `request_body` directives within `handle` statements, which means that the `max_body` sizes can be overridden for specific paths. (by @regisb) diff --git a/docs/configuration.rst b/docs/configuration.rst index b156950..92ca091 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -67,7 +67,7 @@ This configuration parameter defines the name of the Docker image to run for the This configuration paramater defines the name of the Docker image to run the development version of the lms and cms containers. By default, the Docker image tag matches the Tutor version it was built with. -- ``DOCKER_IMAGE_CADDY`` (default: ``"docker.io/caddy:2.4.6"``) +- ``DOCKER_IMAGE_CADDY`` (default: ``"docker.io/caddy:2.6.2"``) This configuration paramater defines which Caddy Docker image to use. diff --git a/tutor/templates/apps/caddy/Caddyfile b/tutor/templates/apps/caddy/Caddyfile index 46a5559..b361193 100644 --- a/tutor/templates/apps/caddy/Caddyfile +++ b/tutor/templates/apps/caddy/Caddyfile @@ -37,16 +37,21 @@ rewrite @favicon_matcher /theming/asset/images/favicon.ico # Limit profile image upload size - request_body /api/profile_images/*/*/upload { - max_size 1MB - } - request_body { - max_size 4MB + handle_path /api/profile_images/*/*/upload { + request_body { + max_size 1MB + } } import proxy "lms:8000" {{ patch("caddyfile-lms")|indent(4) }} + + handle_path /* { + request_body { + max_size 4MB + } + } } {{ CMS_HOST }}{$default_site_port} { @@ -55,13 +60,15 @@ } rewrite @favicon_matcher /theming/asset/images/favicon.ico - request_body { - max_size 250MB - } - import proxy "cms:8000" {{ patch("caddyfile-cms")|indent(4) }} + + handle_path /* { + request_body { + max_size 250MB + } + } } {{ patch("caddyfile") }} diff --git a/tutor/templates/config/defaults.yml b/tutor/templates/config/defaults.yml index 819a476..3bee19b 100644 --- a/tutor/templates/config/defaults.yml +++ b/tutor/templates/config/defaults.yml @@ -12,7 +12,7 @@ DOCKER_COMPOSE_VERSION: "3.7" DOCKER_REGISTRY: "docker.io/" DOCKER_IMAGE_OPENEDX: "{{ DOCKER_REGISTRY }}overhangio/openedx:{{ TUTOR_VERSION }}" DOCKER_IMAGE_OPENEDX_DEV: "openedx-dev:{{ TUTOR_VERSION }}" -DOCKER_IMAGE_CADDY: "docker.io/caddy:2.4.6" +DOCKER_IMAGE_CADDY: "docker.io/caddy:2.6.2" DOCKER_IMAGE_ELASTICSEARCH: "docker.io/elasticsearch:7.10.1" DOCKER_IMAGE_MONGODB: "docker.io/mongo:4.2.17" DOCKER_IMAGE_MYSQL: "docker.io/mysql:5.7.35"