Skip to content

Commit b4a783a

Browse files
authored
feat: add volume patches to mfe service and k8s (#264)
1 parent 02f06a6 commit b4a783a

6 files changed

Lines changed: 92 additions & 1 deletion

File tree

README.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,71 @@ For instance:
489489
Refer to the `patch catalog <#template-patch-catalog>`_ below for more details.
490490
491491
492+
Hosting extra static files
493+
~~~~~~~~~~~~~~~~~~~~~~~~~~
494+
495+
The MFE plugin allows other plugins to serve extra static files through the MFE service. This enables hosting custom assets (CSS, images, JavaScript, themes, etc.) directly alongside MFE applications, without rebuilding the core MFE image. Assets are exposed via a dedicated volume, so updates can be deployed dynamically via simple pushes to that volume, speeding up tests and updates without full-image builds.
496+
497+
To enable this functionality, set ``MFE_HOST_EXTRA_FILES`` to ``true``:
498+
499+
.. code-block:: bash
500+
501+
tutor config save --set MFE_HOST_EXTRA_FILES=true
502+
503+
When this setting is enabled, the configured volume patches (explained below) will be applied in all environments so that extra files can be served. In development mode it will additionally expose port ``8002`` on the ``mfe`` service, allowing direct access to those files. In production deployments, port mapping is not required since files are served through Caddy.
504+
505+
Then add your static files using volume patches. For local deployments, use the ``mfe-volumes`` patch:
506+
507+
.. code-block:: python
508+
509+
from tutor import hooks
510+
511+
hooks.Filters.ENV_PATCHES.add_item(
512+
(
513+
"mfe-volumes",
514+
"""
515+
- /path/to/static/files:/usr/share/caddy/myfiles:ro
516+
"""
517+
)
518+
)
519+
520+
For Kubernetes deployments, use the ``mfe-k8s-volumes`` patch:
521+
522+
.. code-block:: python
523+
524+
hooks.Filters.ENV_PATCHES.add_item(
525+
(
526+
"mfe-k8s-volumes",
527+
"""
528+
# Add your custom volume definition here. This can be any valid Kubernetes volume type.
529+
- name: myfiles-volume
530+
configMap:
531+
name: myfiles-configmap
532+
...
533+
"""
534+
)
535+
)
536+
537+
Your static files will be accessible at ``http(s)://{{ MFE_HOST }}/myfiles/``.
538+
539+
For advanced routing configurations, you can use the ``mfe-caddyfile`` patch to define custom Caddy rules for handling your static files:
540+
541+
.. code-block:: python
542+
543+
hooks.Filters.ENV_PATCHES.add_item(
544+
(
545+
"mfe-caddyfile",
546+
"""
547+
# Custom routing for static files
548+
handle_path /myfiles/* {
549+
root * /usr/share/caddy/myfiles
550+
file_server
551+
}
552+
"""
553+
)
554+
)
555+
556+
492557
Installing from a private npm registry
493558
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
494559
@@ -767,6 +832,20 @@ For a complete list of supported directives, consult the Caddy `Directives <http
767832
768833
File changed: ``tutormfe/templates/mfe/apps/mfe/Caddyfile``
769834
835+
mfe-volumes
836+
~~~~~~~~~~~
837+
838+
Add volumes to the mfe service in local Docker Compose deployment.
839+
840+
File changed: ``local/docker-compose.yml``
841+
842+
mfe-k8s-volumes
843+
~~~~~~~~~~~~~~~
844+
845+
Add volumes to the mfe deployment in Kubernetes.
846+
847+
File changed: ``k8s/deployments.yml``
848+
770849
771850
caddyfile-mfe-proxy
772851
~~~~~~~~~~~~~~~~~~~
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [Feature] Add `mfe-volumes` and `mfe-k8s-volumes` patches to enable plugins to serve static files through MFE service. (by @andres.giraldo)
2+
- [Improvement] Ensure MFE container accessibility in dev mode with default port mapping and external file hosting support. (by @andres.giraldo)

tutormfe/patches/k8s-deployments

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ spec:
2626
- name: config
2727
configMap:
2828
name: mfe-caddy-config
29+
{%- if MFE_HOST_EXTRA_FILES %}
30+
{{ patch("mfe-k8s-volumes") | indent(8) }}
31+
{%- endif %}

tutormfe/patches/local-docker-compose-dev-services

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
{%- endfor %}
2121

2222

23-
{% if mfe_data.unmounted|length > 0 %}
23+
{% if mfe_data.unmounted|length > 0 or MFE_HOST_EXTRA_FILES %}
2424
mfe:
2525
ports:
26+
{%- if MFE_HOST_EXTRA_FILES %}
27+
- 8002:8002
28+
{%- endif %}
2629
{%- for app_name, app in mfe_data.unmounted %}
2730
- {{ app["port"] }}:8002 # {{ app_name }}
2831
{%- endfor %}

tutormfe/patches/local-docker-compose-services

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ mfe:
44
restart: unless-stopped
55
volumes:
66
- ../plugins/mfe/apps/mfe/Caddyfile:/etc/caddy/Caddyfile:ro
7+
{% if MFE_HOST_EXTRA_FILES %}
8+
{{ patch("mfe-volumes") | indent(8) }}
9+
{% endif %}
710
depends_on:
811
- lms

tutormfe/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"HOST": "apps.{{ LMS_HOST }}",
2828
"COMMON_VERSION": "{{ OPENEDX_COMMON_VERSION }}",
2929
"CADDY_DOCKER_IMAGE": "{{ DOCKER_IMAGE_CADDY }}",
30+
"HOST_EXTRA_FILES": False,
3031
},
3132
}
3233

0 commit comments

Comments
 (0)