Skip to content

Commit

Permalink
feat: add support to nutmeg (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrrypg authored Jan 23, 2024
1 parent bfb9e4f commit b72c7b8
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 84 deletions.
81 changes: 45 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ for MFEs.

| Open edX release | Tutor version | Tutor MFE Version | Plugin release |
|------------------|-------------------|--------------------------------------|----------------|
| Olive | `>=15.0, <16` | `edunext/tutor-mfe@15.0.7.post1` | 1.x.x |
| Nutmeg | `>=13.0, <14` | `edunext/tutor-mfe@14.0.2.post1` | 14.x.x |

## Installation

```bash
pip install git+https://github.com/edunext/tutor-contrib-mfe-extensions@v1.1.0#egg=tutor-contrib-mfe-extensions==v1.1.0
pip install git+https://github.com/edunext/tutor-mfe@v15.0.7.post1#egg=tutor-mfe==v15.0.7.post1
pip install git+https://github.com/edunext/tutor-contrib-mfe-extensions@v14.0.0#egg=tutor-contrib-mfe-extensions==v14.0.0
pip install git+https://github.com/edunext/tutor-mfe@v14.0.2.post1#egg=tutor-mfe==v14.0.2.post1
```

## Plugin Configuration
Expand All @@ -36,42 +36,51 @@ bundles of each MFE and simply serve a small index.html file through caddy.
We use webpack's
[`output.publicPath`](https://webpack.js.org/configuration/output/#outputpublicpath)
to accomplish this. Due to current limitations in the building scripts
we need to use a custom version of
[`frontend-build`](https://github.com/eduNEXT/frontend-build/branches/all?query=cdn).
Until [`openedx/frontend-build#398`](https://github.com/openedx/frontend-build/pull/398)
is merged.

There is a custom version for each major release of `frontend-build` used by
the 7 default MFEs in olive:

- account: `v12.0.6-cdn-support`
- course-authoring: `v11.0.2-cdn-support`
- discussions: `v11.0.2-cdn-support`
- authn: `v11.0.2-cdn-support`
- gradebook: `v9.1.4-cdn-support`
- learning: `v9.1.4-cdn-support`
- profile: `v12.0.6-cdn-support`

In addition, we need to use a custom version of `tutor-mfe` to set extra environment
variables before the build step. The custom version version of `tutor-mfe` is going
to be needed for Olive installations and will eventually be dropped some time during
the Palm release.
we need to use custom versions of `frontend-platform` that include a backport of
[`openedx/frontend-platform#568`](https://github.com/openedx/frontend-platform/pull/568)
for releases previous to Quince.

The following is a list of supported MFEs for the current plugin version, each MFE is a
custom fork hosted by eduNEXT. You might use your own fork, but you must include the backport
mentioned before.


- Learning: [`eduNEXT/frontend-app-learning@ednx-release/nuez.master`](https://github.com/eduNEXT/frontend-app-learning/tree/ednx-release/nuez.master)

In addition, we need to use a custom version of `tutor-mfe` that includes the patch
`mfe-dockerfile-production-final` introduced in [`overhangio/tutor-mfe#179`](https://github.com/overhangio/tutor-mfe/pull/179).

### Building Caveats

At the moment each MFE image will be tied to a specific CDN endpoint. As a result,
it isn't possible to reuse the MFE image between environments (namely Staging and
production). You will have to rebuild the image in the following scenarios:

1. You have a working production image and want to enable CDN support: You must
rebuild the image using the same parameters while setting the
`MFE_EXTENSIONS_CDN_URL` variable with your distribution.
2. You modified your CDN endpoint and it now uses a different URL: Update the
value of `MFE_EXTENSIONS_CDN_URL` to the new URL.
3. You made changes to the code of any of the MFEs in the image and want to
deploy a new version: If your configuration already had CDN support update
the other parameters as you usually do in your deployment process, if it
didn't have CDN support follow step #1.
The value of `publicPath` is fixed at build time, therefore it's not possible to reuse
the MFE docker image if we set it's value to a specific CDN endpoint.
To avoid this limitation we use a script
[`docker-entrypoint.sh`](tutormfe_extensions/templates/mfe/build/mfe/docker-entrypoint.sh)
to dinamically change a placeholder value used in `publicPath` each time the container is
started.

We need to make sure our image is built using the placeholder `MFE_EXTENSIONS_PLACEHOLDER_STRING/app_name` as our `publicPath` (where `app_name` refers to the value of `MFE_MYMFE_MFE_APP.name`). In Nutmeg you configure `PUBLIC_PATH` through the `config.yml` file:

```yaml
MFE_LEARNING_MFE_APP:
env:
production:
PUBLIC_PATH: MFE_EXTENSIONS_PLACEHOLDER_STRING/learning
MFE_CONFIG_API_URL: /api/mfe_config/v1
APP_ID: learning
name: learning
port: 2000
repository: https://github.com/eduNEXT/frontend-app-learning.git
version: ednx-release/nuez.master
```
The learning MFE in eduNEXT fork also has support for the [`MFE_CONFIG_API`](https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst) in Nutmeg, you must also include the variables `MFE_CONFIG_API_URL` and `APP_ID` in your
`config.yml` while building the MFE to enable the API.

Once you enable the plugin and add the previous snippet to your configuration you can build
an image with a _"dynamic"_ `publicPath`. By default the placeholder will be replaced by
an empty string, which was the original value. In a Kubernetes environment it will be
replaced with the value of `MFE_EXTENSIONS_CDN_URL`.

## Hosting by Path

Expand Down
2 changes: 1 addition & 1 deletion tutormfe_extensions/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "14.0.0"
6 changes: 0 additions & 6 deletions tutormfe_extensions/patches/kustomization-configmapgenerator

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tutormfe_extensions/patches/mfe-dockerfile-pre-npm-build

This file was deleted.

5 changes: 5 additions & 0 deletions tutormfe_extensions/patches/mfe-dockerfile-production-final
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
COPY --chmod=755 ./docker-entrypoint.sh /openedx

ENTRYPOINT ["/openedx/docker-entrypoint.sh"]

CMD [ "caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile" ]
35 changes: 35 additions & 0 deletions tutormfe_extensions/patches/openedx-lms-production-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
LEARNING_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/learning"
ENABLE_MFE_CONFIG_API = True
MFE_CONFIG = {
"PARAGON_THEME_URLS": {
"core": {
"url": "https://cdn.jsdelivr.net/combine/npm/@edx/[email protected]/styles/css/themes/light/utility-classes.min.css,npm/@edx/[email protected]/dist/core.min.css"
},
"defaults": {
"light": "light"
},
"variants": {
"light": {
"url": "https://css-varsify.s3.amazonaws.com/public/a9959998-0bab-4447-ada5-6819866195f3.css"
}
}
},
"ACCESS_TOKEN_COOKIE_NAME": "edx-jwt-cookie-header-payload",
"BASE_URL": "{{ MFE_HOST }}",
"CSRF_TOKEN_API_PATH": "/csrf/api/v1/token",
"CREDENTIALS_BASE_URL": "",
"DISCOVERY_API_BASE_URL": "{% if DISCOVERY_HOST is defined %}{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ DISCOVERY_HOST }}{% endif %}",
"FAVICON_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/favicon.ico",
"LANGUAGE_PREFERENCE_COOKIE_NAME": "openedx-language-preference",
"LMS_BASE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}",
"LOGIN_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login",
"LOGO_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_TRADEMARK_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_WHITE_URL": "",
"LOGOUT_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/logout",
"MARKETING_SITE_BASE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}",
"REFRESH_ACCESS_TOKEN_ENDPOINT": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login_refresh",
"SEGMENT_KEY": "",
"STUDIO_BASE_URL": "{{ 'https' if ENABLE_HTTPS else 'http' }}://{{ CMS_HOST }}",
"USER_INFO_COOKIE_NAME": "user-info",
}
19 changes: 17 additions & 2 deletions tutormfe_extensions/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
("MFE_EXTENSIONS_VERSION", __version__),
("MFE_EXTENSIONS_CDN_URL", ""),
("MFE_EXTENSIONS_BY_PATH", True),
("MFE_EXTENSIONS_NPM_OVERRIDES", True),
]
)

Expand All @@ -42,7 +41,22 @@
# Danger zone!
# Add values to override settings from Tutor core or other plugins here.
# Each override is a pair: (setting_name, new_value). For example:
### ("PLATFORM_NAME", "My platform"),
(
"MFE_LEARNING_MFE_APP",
{
"name": "learning",
"repository": "https://github.com/eduNEXT/frontend-app-learning",
"env": {
"production": {
"PUBLIC_PATH": "MFE_EXTENSIONS_PLACEHOLDER_STRING/learning",
"MFE_CONFIG_API_URL": "/api/mfe_config/v1",
"APP_ID": "learning",
}
},
"port": 2000,
"version": "ednx-release/nuez.master",
},
),
]
)

Expand Down Expand Up @@ -148,6 +162,7 @@
[
("mfe_extensions/apps", "plugins"),
("mfe_extensions/k8s", "plugins"),
("mfe/build", "plugins"),
],
)

Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,3 @@ spec:
- name: MFE_CDN_URL
value: {{ MFE_EXTENSIONS_CDN_URL }}
name: mfe
volumeMounts:
- mountPath: /openedx/bin/
name: entrypoint
command:
- /openedx/bin/docker-entrypoint.sh
args:
- caddy
- run
- --config
- /etc/caddy/Caddyfile
- --adapter
- caddyfile
volumes:
- configMap:
defaultMode: 484
name: mfeextensions-docker
name: entrypoint

0 comments on commit b72c7b8

Please sign in to comment.