openedx / edx-platform

The Open edX LMS & Studio, powering education sites around the world!
https://openedx.org
GNU Affero General Public License v3.0
7.11k stars 3.8k forks source link

build: allow symlinks to be used in place of static asset artifacts #34894

Closed kdmccormick closed 1 month ago

kdmccormick commented 1 month ago

Description

This PR supports an experimental optimization to tutor dev mode. Specifically, it will allow us to build static assets outside of edx-platform, and symlink to those externally-built assets from within edx-platform. For example, today, CSS compiled to:

./cms/static/css/
./lms/static/css/
./lms/certificates/static/css/

With this change, we could have:

./cms/static/css -> ../artifacts/cms/static/css/
./lms/static/css  -> ../artifacts/lms/static/css/
./lms/certificates/static/css -> ../artifacts/lms/certificates/css/

In Tutor, this would allow us to build static assets once, and then re-use them whether the developer wants to run a pre-built edx-platform clone or a bind-mounted local repository (currently, to use a bind-mounted local repo, the developer must re-build the assets locally, wasting time and bandwidth).

Regardless of Tutor, I believe the changes are also generally good for edx-platform's build story.

The changes are broken into two commits:

build: lms/static/css/vendor/* -> common/static/css/vendor

The git-ignored target directory for LMS Sass compilation is:

lms/static/css

Unfortunately, that directory contains git-controlled directory of vendored-in static assets:

lms/static/css/vendor

This is a problem for a couple reasons:

  1. In Tutor, we would like to make lms/static/css a symlink to an external location for the sake of build efficiency. This is impossible to do without clobbering lms/static/css/vendor and dirtying the git state.

  2. More generally, when optimizing (or just understanding) a build system, it adds complexity when git-controlled source directories are mixed up inside git-ignored target directories.

The solution is to simply merge these vendored-in assets to another existing git-controlled vendor directory:

common/static/css/vendor

LMS already reads assets from this folder, so no further changes need to be made. common/static/css is fully git-controlled, so we avoid the complexity described above.

build: git-ignore static asset artifacts whether they are links or dirs

Remove the trailing slashes from the .gitignore entries for static asset build artifacts. With these slashes, only directory contents are ignored. Without these slashes, the artifact is ignored whether it is a directory or an actual file (particularly, in our case: a symlink).

This allows us to build edx-platform static assets into a separate directory, and then symlink to them from edx-platform.

Also: We remove the duplicate cms/static/css/ gitignore entry.

Testing

I've smoke-tested the build and basic legacy LMS/Studio frontend functionality with this branch.

Merge considerations

I'd like to merge this by Jun 6 so that I can backport it to Redwood. That way, we can utilize it as an optimization in minor Tutor v18 (Redwood-based) release.

This should be fully backwards-compatible. This will have zero effect on folks who don't use symlinks for static assets.

Even if the downstream experimental Tutor change does not work out, I think this change will be good to have in edx-platform.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX production environment.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX production environment.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX production environment.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

edx-pipeline-bot commented 1 month ago

2U Release Notice: This PR has been deployed to the edX production environment.