Skip to content

Commit 7098198

Browse files
authored
fix: Write webpack stats file to right place (so static assets can load) (#66)
After the removal of paver, static assets build wasn't completing properly in edxapp -- static files were written to the correct directory in the assets volume (mounted under /edx/var) but the webpack-stats.json files were written to the test_root dir in the app container (under /edx/app). The service would fail on first page load as it failed to find the stats file, which is apparently used for locating resources. The static assets build was also taking quite a long time and a lot of CPU, which is likely because we were doing the production-style build with full optimization. - Set static-root environment variables so that webpack-stats.json is written to the right place. See `staticRootLms` and `staticRootCms` in `webpack.common.config.js` in edx-platform for where that default is set. Set both LMS/CMS vars for both lms and cms since there's some dependency of CMS on LMS in the logic (and both calls build both sets of files, for better or worse). - Use npm dev build for reduced optimization (faster build). - Use `--settings devstack_docker` in the Makefile call to collectstatic; I'm not actually sure what the impact of that is, but it's what was in the provisioning script's version of the call and I needed to deduplicate these calls. - Have `provision-lms.sh` just call the Makefile so that there aren't two sources of truth on how to build static assets for edxapp. Also: - Use same spelling of `--no-input` for both calls (either works, just make it uniform) Addresses #65
1 parent 9fd28f2 commit 7098198

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,14 @@ $(foreach asset_service,$(ASSET_SERVICES_LIST),\
443443

444444
dev.static: | $(_asset_compilation_targets)
445445

446+
# Put webpack-stats.json in the right place during NPM build:
447+
EDXAPP_STATIC_ROOT_ENV=STATIC_ROOT_LMS=/edx/var/edxapp/staticfiles STATIC_ROOT_CMS=/edx/var/edxapp/staticfiles/studio
448+
446449
dev.static.lms:
447-
docker compose exec -T lms bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && npm run build && ./manage.py lms collectstatic --noinput'
450+
docker compose exec -T lms bash -c "source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && $(EDXAPP_STATIC_ROOT_ENV) npm run build-dev && ./manage.py lms collectstatic --no-input --settings devstack_docker"
448451

449452
dev.static.cms:
450-
docker compose exec -T cms bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && npm run build && ./manage.py cms collectstatic --no-input'
453+
docker compose exec -T cms bash -c "source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && $(EDXAPP_STATIC_ROOT_ENV) npm run build-dev && ./manage.py cms collectstatic --no-input --settings devstack_docker"
451454

452455
dev.static.%: ## Rebuild static assets for the specified service's container.
453456
docker compose exec -T $* bash -c 'source /edx/app/$*/$*_env && cd /edx/app/$*/$*/ && make static'

docs/troubleshoot_general_tips.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,19 @@ Past problems (fixed)
276276

277277
If you see any of the following issues, you'll need to `update your repos and pull the latest images <updating devstack_>`_.
278278

279+
webpack-stats.json not found
280+
----------------------------
281+
282+
In a devstack provisioned after May 2024, loading any page in LMS would fail with::
283+
284+
OSError at /
285+
286+
Error reading /edx/var/edxapp/staticfiles/webpack-stats.json. Are you sure webpack has generated the file and the path is correct?
287+
288+
CMS would give the same error, but with path ``/edx/var/edxapp/staticfiles/studio/webpack-stats.json``. Static asset generation also took overly long and consumed more CPU than necessary.
289+
290+
This was resolved in `<https://github.com/edx/devstack/pull/66>`__ in November 2024 with an adjustment to the Makefile. Updating to a more recent devstack and re-running ``make lms-static cms-static`` should fix this, but as a quick workaround, the webpack-stats.json files can be manually moved from ``/edx/app/edxapp/edx-platform/test_root/staticfiles/{studio/,}webpack-stats.json`` to ``/edx/var/edxapp/staticfiles/{studio/,}webpack-stats.json``.
291+
279292
Permission denied for copying studio-frontend JS & CSS during provisioning
280293
--------------------------------------------------------------------------
281294

provision-lms.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ done
7979

8080
# Create static assets for both LMS and CMS
8181
for app in "${apps[@]}"; do
82-
docker compose exec -T $app bash -e -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && npm run build && ./manage.py lms collectstatic --noinput --settings devstack_docker && ./manage.py cms collectstatic --noinput --settings devstack_docker'
82+
make "dev.static.$app"
8383
done
8484

8585
# Allow LMS SSO for CMS

0 commit comments

Comments
 (0)