Skip to content

Commit

Permalink
feat: quicker & simpler build process for local packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Feb 7, 2023
1 parent 928859c commit 38c0db1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 11 deletions.
16 changes: 11 additions & 5 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,14 @@ RUN pip install uwsgi==2.0.21

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

# Copy shell scripts. Python scripts will be copied in later.
ENV PATH /openedx/bin:${PATH}
COPY ./bin/pip-install-all /openedx/bin/pip-install-all
RUN chmod a+x /openedx/bin/pip-install-all

# Install private requirements: this is useful for installing custom xblocks.
COPY ./requirements/ /openedx/requirements
RUN cd /openedx/requirements/ \
&& touch ./private.txt \
&& pip install -r ./private.txt
RUN pip-install-all /openedx/requirements

{% for extra_requirements in OPENEDX_EXTRA_PIP_REQUIREMENTS %}RUN pip install '{{ extra_requirements }}'
{% endfor %}
Expand Down Expand Up @@ -168,10 +171,9 @@ RUN cd /openedx/locale/user && \
RUN ./manage.py lms --settings=tutor.i18n compilejsi18n
RUN ./manage.py cms --settings=tutor.i18n compilejsi18n

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

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

Expand Down Expand Up @@ -224,6 +226,10 @@ RUN pip install -r requirements/edx/development.txt
# https://pypi.org/project/ipython
RUN pip install ipdb==0.13.9 ipython==8.7.0

# Install development-only private requirements
COPY --chown=app:app ./requirements-dev /openedx/requirements-dev
RUN pip-install-all /openedx/requirements-dev

# Add ipdb as default PYTHONBREAKPOINT
ENV PYTHONBREAKPOINT=ipdb.set_trace

Expand Down
36 changes: 36 additions & 0 deletions tutor/templates/build/openedx/bin/pip-install-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
# TODO: Document this

set -eu

script="$(basename "$0")"

if [ $# != 1 ] ; then
echo "$script: error: expected exactly one argument: a directory."
exit 1
fi

dir="$1"

if [ ! -d "$dir" ] ; then
echo "$script: error: not a directory: $dir"
exit 1
fi

if [ -z "$(ls -A "$dir")" ] ; then
echo "$script: $dir is empty; nothing to do"
exit 0
fi

for dir_item in "$dir"/* ; do
if [ ! -d "$dir_item" ] ; then
# skip regular files
continue
fi
# TODO: Is it right to always do editable (-e) install?
# Should we make it configurable?
set -x
pip install -e "$dir_item"
set +x
done

17 changes: 17 additions & 0 deletions tutor/templates/build/openedx/requirements-dev/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
requirements-dev
################

If you want to install a local Python package into the openedx-dev image, then:

1. Move it into this directory.
2. Reboot your development platform (``tutor dev reboot``). This will trigger the openedx-dev image to be rebuilt and containers to be recreated.

Going forward, changes to the local package's code should be automatically manifested.

To remove the local package, simply:

1. Move it out of this directory.
2. Reboot your development platform (``tutor dev reboot``).

Please note: This strategy will only affect the image for the Open edX development (``tutor dev``) environment. To install a package into all environments (``tutor dev``, ``tutor local``, ``tutor k8s``), use the `../requirements`_ directory instead.

16 changes: 16 additions & 0 deletions tutor/templates/build/openedx/requirements/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
requirements
############

If you want to install a local Python package into the openedx image, then:

1. Move it into this directory.
2. Reboot your platform (``tutor local/k8s/dev reboot``). This will trigger the openedx image to be rebuilt and containers to be recreated.

Going forward, changes to the local package's code should be automatically manifested.

To remove the local package, simply:

1. Move it out of this directory.
2. Reboot your platform (``tutor local/k8s/dev reboot``).

Tip: If you are only testing out a local package with your development environment (``tutor dev``), then you can save image build time by using `../requirements-dev`_ instead.
6 changes: 0 additions & 6 deletions tutor/templates/build/openedx/requirements/private-sample.txt

This file was deleted.

0 comments on commit 38c0db1

Please sign in to comment.