From a4aa01987b5cad61be8dd0cfed908db3f09e29fc Mon Sep 17 00:00:00 2001 From: "iamcristye@outlook.com" Date: Tue, 21 Jun 2022 08:37:24 +0800 Subject: [PATCH 1/3] improvement: compatibility with Docker Compose subcommand closes #641 --- CHANGELOG.md | 1 + docs/local.rst | 3 +++ tutor/utils.py | 24 +++++++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447b03f..659f5e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Every user-facing change should have an entry in this changelog. Please respect - [Bugfix] Fix smtp server port in `cms.yml` which was causing email sending failures in the Studio. (by @regisb) - [Improvement] Use `git am` instead of `cherry-pick` to simplify patching process. +- [Improvement] Tutor is now compatible with Docker Compose subcommand. ## v14.0.1 (2022-06-13) diff --git a/docs/local.rst b/docs/local.rst index c6a6a67..7ca2f0a 100644 --- a/docs/local.rst +++ b/docs/local.rst @@ -5,6 +5,9 @@ Local deployment This method is for deploying Open edX locally on a single server, where docker images are orchestrated with `docker-compose `_. +.. note:: + Tutor is compatible with the ``docker compose`` subcommand. However, this support is still in beta and we're not sure it will behave the same as the previous ``docker-compose`` command. So ``docker-compose`` will be preferred, unless you set an environment variable ``TUTOR_USE_COMPOSE_SUBCOMMAND`` to enforce using ``docker compose``. + .. _tutor_root: In the following, environment and data files will be generated in a user-specific project folder which will be referred to as the "**project root**". On Linux, the default project root is ``~/.local/share/tutor``. An alternative project root can be defined by passing the ``--root=...`` option to the ``tutor`` command, or defining the ``TUTOR_ROOT=...`` environment variable:: diff --git a/tutor/utils.py b/tutor/utils.py index 6175e6a..ac691ff 100644 --- a/tutor/utils.py +++ b/tutor/utils.py @@ -1,4 +1,5 @@ import base64 +from functools import lru_cache import json import os import random @@ -162,12 +163,25 @@ def docker(*command: str) -> int: return execute("docker", *command) +@lru_cache +def _docker_compose_command() -> Tuple[str, ...]: + """ + A helper function to determine which program to call when running docker compose + """ + if os.environ.get("TUTOR_USE_COMPOSE_SUBCOMMAND") is not None: + return ("docker", "compose") + if shutil.which("docker-compose") is not None: + return ("docker-compose",) + if shutil.which("docker") is not None: + if subprocess.run(["docker", "compose"], capture_output=True).returncode == 0: + return ("docker", "compose") + raise exceptions.TutorError( + "docker-compose is not installed. Please follow instructions from https://docs.docker.com/compose/install/" + ) + + def docker_compose(*command: str) -> int: - if shutil.which("docker-compose") is None: - raise exceptions.TutorError( - "docker-compose is not installed. Please follow instructions from https://docs.docker.com/compose/install/" - ) - return execute("docker-compose", *command) + return execute(*_docker_compose_command(), *command) def kubectl(*command: str) -> int: From 4dac13923f497b2d8f35cf19388472d5f7f6187e Mon Sep 17 00:00:00 2001 From: Carlos Muniz Date: Wed, 22 Jun 2022 05:26:50 -0400 Subject: [PATCH 2/3] feat: default to ipdb as PYTHONBREAKPOINT PYTHONBREAKPOINT has been exposed as an environment variable in the openedx Dockerfile available to be changed in config.yml. The docs have also been changed to recommend using breakpoint and explaining how PYTHONBREAKPOINT can be modified to use a custom debugger. Close https://github.com/overhangio/2u-tutor-adoption/issues/45 --- CHANGELOG.md | 1 + docs/dev.rst | 6 ++++-- tutor/templates/build/openedx/Dockerfile | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 659f5e7..450d80f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Every user-facing change should have an entry in this changelog. Please respect --> ## Unreleased +- [Feature] Add default PYTHONBREAKPOINT to openedx/Dockerfile (by @Carlos-Muniz) - [Bugfix] Fix smtp server port in `cms.yml` which was causing email sending failures in the Studio. (by @regisb) - [Improvement] Use `git am` instead of `cherry-pick` to simplify patching process. diff --git a/docs/dev.rst b/docs/dev.rst index 1d36fdb..9c6d1e8 100644 --- a/docs/dev.rst +++ b/docs/dev.rst @@ -161,7 +161,7 @@ Tutor makes it easy to create a bind-mount from an existing container. First, co tutor dev bindmount lms /openedx/venv -This command recursively copies the contents of the ``/opendedx/venv`` directory to ``$(tutor config printroot)/volumes/venv``. The code of any Python dependency can then be edited -- for instance, you can then add a ``import ipdb; ipdb.set_trace()`` statement for step-by-step debugging, or implement a custom feature. +This command recursively copies the contents of the ``/opendedx/venv`` directory to ``$(tutor config printroot)/volumes/venv``. The code of any Python dependency can then be edited -- for instance, you can then add a ``breakpoint()`` statement for step-by-step debugging, or implement a custom feature. Then, bind-mount the directory back in the container with the ``--mount`` option:: @@ -238,10 +238,12 @@ Then, you should run the following commands:: # Rebuild static assets openedx-assets build --env=dev -After running all these commands, your edx-platform repository will be ready for local development. To debug a local edx-platform repository, you can then add a ``import ipdb; ipdb.set_trace()`` breakpoint anywhere in your code and run:: +After running all these commands, your edx-platform repository will be ready for local development. To debug a local edx-platform repository, you can then add a `python breakpoint `__ with ``breakpoint()`` anywhere in your code and run:: tutor dev start --mount=/path/to/edx-platform lms +The default debugger is ``ipdb.set_trace``. ``PYTHONBREAKPOINT`` can be modified by setting an environment variable in the Docker imamge. + If LMS isn't running, this will start it in your terminal. If an LMS container is already running background, this command will stop it, recreate it, and attach your terminal to it. Later, to detach your terminal without stopping the container, just hit ``Ctrl+z``. diff --git a/tutor/templates/build/openedx/Dockerfile b/tutor/templates/build/openedx/Dockerfile index abc5b0d..045711e 100644 --- a/tutor/templates/build/openedx/Dockerfile +++ b/tutor/templates/build/openedx/Dockerfile @@ -230,6 +230,9 @@ USER app RUN pip install -r requirements/edx/development.txt RUN pip install ipdb==0.13.4 ipython==7.27.0 +# Add ipdb as default PYTHONBREAKPOINT +ENV PYTHONBREAKPOINT=ipdb.set_trace + # 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. From b13d4da1b17ff257cda34a89c02c17a84fb5289e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Wed, 22 Jun 2022 11:28:27 +0200 Subject: [PATCH 3/3] fix: @lru_cache python 3.7 compatibility In Python 3.7, which is used in the Tutor CI, the lru_cache needs an argument: https://docs.python.org/3.7/library/functools.html#functools.lru_cache On GitHub, CI did not catch this error because it is running Python 3.8. --- tutor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutor/utils.py b/tutor/utils.py index ac691ff..18a7472 100644 --- a/tutor/utils.py +++ b/tutor/utils.py @@ -163,7 +163,7 @@ def docker(*command: str) -> int: return execute("docker", *command) -@lru_cache +@lru_cache(maxsize=None) def _docker_compose_command() -> Tuple[str, ...]: """ A helper function to determine which program to call when running docker compose