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 1 commit into
base: release
Choose a base branch
from

Conversation

hinakhadim
Copy link
Contributor

Description

The issue occurs when all MFEs (Micro Frontends) are mounted, and the ports section in the Docker configuration is left empty, leading to a syntax error in the generated Dockerfile. Specifically, the ports: line becomes invalid as another key follows it (auth:) without any content. In the tutor dev context, the issue occurs because developers mount MFEs for testing purposes. It won't reproduce for tutor local.

...

mfe:
    ports:
auth:
   ....

How to Reproduce

  • Clone all MFEs (authn, account, communications, course-authoring, discussions, gradebook, learner-dashboard, learning, ora-grading, profile)
  • Run tutor mounts add $(pwd)/frontend-app-* where * represents all MFEs name one by one
  • tutor config save
  • tutor dev start OR directly check the mfe-ports section in tutor-env/env/dev/docker-compose.yml

What this PR does

This PR resolves the issue by implementing logic to first check if any unmounted MFEs exist. If unmounted MFEs are found, their corresponding ports are rendered in the ports: section. This ensures that the Docker configuration is generated correctly and avoids errors caused by leaving the ports: section empty.

TestCases:

  • If any unmounted MFE exists, its corresponding port should be rendered under the mfe: ports: section.
...

mfe:
    ports:
        - 1997:8002 # account
        - 1984:8002 # communications

authn:
    image: ...
...           
  • If no unmounted MFEs exist, the mfe: ports: section should be excluded entirely from the generated output.
...
#There should be no section of mfe->ports

authn:
     image: ....
...          

Closes #242

@hinakhadim hinakhadim requested a review from regisb December 14, 2024 06:30
Copy link
Contributor

@regisb regisb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is way better than the one I initially suggested. Please just add a changelog entry and add "close #242" to your commit message.

{%- set _ = unmounted_mfes.append((app_name, app)) %}
{%- endif %}
{%- endfor %}
{% if unmounted_mfes|length > 0 %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: {% if unmounted_mfes|length > 0 %}

@@ -1,10 +1,17 @@
{%- set unmounted_mfes = [] %}
{%- for app_name, app in iter_mfes() %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simplify this declaration with the following?

{%- set unmounted_mfes = [(app_name, app) for app_name, app in iter_mfes() if not list(iter_mounts(MOUNTS, app_name))] %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's giving error: Error: Template syntax error: expected token ',', got 'for'. Because of , in app_name, app. I've also tried with iter_mfes().items(). Got same error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. In which case, I suggest to expose a unmounted_mfes variable via the ENV_TEMPLATE_VARIABLES filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

Mounting all MFEs leads to error
2 participants