Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render mfe-ports for unmounted mfes when these exist #241

Open
wants to merge 4 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changelog.d/20250226_134324_ahmed.khalid_mfe_ports_bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Bugfix] Fixed syntax error in Docker configuration when all MFEs are mounted by ensuring the `ports:` section is only included if unmounted MFEs exist. (by @ahmed-arb and hinakhadim)
22 changes: 11 additions & 11 deletions tutormfe/patches/local-docker-compose-dev-services
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
mfe:
ports:
{%- for app_name, app in iter_mfes() %}
{%- if not iter_mounts(MOUNTS, app_name)|list %}
- {{ app["port"] }}:8002 # {{ app_name }}
{%- endif %}
{%- endfor %}
{%- set mfe_data = MFEMountData(MOUNTS) %}

{%- for app_name, app in iter_mfes() %}
{%- set mounts = iter_mounts(MOUNTS, app_name)|list %}
{%- if mounts %}
{%- for app_name, app, mounts in mfe_data.mounted %}
{{ app_name }}: # Work on this MFE for development
image: "{{ MFE_DOCKER_IMAGE_DEV_PREFIX }}-{{ app_name }}-dev:{{ MFE_VERSION }}"
ports:
Expand All @@ -25,5 +17,13 @@ mfe:
- lms
environment:
- "PORT={{ app['port'] }}"
{%- endif %}
{%- endfor %}


{% if mfe_data.unmounted|length > 0 %}
mfe:
ports:
{%- for app_name, app in mfe_data.unmounted %}
- {{ app["port"] }}:8002 # {{ app_name }}
{%- endfor %}
{% endif %}
20 changes: 20 additions & 0 deletions tutormfe/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tutor.__about__ import __version_suffix__
from tutor.hooks import priorities
from tutor.types import Config, get_typed
from tutor.bindmount import iter_mounts

from .__about__ import __version__
from .hooks import MFE_APPS, MFE_ATTRS_TYPE, PLUGIN_SLOTS
Expand Down Expand Up @@ -90,6 +91,24 @@ def get_mfes() -> dict[str, MFE_ATTRS_TYPE]:
return MFE_APPS.apply({})


class MFEMountData:
"""Stores categorized mounted and unmounted MFEs."""

def __init__(self, mounts: list[str]):
self.mounted: list[tuple[str, MFE_ATTRS_TYPE, list[str]]] = []
self.unmounted: list[tuple[str, MFE_ATTRS_TYPE]] = []
self._categorize_mfes(mounts)

def _categorize_mfes(self, mounts: list[str]) -> None:
"""Populates mounted and unmounted MFE lists based on mount data."""
for app_name, app in iter_mfes():
mfe_mounts = list(iter_mounts(mounts, app_name))
if mfe_mounts:
self.mounted.append((app_name, app, mfe_mounts))
else:
self.unmounted.append((app_name, app))


@tutor_hooks.lru_cache
def get_plugin_slots(mfe_name: str) -> list[tuple[str, str]]:
"""
Expand Down Expand Up @@ -131,6 +150,7 @@ def get_mfe(mfe_name: str) -> t.Union[MFE_ATTRS_TYPE, t.Any]:
("iter_mfes", iter_mfes),
("iter_plugin_slots", iter_plugin_slots),
("is_mfe_enabled", is_mfe_enabled),
("MFEMountData", MFEMountData),
]
)

Expand Down