From f16be61ac2fa319adad33609b8318bd0f7be118b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Fernanda=20Magallanes?= <35668326+MaferMazu@users.noreply.github.com> Date: Fri, 6 Sep 2024 09:54:35 -0500 Subject: [PATCH] fix: add patches to compile and enable themes (#5) * fix: add patches to compile and enable themes * fix: add dependencies compilation * docs: update the readme * test: add more tests in integration test * fix: use TUTOR_VERSION instead of PICASSO_TUTOR_VERSION to maintain compatibility --- .github/workflows/integration_test.yml | 30 ++++++++++++++ README.rst | 25 ++++++++++-- tutorpicasso/patches/cms-env | 3 ++ tutorpicasso/patches/lms-env | 3 ++ .../patches/openedx-cms-production-settings | 6 +++ .../patches/openedx-common-assets-settings | 3 ++ .../patches/openedx-development-settings | 6 +++ .../patches/openedx-dockerfile-pre-assets | 40 +++++++++++++++++++ .../patches/openedx-lms-production-settings | 6 +++ 9 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 tutorpicasso/patches/cms-env create mode 100644 tutorpicasso/patches/lms-env create mode 100644 tutorpicasso/patches/openedx-cms-production-settings create mode 100644 tutorpicasso/patches/openedx-common-assets-settings create mode 100644 tutorpicasso/patches/openedx-development-settings create mode 100644 tutorpicasso/patches/openedx-dockerfile-pre-assets create mode 100644 tutorpicasso/patches/openedx-lms-production-settings diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index 2032919..0214eca 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -33,7 +33,9 @@ jobs: - name: Adding data to the config.yml run: | + TUTOR_VERSION=$(tutor --version | awk '{print $NF}') cat <> config.yml + TUTOR_VERSION: $TUTOR_VERSION PICASSO_MANAGE_DPKG: name: eox-manage repo: git@github.com:eduNEXT/eox-manage.git @@ -42,6 +44,13 @@ jobs: - name: endx-saas-themes repo: git@github.com:eduNEXT/ednx-saas-themes.git version: master + PICASSO_THEME_DIRS: + - /openedx/themes/ednx-saas-themes/edx-platform + - /openedx/themes/ednx-saas-themes/edx-platform/bragi-generator + - /openedx/themes/ednx-saas-themes/edx-platform/bragi-children + PICASSO_THEMES_NAME: + - bragi + - css-runtime PICASSO_EXTRA_COMMANDS: - tutor plugins update - tutor plugins index add https://raw.githubusercontent.com/eduNEXT/tutor-plugin-indexes/picasso_test/ @@ -58,6 +67,27 @@ jobs: run: | TUTOR_ROOT="$(pwd)" tutor picasso enable-themes + if grep -q 'bragi' env/build/openedx/Dockerfile; then + echo "'bragi' found in env/build/openedx/Dockerfile." + else + echo "'bragi' not found for the building process." + exit 1 + fi + + if grep -q '/openedx/themes/ednx-saas-themes/edx-platform' env/build/openedx/Dockerfile; then + echo "'/openedx/themes/ednx-saas-themes/edx-platform' found in env/build/openedx/Dockerfile." + else + echo "'/openedx/themes/ednx-saas-themes/edx-platform' not found for the building process." + exit 1 + fi + + if grep -q 'ENABLE_COMPREHENSIVE_THEMING = True' env/apps/openedx/settings/lms/production.py; then + echo "'ENABLE_COMPREHENSIVE_THEMING = True' found in env/apps/openedx/settings/lms/production.py." + else + echo "'ENABLE_COMPREHENSIVE_THEMING = True' not found in env/apps/openedx/settings/lms/production.py." + exit 1 + fi + - name: Check enable-private-packages run: | TUTOR_ROOT="$(pwd)" tutor picasso enable-private-packages diff --git a/README.rst b/README.rst index fdf57f4..564d694 100644 --- a/README.rst +++ b/README.rst @@ -104,18 +104,27 @@ To enable themes in your Tutor environment, follow these steps: 1. Add the necessary configuration in your Tutor environment's ``config.yml`` file: .. code-block:: yaml - + + TUTOR_VERSION: PICASSO_THEMES: - - name: + - name: repo: version: - - name: + - name: repo: version: + PICASSO_THEMES_NAME: + - + - + PICASSO_THEME_DIRS: + - + - **Note:** If your theme repository is public, you can also use the HTTPS URL in ``repo``. +**Note:** The ``PICASSO_THEMES``, ``PICASSO_THEME_DIRS`` and ``PICASSO_THEMES_NAME`` variables are lists and can have one or more elements. + 2. Save the configuration with ``tutor config save`` 3. Run the enable command @@ -125,7 +134,15 @@ To enable themes in your Tutor environment, follow these steps: # Enable themes tutor picasso enable-themes -This command clones your theme repository into the folder that Tutor uses for themes. Documentation available at `Installing custom theme`_ tutorial. +This command will clone your theme repository into the folder that Tutor uses for themes. You can find the documentation in the `Installing custom theme`_ tutorial. + +If ``PICASSO_THEMES`` is defined, the plugin will set ``ENABLE_COMPREHENSIVE_THEMING = True``. + +If ``PICASSO_THEME_DIRS`` is defined, the plugin will extend the ``COMPREHENSIVE_THEME_DIRS`` by patches. + +The ``TUTOR_VERSION``, ``PICASSO_THEME_DIRS`` and ``PICASSO_THEMES_NAME`` variables are used to compile the themes. For detailed information, see the patch `openedx-dockerfile-pre-assets `_. + +You can set the ``PICASSO_DEFAULT_SITE_THEME`` (optional), which will be in ``DEFAULT_SITE_THEME``; if not, we will use the first element in ``PICASSO_THEMES_NAME``. **Note:** Don't forget to add extra configurations in a Tutor plugin if your theme requires it. diff --git a/tutorpicasso/patches/cms-env b/tutorpicasso/patches/cms-env new file mode 100644 index 0000000..ad8b8d9 --- /dev/null +++ b/tutorpicasso/patches/cms-env @@ -0,0 +1,3 @@ +{%- if PICASSO_DEFAULT_SITE_THEME is defined or PICASSO_THEMES_NAME is defined %} +DEFAULT_SITE_THEME: "{{ PICASSO_DEFAULT_SITE_THEME | default(PICASSO_THEMES_NAME[0]) }}" +{% endif %} diff --git a/tutorpicasso/patches/lms-env b/tutorpicasso/patches/lms-env new file mode 100644 index 0000000..ad8b8d9 --- /dev/null +++ b/tutorpicasso/patches/lms-env @@ -0,0 +1,3 @@ +{%- if PICASSO_DEFAULT_SITE_THEME is defined or PICASSO_THEMES_NAME is defined %} +DEFAULT_SITE_THEME: "{{ PICASSO_DEFAULT_SITE_THEME | default(PICASSO_THEMES_NAME[0]) }}" +{% endif %} diff --git a/tutorpicasso/patches/openedx-cms-production-settings b/tutorpicasso/patches/openedx-cms-production-settings new file mode 100644 index 0000000..d1c601c --- /dev/null +++ b/tutorpicasso/patches/openedx-cms-production-settings @@ -0,0 +1,6 @@ +{% if PICASSO_THEMES is defined -%} +ENABLE_COMPREHENSIVE_THEMING = True +{%- endif %} +{% if PICASSO_THEME_DIRS is defined -%} +COMPREHENSIVE_THEME_DIRS.extend({{ PICASSO_THEME_DIRS }}) +{%- endif %} diff --git a/tutorpicasso/patches/openedx-common-assets-settings b/tutorpicasso/patches/openedx-common-assets-settings new file mode 100644 index 0000000..7645076 --- /dev/null +++ b/tutorpicasso/patches/openedx-common-assets-settings @@ -0,0 +1,3 @@ +{%- if PICASSO_THEME_DIRS is defined %} +COMPREHENSIVE_THEME_DIRS.extend({{ PICASSO_THEME_DIRS }}) +{%- endif %} diff --git a/tutorpicasso/patches/openedx-development-settings b/tutorpicasso/patches/openedx-development-settings new file mode 100644 index 0000000..8404f25 --- /dev/null +++ b/tutorpicasso/patches/openedx-development-settings @@ -0,0 +1,6 @@ +{% if PICASSO_THEMES is defined -%} +ENABLE_COMPREHENSIVE_THEMING = True +{%- endif %} +{%- if PICASSO_THEME_DIRS is defined %} +COMPREHENSIVE_THEME_DIRS.extend({{ PICASSO_THEME_DIRS }}) +{%- endif %} diff --git a/tutorpicasso/patches/openedx-dockerfile-pre-assets b/tutorpicasso/patches/openedx-dockerfile-pre-assets new file mode 100644 index 0000000..a04fd50 --- /dev/null +++ b/tutorpicasso/patches/openedx-dockerfile-pre-assets @@ -0,0 +1,40 @@ +{% if TUTOR_VERSION is defined and PICASSO_THEME_DIRS is defined and PICASSO_THEMES_NAME is defined %} +{% set redwood_version = 'v18.0.0'.lstrip('v').split('.') %} +{% set current_version = TUTOR_VERSION.lstrip('v').split('.') %} +{% set redwood_version = redwood_version | map('int') | list %} +{% set current_version = current_version | map('int') | list %} + +COPY --chown=app:app ./themes/ /openedx/themes +{% if (current_version[0] < redwood_version[0]) %} +# This compiles the Picasso themes assets in the releases < redwood. + +# These commands are already in the Dockerfile Tutor template, +# but we needed them for the Picasso themes compilation. +ENV NO_PYTHON_UNINSTALL 1 +ENV NO_PREREQ_INSTALL 1 +RUN openedx-assets xmodule \ + && openedx-assets npm \ + && openedx-assets webpack --env=prod \ + && openedx-assets common +# Compiling the Picasso themes. +RUN openedx-assets themes \ + --theme-dirs {{ PICASSO_THEME_DIRS | join(' ') }} \ + --themes {{ PICASSO_THEMES_NAME | join(' ') }} \ + && openedx-assets collect --settings=tutor.assets \ + && rdfind -makesymlinks true -followsymlinks true /openedx/staticfiles/ +{% else %} +# This compiles the Picasso themes assets from the redwood release. + +# These commands are already in the Dockerfile Tutor template, +# but we needed them for the Picasso themes compilation. +RUN npm run postinstall +RUN npm run compile-sass -- --skip-themes +RUN npm run webpack +# Compiling the Picasso themes. +RUN npm run compile-sass -- \ + --theme-dir {{ PICASSO_THEME_DIRS | join(' --theme-dir ') }} \ + --theme {{ PICASSO_THEMES_NAME | join(' --theme ') }} \ + && ./manage.py lms collectstatic --noinput --settings=tutor.assets \ + && rdfind -makesymlinks true -followsymlinks true /openedx/staticfiles/ +{% endif %} +{% endif %} diff --git a/tutorpicasso/patches/openedx-lms-production-settings b/tutorpicasso/patches/openedx-lms-production-settings new file mode 100644 index 0000000..d1c601c --- /dev/null +++ b/tutorpicasso/patches/openedx-lms-production-settings @@ -0,0 +1,6 @@ +{% if PICASSO_THEMES is defined -%} +ENABLE_COMPREHENSIVE_THEMING = True +{%- endif %} +{% if PICASSO_THEME_DIRS is defined -%} +COMPREHENSIVE_THEME_DIRS.extend({{ PICASSO_THEME_DIRS }}) +{%- endif %}