Skip to content

Commit

Permalink
experimenting with npm prefix and assets
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Sep 15, 2022
1 parent 1a76f7c commit ff43278
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
37 changes: 20 additions & 17 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM docker.io/ubuntu:20.04 as minimal
LABEL maintainer="Overhang.io <contact@overhang.io>"

ENV DEBIAN_FRONTEND=noninteractive
# TODO: Should we rm apt lists here?
# TODO: Safe/effective to rm var/lib/apt/lists in all these places?
RUN apt update && \
apt install -y \
build-essential \
Expand Down Expand Up @@ -67,6 +67,7 @@ RUN dockerize_url="https://github.com/powerman/dockerize/releases/download/$DOCK
FROM minimal as code
ARG EDX_PLATFORM_REPOSITORY={{ EDX_PLATFORM_REPOSITORY }}
ARG EDX_PLATFORM_VERSION={{ EDX_PLATFORM_VERSION }}
RUN echo BREAK CACHE 1
RUN mkdir -p /openedx/edx-platform && \
git clone $EDX_PLATFORM_REPOSITORY --branch $EDX_PLATFORM_VERSION --depth 1 /openedx/edx-platform
WORKDIR /openedx/edx-platform
Expand Down Expand Up @@ -205,15 +206,17 @@ COPY --chown=app:app --from=python-requirements /openedx/venv /openedx/venv
COPY --chown=app:app --from=python-requirements /openedx/requirements /openedx/requirements
COPY --chown=app:app --from=nodejs-requirements /openedx/nodeenv /openedx/nodeenv
COPY --chown=app:app --from=nodejs-requirements /openedx/edx-platform/node_modules /openedx/node_modules
RUN mv /openedx/node_modules/.bin /openedx/node_modules/bin

ENV PATH /openedx/venv/bin:./node_modules/.bin:/openedx/nodeenv/bin:${PATH}
# Enable venv & nodeenv
ENV PATH /openedx/venv/bin:/openedx/node_modules/bin:/openedx/nodeenv/bin:${PATH}
ENV VIRTUAL_ENV /openedx/venv/
WORKDIR /openedx/edx-platform
# Ensure node modules exist outside of edx-platform repository.
# That way, when a developer mounts a fork of edx-platform, they don't need to
# re-run `npm install` themselves, because the pre-built node_modules folder will
# still be available on the image.
RUN ln -s /openedx/node_modules

# Copy scripts and put them on the path.
COPY --chown=app:app ./bin /openedx/bin
RUN chmod a+x /openedx/bin/*
ENV PATH /openedx/bin:${PATH}

# Generate Open-edX.egg_info by installing edx-platform itself.
# Ensures entrypoints & console scripts from setup.py are registered.
Expand Down Expand Up @@ -242,11 +245,6 @@ RUN cd /openedx/locale/user && \
RUN ./manage.py lms --settings=tutor.i18n compilejsi18n
RUN ./manage.py cms --settings=tutor.i18n compilejsi18n

# Copy scripts
COPY --chown=app:app ./bin /openedx/bin
RUN chmod a+x /openedx/bin/*
ENV PATH /openedx/bin:${PATH}

{{ patch("openedx-dockerfile-pre-assets") }}

# Collect production assets. By default, only assets from the default theme
Expand All @@ -258,14 +256,17 @@ ENV PATH /openedx/bin:${PATH}
# /openedx/staticfiles.
ENV NO_PYTHON_UNINSTALL 1
ENV NO_PREREQ_INSTALL 1

# We need to rely on a separate openedx-assets command to accelerate asset processing.
# For instance, we don't want to run all steps of asset collection every time the theme
# is modified.
# TODO: Can we remove the pavelib dependency?
RUN openedx-assets xmodule \
&& openedx-assets npm \
&& openedx-assets webpack --env=prod \
&& openedx-assets common
# TODO: OK to use scripts/update-assets-dev.sh?
RUN scripts/update-assets-dev.sh
# RUN openedx-assets xmodule \
# && openedx-assets npm \
# && openedx-assets webpack --env=prod \
# && openedx-assets common
COPY --chown=app:app ./themes/ /openedx/themes/
RUN openedx-assets themes \
&& openedx-assets collect --settings=tutor.assets \
Expand Down Expand Up @@ -317,9 +318,11 @@ RUN npm install --dev
# Recompile static assets: in development mode all static assets are stored in edx-platform,
# and the location of these files is stored in webpack-stats.json. If we don't recompile
# static assets, then production assets will be served instead.
# TODO: OK to use scripts/update-assets-dev.sh?
RUN rm -r /openedx/staticfiles && \
mkdir /openedx/staticfiles && \
openedx-assets webpack --env=dev
scripts/update-assets-dev.sh
# openedx-assets webpack --env=dev

{{ patch("openedx-dev-dockerfile-post-python-requirements") }}

Expand Down
14 changes: 14 additions & 0 deletions tutor/templates/build/openedx/bin/npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
#
# Wrapper around 'npm' for openedx image.
# Ensures that npm always operates in the 'global' /openedx/node_modules directory,
# not in the 'local' /openedx/edx-platform/node_modules directory.
#
# Rationale: We want node_modules to exist outside of the edx-platform repository.
# That way, when a developer mounts a fork of edx-platform, they don't need to
# re-run `npm install` themselves, because the pre-built node_modules folder will
# still be available on the image.

set -ue # Fail loudly.
set -x # Print next command.
/openedx/nodeenv/bin/npm --global --prefix=/openedx/node_modules "$@"

0 comments on commit ff43278

Please sign in to comment.