From ff320c62a1c091a6c6954e1c23ebee0148292277 Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 17 Oct 2023 13:48:19 -0400 Subject: [PATCH] build: switch to new edx-platform asset build TODO: * Test dev & prod builds one last time * Test watching again * Print warning in openedx-assets * Add REMOVE-AFTER-VXX comments * Update docs Part of: https://github.com/openedx/edx-platform/issues/31895 --- tutor/templates/build/openedx/Dockerfile | 31 +++++++------------ .../build/openedx/bin/openedx-assets | 4 +++ tutor/templates/dev/docker-compose.yml | 2 +- .../jobs/init/mounted-edx-platform.sh | 2 +- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/tutor/templates/build/openedx/Dockerfile b/tutor/templates/build/openedx/Dockerfile index 0f0aa66f4e..5e94d164ce 100644 --- a/tutor/templates/build/openedx/Dockerfile +++ b/tutor/templates/build/openedx/Dockerfile @@ -206,26 +206,19 @@ ENV PATH /openedx/bin:${PATH} {{ patch("openedx-dockerfile-pre-assets") }} -# Collect production assets. By default, only assets from the default theme +# Build & collect production assets. By default, only assets from the default theme # will be processed. This makes the docker image lighter and faster to build. -# Only the custom themes added to /openedx/themes will be compiled. -# Here, we don't run "paver update_assets" which is slow, compiles all themes -# and requires a complex settings file. Instead, we decompose the commands -# and run each one individually to collect the production static assets to -# /openedx/staticfiles. -ENV NO_PYTHON_UNINSTALL 1 -ENV NO_PREREQ_INSTALL 1 -# We need to rely on a separate openedx-assets command to accelerate asset processing. -# For instance, we don't want to run all steps of asset collection every time the theme -# is modified. -RUN openedx-assets xmodule \ - && openedx-assets npm \ - && openedx-assets webpack --env=prod \ - && openedx-assets common +RUN npm run compile-sass -- --skip-themes +RUN npm run webpack + +# Now that the default theme is built, build any custom themes in /openedx/themes. COPY --chown=app:app ./themes/ /openedx/themes/ -RUN openedx-assets themes \ - && openedx-assets collect --settings=tutor.assets \ - # De-duplicate static assets with symlinks +RUN npm run compile-sass -- --theme-dir /openedx/themes + +# and finally, collect assets for the production image. +RUN ./manage.py lms collectstatic --noinput && \ + ./manage.py cms collectstatic --noinput && \ + # De-duplicate static assets with symlinks \ && rdfind -makesymlinks true -followsymlinks true /openedx/staticfiles/ # Create a data directory, which might be used (or not) @@ -273,7 +266,7 @@ ENV PYTHONBREAKPOINT=ipdb.set_trace # static assets, then production assets will be served instead. RUN rm -r /openedx/staticfiles && \ mkdir /openedx/staticfiles && \ - openedx-assets webpack --env=dev + npm run build-dev {{ patch("openedx-dev-dockerfile-post-python-requirements") }} diff --git a/tutor/templates/build/openedx/bin/openedx-assets b/tutor/templates/build/openedx/bin/openedx-assets index 1b89434d67..e818394d28 100755 --- a/tutor/templates/build/openedx/bin/openedx-assets +++ b/tutor/templates/build/openedx/bin/openedx-assets @@ -1,4 +1,8 @@ #! /usr/bin/env python + +# This script has been replaced by `npm run build`, et al, in edx-platform. +# REMOVE-AFTER-V17 + from __future__ import print_function import argparse import os diff --git a/tutor/templates/dev/docker-compose.yml b/tutor/templates/dev/docker-compose.yml index 4b8cd38c9b..9070f7f2d6 100644 --- a/tutor/templates/dev/docker-compose.yml +++ b/tutor/templates/dev/docker-compose.yml @@ -49,7 +49,7 @@ services: # Additional service for watching theme changes watchthemes: <<: *openedx-service - command: openedx-assets watch-themes --env dev + command: npm run watch restart: unless-stopped {{ patch("local-docker-compose-dev-services")|indent(2) }} diff --git a/tutor/templates/jobs/init/mounted-edx-platform.sh b/tutor/templates/jobs/init/mounted-edx-platform.sh index 9516654ff5..c8d45695af 100644 --- a/tutor/templates/jobs/init/mounted-edx-platform.sh +++ b/tutor/templates/jobs/init/mounted-edx-platform.sh @@ -20,7 +20,7 @@ pip install -e . npm clean-install # Regenerate static assets. -openedx-assets build --env=dev +npm run build-dev set -x echo "Done setting up bind-mounted edx-platform."