From 274432436fc62675fd424e5455bebc7b658b6adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Tue, 20 Nov 2018 11:24:34 +0100 Subject: [PATCH] Fix assets generation in development webpack requires the NODE_ENV environment variable which is incorrectly set "paver update_assets" in development mode. To avoid this issue, we split update_assets into its subparts. --- Makefile | 44 ++++++++++++++++++++++++++++++++++++++------ README.md | 7 +++++-- openedx/Dockerfile | 7 +++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 772cc74..43f4da9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all android configure build update migrate assets run daemonize +.PHONY: all android configure build update migrate run .DEFAULT_GOAL := help @@ -95,11 +95,43 @@ reindex-courses: ## Refresh course index so they can be found in the LMS search ##################### Static assets -assets: assets-lms assets-cms ## Collect static assets for the LMS and the CMS -assets-lms: ## Collect static assets for the LMS - $(DOCKER_COMPOSE_RUN_OPENEDX) -e NO_PREREQ_INSTALL=True lms paver update_assets lms --settings=$(EDX_PLATFORM_SETTINGS) -assets-cms: ## Collect static assets for the CMS - $(DOCKER_COMPOSE_RUN_OPENEDX) -e NO_PREREQ_INSTALL=True cms paver update_assets cms --settings=$(EDX_PLATFORM_SETTINGS) +# To collect assets we don't rely on the "paver update_assets" command because +# webpack collection incorrectly sets the NODE_ENV variable when using custom +# settings. Thus, each step must be performed separately. This should be fixed +# in the next edx-platform release thanks to https://github.com/edx/edx-platform/pull/18430/ +#assets-lms: ## Collect static assets for the LMS + #$(DOCKER_COMPOSE_RUN_OPENEDX) lms -e NO_PREREQ_INSTALL=True lms paver update_assets lms --settings=$(EDX_PLATFORM_SETTINGS) +#assets-cms: ## Collect static assets for the CMS + #$(DOCKER_COMPOSE_RUN_OPENEDX) cms -e NO_PREREQ_INSTALL=True cms paver update_assets cms --settings=$(EDX_PLATFORM_SETTINGS) + +assets: assets-lms assets-cms ## Generate production-ready static assets +assets-development: assets-development-lms assets-development-cms ## Generate static assets for local development + +assets-lms: + $(DOCKER_COMPOSE_RUN_OPENEDX) lms bash -c \ + "NODE_ENV=production ./node_modules/.bin/webpack --config=webpack.prod.config.js \ + && ./manage.py lms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass lms \ + && python -c \"import pavelib.assets; pavelib.assets.collect_assets(['lms'], '$(EDX_PLATFORM_SETTINGS)')\"" +assets-cms: + $(DOCKER_COMPOSE_RUN_OPENEDX) cms bash -c \ + "NODE_ENV=production ./node_modules/.bin/webpack --config=webpack.prod.config.js \ + && ./manage.py cms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass studio \ + && python -c \"import pavelib.assets; pavelib.assets.collect_assets(['studio'], '$(EDX_PLATFORM_SETTINGS)')\"" +assets-development-lms: + $(DOCKER_COMPOSE_RUN_OPENEDX) lms bash -c \ + "xmodule_assets common/static/xmodule \ + && python -c \"import pavelib.assets; pavelib.assets.process_npm_assets()\" + && NODE_ENV=development ./node_modules/.bin/webpack --config=webpack.dev.config.js \ + && ./manage.py lms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass lms \ + && python -c \"import pavelib.assets; pavelib.assets.collect_assets(['lms'], '$(EDX_PLATFORM_SETTINGS)')\"" +assets-development-cms: + $(DOCKER_COMPOSE_RUN_OPENEDX) cms bash -c \ + "xmodule_assets common/static/xmodule \ + && python -c \"import pavelib.assets; pavelib.assets.process_npm_assets()\" + && NODE_ENV=development ./node_modules/.bin/webpack --config=webpack.dev.config.js \ + && ./manage.py cms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass studio \ + && python -c \"import pavelib.assets; pavelib.assets.collect_assets(['studio'], '$(EDX_PLATFORM_SETTINGS)')\"" + ##################### Information diff --git a/README.md b/README.md index 6f6dc35..aea1d94 100644 --- a/README.md +++ b/README.md @@ -213,10 +213,13 @@ Then open an LMS shell: make lms -You can then collect assets and run a local web server, as usual: +You can then run a local web server, as usual: paver update_assets lms --settings=universal.development - ./manage.py lms runserver 0.0.0.0:8000 + +Note that assets collection is made more difficult by the fact that development settings are [incorrectly loaded in hawthorn](https://github.com/edx/edx-platform/pull/18430/files). This should be fixed in the next release. Meanwhile, do not run `paver update_assets` while in development mode. Instead, run on the host: + + make assets-development ### Custom devstack diff --git a/openedx/Dockerfile b/openedx/Dockerfile index efdcb4d..1444baa 100644 --- a/openedx/Dockerfile +++ b/openedx/Dockerfile @@ -36,6 +36,11 @@ RUN pip install --src ../venv/src -r requirements/edx/development.txt RUN npm install ENV PATH ./node_modules/.bin:${PATH} +# Some parts of assets collection can be run without relying on specific +# settings, nor mounting the staticfiles/ folder +RUN xmodule_assets common/static/xmodule +RUN python -c "import pavelib.assets; pavelib.assets.process_npm_assets()" + # Link configuration files to common /openedx/config folder, which should later # be mounted as a volume. Note that this image will not be functional until # config files have been mounted inside the container @@ -63,6 +68,8 @@ COPY ./bin/docker-entrypoint.sh /usr/local/bin/ # service variant is "lms" or "cms" ENV SERVICE_VARIANT lms ENV SETTINGS universal.production +ENV STATIC_ROOT_LMS /openedx/data/staticfiles +ENV STATIC_ROOT_CMS /openedx/data/staticfiles/studio # Entrypoint will fix permissiosn of all files and run commands as openedx ENTRYPOINT ["docker-entrypoint.sh"]