Skip to content

Commit

Permalink
refactor: use MFE refs caching for master branches
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-boros committed Nov 14, 2023
1 parent 9b0f9a6 commit 1825eaf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
37 changes: 23 additions & 14 deletions tutormfe/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from glob import glob
import os
import re
import typing as t

import pkg_resources

from tutor import fmt
from tutor import hooks as tutor_hooks
from tutor import config as tutor_config
from tutor.hooks import priorities
from tutor.types import Config, get_typed
from .__about__ import __version__, __version_suffix__
Expand All @@ -24,55 +26,41 @@
}


# If the package version suffix is set (for instance, in the nightly branch) use the "heads" Github refs API endpoint by default.
def gh_refs_path() -> str:
return "heads" if __version_suffix__ else "tags"


CORE_MFE_APPS: dict[str, MFE_ATTRS_TYPE] = {
"authn": {
"repository": "https://github.com/openedx/frontend-app-authn",
"refs": "https://api.github.com/repos/openedx/frontend-app-authn/git/refs/" + gh_refs_path(),
"port": 1999,
},
"account": {
"repository": "https://github.com/openedx/frontend-app-account",
"refs": "https://api.github.com/repos/openedx/frontend-app-account/git/refs/" + gh_refs_path(),
"port": 1997,
},
"communications": {
"repository": "https://github.com/openedx/frontend-app-communications",
"refs": "https://api.github.com/repos/openedx/frontend-app-communications/git/refs/" + gh_refs_path(),
"port": 1984,
},
"course-authoring": {
"repository": "https://github.com/openedx/frontend-app-course-authoring",
"refs": "https://api.github.com/repos/openedx/frontend-app-course-authoring/git/refs/" + gh_refs_path(),
"port": 2001,
},
"discussions": {
"repository": "https://github.com/openedx/frontend-app-discussions",
"refs": "https://api.github.com/repos/openedx/frontend-app-discussions/git/refs/" + gh_refs_path(),
"port": 2002,
},
"gradebook": {
"repository": "https://github.com/openedx/frontend-app-gradebook",
"refs": "https://api.github.com/repos/openedx/frontend-app-gradebook/git/refs/" + gh_refs_path(),
"port": 1994,
},
"learning": {
"repository": "https://github.com/openedx/frontend-app-learning",
"refs": "https://api.github.com/repos/openedx/frontend-app-learning/git/refs/" + gh_refs_path(),
"port": 2000,
},
"ora-grading": {
"repository": "https://github.com/openedx/frontend-app-ora-grading",
"refs": "https://api.github.com/repos/openedx/frontend-app-ora-grading/git/refs/" + gh_refs_path(),
"port": 1993,
},
"profile": {
"repository": "https://github.com/openedx/frontend-app-profile",
"refs": "https://api.github.com/repos/openedx/frontend-app-profile/git/refs/" + gh_refs_path(),
"port": 1995,
},
}
Expand All @@ -86,6 +74,27 @@ def _add_core_mfe_apps(apps: dict[str, MFE_ATTRS_TYPE]) -> dict[str, MFE_ATTRS_T
return apps


@hooks.Actions.PROJECT_ROOT_READY.add()
def _modify_mfes(root: str):
"""
Set the GitHub ref for OpenEdX MFEs that are using the *.master branch.
If the repository of the MFE is not of openedx or the branch is not a
*.master branch, we are not setting the ref, hence the build won't benefit
from build caches.
"""
config = tutor_config.load_minimal(root)

for mfe, app in iter_mfes():
mfe_app_version = app.get("version", config.get("MFE_COMMON_VERSION"))
is_openedx_repo = app["repository"].startswith("https://github.com/openedx/")
is_master_branch = re.match(r"(^open-release\/\w+\.)?master$", mfe_app_version) is not None

if is_openedx_repo and is_master_branch:
refs_api_url_base = app["repository"].replace("github.com", "api.github.com/repos")
apps[mfe]["refs"] = f"{refs_api_url_base}/git/refs/heads/{mfe_app_version}"


def iter_mfes() -> t.Iterable[tuple[str, MFE_ATTRS_TYPE]]:
"""
Yield:
Expand Down
2 changes: 1 addition & 1 deletion tutormfe/templates/mfe/build/mfe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN echo "copying i18n data" \
FROM base AS {{ app_name }}-git
{#- Invalidate the build cache if a change is detected upstream #}
{%- if app.get("refs") %}
ADD {{ app["refs"] }}/{{ app.get("version", MFE_COMMON_VERSION) }} /tmp/gitref-{{ app_name }}
ADD {{ app["refs"] }} /tmp/gitref-{{ app_name }}
{%- endif %}
RUN git clone {{ app["repository"] }} --branch {{ app.get("version", MFE_COMMON_VERSION) }} --depth 1 .

Expand Down

0 comments on commit 1825eaf

Please sign in to comment.