Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

kdmccormick
Copy link
Member

@kdmccormick kdmccormick commented Jun 3, 2024

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.

@kdmccormick kdmccormick force-pushed the kdmccormick/assets-split branch 2 times, most recently from 8688fd7 to 2f4bcf0 Compare June 4, 2024 13:46
@kdmccormick kdmccormick changed the title Support symlinks to static asset build artifacts build: allow symlinks to be used in place of static asset artifacts Jun 4, 2024
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.
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.
@kdmccormick kdmccormick marked this pull request as ready for review June 4, 2024 14:30
Copy link
Contributor

@feanil feanil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and was able to bring up the LMS and load up static assets without any issues.

@kdmccormick kdmccormick merged commit 1f41529 into openedx:master Jun 4, 2024
45 checks passed
@kdmccormick kdmccormick deleted the kdmccormick/assets-split branch June 4, 2024 15:48
@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

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

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

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

@edx-pipeline-bot
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants