Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,71 @@ For instance:
Refer to the `patch catalog <#template-patch-catalog>`_ below for more details.


Hosting extra static files
~~~~~~~~~~~~~~~~~~~~~~~~~~

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.

To enable this functionality, set ``MFE_HOST_EXTRA_FILES`` to ``true``:

.. code-block:: bash

tutor config save --set MFE_HOST_EXTRA_FILES=true

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.

Then add your static files using volume patches. For local deployments, use the ``mfe-volumes`` patch:

.. code-block:: python

from tutor import hooks

hooks.Filters.ENV_PATCHES.add_item(
(
"mfe-volumes",
"""
- /path/to/static/files:/usr/share/caddy/myfiles:ro
"""
)
)

For Kubernetes deployments, use the ``mfe-k8s-volumes`` patch:

.. code-block:: python

hooks.Filters.ENV_PATCHES.add_item(
(
"mfe-k8s-volumes",
"""
# Add your custom volume definition here. This can be any valid Kubernetes volume type.
- name: myfiles-volume
configMap:
name: myfiles-configmap
...
"""
)
)

Your static files will be accessible at ``http(s)://{{ MFE_HOST }}/myfiles/``.

For advanced routing configurations, you can use the ``mfe-caddyfile`` patch to define custom Caddy rules for handling your static files:

.. code-block:: python

hooks.Filters.ENV_PATCHES.add_item(
(
"mfe-caddyfile",
"""
# Custom routing for static files
handle_path /myfiles/* {
root * /usr/share/caddy/myfiles
file_server
}
"""
)
)


Installing from a private npm registry
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -762,6 +827,20 @@ Add any configurations for the mfe-caddyfile.

File changed: ``tutormfe/templates/mfe/apps/mfe/Caddyfile``

mfe-volumes
~~~~~~~~~~~

Add volumes to the mfe service in local Docker Compose deployment.

File changed: ``local/docker-compose.yml``

mfe-k8s-volumes
~~~~~~~~~~~~~~~

Add volumes to the mfe deployment in Kubernetes.

File changed: ``k8s/deployments.yml``


Troubleshooting
---------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Feature] Add `mfe-volumes` and `mfe-k8s-volumes` patches to enable plugins to serve static files through MFE service. (by @andres.giraldo)
- [Improvement] Ensure MFE container accessibility in dev mode with default port mapping and external file hosting support. (by @andres.giraldo)
3 changes: 3 additions & 0 deletions tutormfe/patches/k8s-deployments
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ spec:
- name: config
configMap:
name: mfe-caddy-config
{%- if MFE_HOST_EXTRA_FILES %}
{{ patch("mfe-k8s-volumes") | indent(8) }}
{%- endif %}
5 changes: 4 additions & 1 deletion tutormfe/patches/local-docker-compose-dev-services
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
{%- endfor %}


{% if mfe_data.unmounted|length > 0 %}
{% if mfe_data.unmounted|length > 0 or MFE_HOST_EXTRA_FILES %}
Comment thread
Ang-m4 marked this conversation as resolved.
mfe:
ports:
{%- if MFE_HOST_EXTRA_FILES %}
- 8002:8002
{%- endif %}
{%- for app_name, app in mfe_data.unmounted %}
- {{ app["port"] }}:8002 # {{ app_name }}
{%- endfor %}
Expand Down
3 changes: 3 additions & 0 deletions tutormfe/patches/local-docker-compose-services
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ mfe:
restart: unless-stopped
volumes:
- ../plugins/mfe/apps/mfe/Caddyfile:/etc/caddy/Caddyfile:ro
{% if MFE_HOST_EXTRA_FILES %}
{{ patch("mfe-volumes") | indent(8) }}
{% endif %}
depends_on:
- lms
1 change: 1 addition & 0 deletions tutormfe/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"HOST": "apps.{{ LMS_HOST }}",
"COMMON_VERSION": "{{ OPENEDX_COMMON_VERSION }}",
"CADDY_DOCKER_IMAGE": "{{ DOCKER_IMAGE_CADDY }}",
"HOST_EXTRA_FILES": False,
},
}

Expand Down