overhangio / tutor-mfe

This plugin makes it possible to easily add micro frontend (MFE) applications on top of an Open edX platform that runs with Tutor.
GNU Affero General Public License v3.0
22 stars 90 forks source link

Mounted MFEs with node_modules missing fail to start the server #218

Open DawoudSheraz opened 2 months ago

DawoudSheraz commented 2 months ago

This issue is a similar issue to https://github.com/overhangio/tutor/issues/997. The steps to reproduce are:

Like the mentioned issue in tutor core, the bind-mounted MFE during image build does not get node_modules copied back to host. When running tutor, the host MFE directory without node_modules overrides the installed node_modules within image, thus resulting in fedx-script not found.

hinakhadim commented 1 month ago

I conclude to two solutions:

Solution 1:

While mounting, add this line in the volume: /openedx/app/node_modules. This line will make node_modules a volume (It won't call binding). Link to StackOverflow

authn: # Work on this MFE for development
      image: "docker.io/overhangio/openedx-authn-dev:18.0.0"
      ...
      volumes:
          - ../plugins/mfe/apps/mfe/webpack.dev-tutor.config.js:/openedx/app/webpack.dev-tutor.config.js:ro
          - /host-machine-path/.../frontend-app-authn:/openedx/app
          - /openedx/app/node_modules             # here, we're ignoring node_modules
      ...
Pros:
Cons:

Solution 2:

As @DawoudSheraz mentioned this method above, we can install node_modules in the host machine project folder after the mounting process (this is binding; we are binding our host machine files to container files).

Pros:
Cons:

Feel free to share if you have any other method to tackle this thing.

DawoudSheraz commented 1 month ago

@hinakhadim For solution 1, when will the very first install after the mount happen? Will it be done manually inside container?

hinakhadim commented 1 month ago

@hinakhadim For solution 1, when will the first install after the mount happen? Will it be done manually inside container?

Solution 1 flow:

By using solution 1, we will not face fedx-scripts not found error. In volumes, the line /openedx/app/node_modules ignores node_modules mounting. It means the whole app will mount to /openedx/app and node_modules folder will not mount. As a result, installed node_modules (from the MFE image) will be used.

Solution 2 flow:

@arbrandes @regisb any suggestions are highly appreciated.

regisb commented 1 month ago

I think the answer is to run npm clean-install as part of run tutor dev launch. One "mfe" init tasks could take care of running that command, as it is done in the LMS: https://github.com/overhangio/tutor/blob/master/tutor/templates/jobs/init/mounted-directories.sh