diff --git a/tutor/commands/compose.py b/tutor/commands/compose.py index 7484dc6d592..8e66c6d46ff 100644 --- a/tutor/commands/compose.py +++ b/tutor/commands/compose.py @@ -114,23 +114,6 @@ def launch( click.echo(fmt.title("Docker image updates")) context.invoke(dc_command, command="pull") - # TODO: Find a way to do this that doesn't hard-code understanding of lms and the edx-platform repo? - asset_targets = [ - "node_modules", - "lms/static/css", - "lms/static/certificates/css", - "cms/static/css", - "common/static/bundles", - ] - if not run_for_prod: - if "edx-platform" in bindmount.get_mounts(config): - _, host_path, container_path = bindmount.parse_mount("edx-platform")[0] - click.echo(fmt.title("Copying generated assets from image to bind-mounted repo.")) - for target in asset_targets: - context.invoke(f"echo bash -c 'if [[ -d {target} ]] ; then mv {target} {target.bak} ; fi'") - context.invoke(dc_command, command="cp", args=["--dry-run", f"lms:{host_path}/{target}", f"{host_path}/{target}"]) - return - click.echo(fmt.title("Starting the platform in detached mode")) context.invoke(start, detach=True) diff --git a/tutor/templates/build/openedx/Dockerfile b/tutor/templates/build/openedx/Dockerfile index 47bd353a1dc..1f817018941 100644 --- a/tutor/templates/build/openedx/Dockerfile +++ b/tutor/templates/build/openedx/Dockerfile @@ -66,6 +66,7 @@ FROM minimal as code ###### Checkout edx-platform code ARG EDX_PLATFORM_REPOSITORY={{ EDX_PLATFORM_REPOSITORY }} ARG EDX_PLATFORM_VERSION={{ EDX_PLATFORM_VERSION }} +RUN echo break cache 200 RUN mkdir -p /openedx/edx-platform && \ git clone $EDX_PLATFORM_REPOSITORY --branch $EDX_PLATFORM_VERSION --depth 1 /openedx/edx-platform WORKDIR /openedx/edx-platform @@ -425,10 +426,10 @@ FROM application as production # Copy in and collect production static assets. COPY --chown=app:app --from=bundles-production /openedx/staticfiles /openedx/staticfiles -COPY --chown=app:app --from=bundles-production /openedx/edx-platform/common/static/bundles common/static/bundles -COPY --chown=app:app --from=css-production /openedx/edx-platform/lms/static/css lms/static/css -COPY --chown=app:app --from=css-production /openedx/edx-platform/lms/static/certificates/css ms/static/certificates/css -COPY --chown=app:app --from=css-production /openedx/edx-platform/cms/static/css cms/static/css +COPY --chown=app:app --from=bundles-production /openedx/edx-platform/common/static/bundles /openedx/edx-platform/common/static/bundles +COPY --chown=app:app --from=css-production /openedx/edx-platform/lms/static/css /openedx/edx-platform/lms/static/css +COPY --chown=app:app --from=css-production /openedx/edx-platform/lms/static/certificates/css /openedx/edx-platform/lms/static/certificates/css +COPY --chown=app:app --from=css-production /openedx/edx-platform/cms/static/css /openedx/edx-platform/cms/static/css RUN ./manage.py lms collectstatic --noinput --settings=tutor.assets RUN ./manage.py cms collectstatic --noinput --settings=tutor.assets @@ -475,13 +476,20 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \ ENV PYTHONBREAKPOINT=ipdb.set_trace # Copy in development static assets. -# In development mode, edx-platform expects the files to be in the repo, and pointed to by webpack-stats.json. +# In development mode, edx-platform expects the files to be in the repo, and pointed to by webpack-stats.json... COPY --chown=app:app --from=bundles-development /openedx/staticfiles/webpack-stats.json /openedx/staticfiles/webpack-stats.json COPY --chown=app:app --from=bundles-development /openedx/staticfiles/studio/webpack-stats.json /openedx/staticfiles/studio/webpack-stats.json -COPY --chown=app:app --from=bundles-development /openedx/edx-platform/common/static/bundles common/static/bundles -COPY --chown=app:app --from=css-development /openedx/edx-platform/lms/static/css lms/static/css -COPY --chown=app:app --from=css-development /openedx/edx-platform/lms/static/certificates/css lms/static/certificates/css -COPY --chown=app:app --from=css-development /openedx/edx-platform/cms/static/css cms/static/css + +# ...however, we instead copy the files into the /openedx/devcache directory; otherwise, bind-mounting edx-platform +# would clobber them and force the user to rebuild assets. +COPY --chown=app:app --from=bundles-development /openedx/edx-platform/common/static/bundles /openedx/devcache/common/static/bundles +COPY --chown=app:app --from=css-development /openedx/edx-platform/lms/static/css /openedx/devcache/lms/static/css +COPY --chown=app:app --from=css-development /openedx/edx-platform/lms/static/certificates/css /openedx/devcache/lms/static/certificates/css +COPY --chown=app:app --from=css-development /openedx/edx-platform/cms/static/css /openedx/devcache/cms/static/css +RUN mv node_modules /openedx/devcache/node_modules + +# Create links for static dirs from edx-platform to devcache. +RUN link-static-to-devcache {{ patch("openedx-dev-dockerfile-post-python-requirements") }} diff --git a/tutor/templates/build/openedx/bin/link-static-to-devcache b/tutor/templates/build/openedx/bin/link-static-to-devcache new file mode 100755 index 00000000000..f90ed5e6cd1 --- /dev/null +++ b/tutor/templates/build/openedx/bin/link-static-to-devcache @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +cd /openedx/edx-platform + +for path in node_modules common/static/bundles lms/static/css lms/static/certificates/css cms/static/css ; do + if [[ -L "$path" ]] ; then + rm -rf "$path" + elif [[ -e "$path" ]] ; then + mv "$path" "${path}.bak" + fi + ln -s "/openedx/devcache/$path" "$path" +done diff --git a/tutor/templates/jobs/init/mounted-edx-platform.sh b/tutor/templates/jobs/init/mounted-edx-platform.sh index 6fde238e5a1..f5b1dbbe88b 100644 --- a/tutor/templates/jobs/init/mounted-edx-platform.sh +++ b/tutor/templates/jobs/init/mounted-edx-platform.sh @@ -16,8 +16,11 @@ set -x # Echo out executed lines # Regenerate Open_edX.egg-info pip install -e . -# Regenerate node_copies -npm postinstall +# Regenerate node_modules +npm clean-install + +# Link to static assets in dev image. +link-static-to-devcache set -x echo "Done setting up bind-mounted edx-platform."