Skip to content

Commit 9be70cc

Browse files
committed
feat: full edx-platform setup with tutor dev launch -m ...
Before this commit, setting up an edx-platform development environment took multiple steps: tutor dev launch tutor dev run --mount=/path/to/edx-platform lms bash >> pip install -e . >> npm clean-install >> openedx-assets build --env=dev This commit moves the steps under ``run`` into an init task, which is automatically run by ``launch``. Thus, setup is now one command: tutor dev launch --mount=edx-platform These extra init steps are only applicable when bind-mounting edx-platform (because bind-mounting the repository overrides some important artifacts that exist on the image, which must be re-generated). Thus, the new init tasks exists early if it detects that it is *not* operating on a bind-mounted repository. Finally, we try to simplify the Open edX development docs so that it is clearer how bind-mounting fits into the development process. Part of: openedx-unsupported/wg-developer-experience#146 Closes: openedx-unsupported/wg-developer-experience#152 This works around (but does not close) these related issues: * openedx-unsupported/wg-developer-experience#150 * https://github.com/openedx/wg-developer-experience/issues/151
1 parent 4e7c3ee commit 9be70cc

File tree

5 files changed

+92
-48
lines changed

5 files changed

+92
-48
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Improvement] Running ``tutor dev launch --mount=edx-platform`` now performs all necessary setup for a local edx-platform development. This includes running setup.py, installing node modules, and building assets; previously, those steps had to be run explicitly after bind-mounting a local copy of edx-platform (by @kdmccormick).

docs/dev.rst

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ Open edX development
55

66
In addition to running Open edX in production, Tutor can be used for local development of Open edX. This means that it is possible to hack on Open edX without setting up a Virtual Machine. Essentially, this replaces the devstack provided by edX.
77

8+
.. _edx_platform_dev_env:
89

910
First-time setup
1011
----------------
1112

1213
First, ensure you have already :ref:`installed Tutor <install>` (for development against the named releases of Open edX) or :ref:`Tutor Nightly <nightly>` (for development against Open edX's master branches).
1314

14-
Then, launch the developer platform setup process::
15+
Then, run one of the following in order to launch the developer platform setup process::
1516

17+
# To use the edx-platform repository that is built into the image:
1618
tutor dev launch
1719

20+
# To bind-mount and run your local clone of edx-platform,
21+
# where './edx-platform' should be replaced with your local edx-platform's path:
22+
tutor dev launch --mount=./edx-platform
23+
1824
This will perform several tasks for you. It will:
1925

2026
* stop any existing locally-running Tutor containers,
@@ -33,12 +39,30 @@ This will perform several tasks for you. It will:
3339

3440
* run service initialization scripts, such as service user creation and Waffle configuration.
3541

42+
Additionally, if you chose to bind-mount your local clone of edx-platform, it will:
43+
44+
* re-run setup.py,
45+
46+
* clean-reinstall Node modules, and
47+
48+
* regenerate static assets.
49+
3650
Once setup is complete, the platform will be running in the background:
3751

3852
* LMS will be accessible at `http://local.overhang.io:8000 <http://local.overhang.io:8000>`_.
3953
* CMS will be accessible at `http://studio.local.overhang.io:8001 <http://studio.local.overhang.io:8001>`_.
4054
* Plugged-in services should be accessible at their documented URLs.
4155

56+
Now, you can use the ``tutor dev ...`` command-line interface to manage your development environment. Some common commands are described below.
57+
58+
.. note::
59+
60+
Wherever you see ``[-m ./edx-platform]``, either:
61+
62+
* omit it, if you are using the edx-platform repository built into the image, or
63+
* substitute it with ``-m <path/to/your/edx-platform>``.
64+
65+
You can :ref:`read more about bind-mounts below <bind_mounts>`.
4266

4367
Stopping the platform
4468
---------------------
@@ -47,38 +71,55 @@ To bring down your platform's containers, simply run::
4771

4872
tutor dev stop
4973

50-
5174
Starting the platform back up
5275
-----------------------------
5376

54-
Once you have used ``launch`` once, you can start the platform in the future with the lighter-weight ``start`` command, which brings up containers but does not perform any initialization tasks::
77+
Once you have used ``launch`` once, you can start the platform in the future with the lighter-weight ``start -d`` command, which brings up containers detached (i.e., in the background), but does not perform any initialization tasks::
5578

56-
tutor dev start # Run platform in the same terminal ("attached")
57-
tutor dev start -d # Or, run platform the in the background ("detached")
79+
tutor dev start -d [-m ./edx-platform]
5880

5981
Nonetheless, ``launch`` is idempotent, so it is always safe to run it again in the future without risk to your data. In fact, you may find it useful to use this command as a one-stop-shop for pulling images, running migrations, initializing new plugins you have enabled, and/or executing any new initialization steps that may have been introduced since you set up Tutor::
6082

61-
tutor dev launch --pullimages
83+
tutor dev launch [-m ./edx-platform] --pullimages
84+
85+
Attaching to containers
86+
-----------------------
87+
88+
You can run ``start`` without the ``-d`` flag::
89+
90+
tutor dev start [-m ./edx-platform]
91+
92+
If the platform isn't running, this will start it in your terminal. If the platform is already running in the background, this command will stop it, recreate it, and attach your terminal to it. Later, you can stop the platform with ``Ctrl+c``, or detach (without stopping) using ``Ctrl+z``.
93+
94+
Debugging with breakpoints
95+
--------------------------
96+
97+
To debug a local edx-platform repository, you can add a `python breakpoint <https://docs.python.org/3/library/functions.html#breakpoint>`__ with ``breakpoint()`` anywhere in your code. Then, run ``start`` (without ``-d``) and specify the service through which you want to use the breakpoint, for example::
98+
99+
# Debugging LMS:
100+
tutor dev start [-m ./edx-platform] lms
62101

102+
# Or, debugging CMS:
103+
tutor dev start [-m ./edx-platform] cms
63104

64105
Running arbitrary commands
65106
--------------------------
66107

67108
To run any command inside one of the containers, run ``tutor dev run [OPTIONS] SERVICE [COMMAND] [ARGS]...``. For instance, to open a bash shell in the LMS or CMS containers::
68109

69-
tutor dev run lms bash
70-
tutor dev run cms bash
110+
tutor dev run [-m ./edx-platform] lms bash
111+
tutor dev run [-m ./edx-platform] cms bash
71112

72113
To open a python shell in the LMS or CMS, run::
73114

74-
tutor dev run lms ./manage.py lms shell
75-
tutor dev run cms ./manage.py cms shell
115+
tutor dev run [-m ./edx-platform] lms ./manage.py lms shell
116+
tutor dev run [-m ./edx-platfomr] cms ./manage.py cms shell
76117

77118
You can then import edx-platform and django modules and execute python code.
78119

79-
To collect assets, you can use the ``openedx-assets`` command that ships with Tutor::
120+
To rebuild assets, you can use the ``openedx-assets`` command that ships with Tutor::
80121

81-
tutor dev run lms openedx-assets build --env=dev
122+
tutor dev run [-m ./edx-platform] lms openedx-assets build --env=dev
82123

83124

84125
.. _specialized for developer usage:
@@ -193,42 +234,6 @@ This override file will be loaded when running any ``tutor dev ..`` command. The
193234
Common tasks
194235
------------
195236

196-
.. _edx_platform_dev_env:
197-
198-
Setting up a development environment for edx-platform
199-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200-
201-
Following the instructions :ref:`above <bind_mounts>` on how to bind-mount directories from the host above, you may mount your own `edx-platform <https://github.com/openedx/edx-platform/>`__ fork in your containers by running::
202-
203-
tutor dev start -d --mount=/path/to/edx-platform lms
204-
205-
But to achieve that, you will have to make sure that your fork works with Tutor.
206-
207-
First of all, you should make sure that you are working off the latest release tag (unless you are running the Tutor :ref:`nightly <nightly>` branch). See the :ref:`fork edx-platform section <edx_platform_fork>` for more information.
208-
209-
Then, you should run the following commands::
210-
211-
# Run bash in the lms container
212-
tutor dev run --mount=/path/to/edx-platform lms bash
213-
214-
# Compile local python requirements
215-
pip install --requirement requirements/edx/development.txt
216-
217-
# Install nodejs packages in node_modules/
218-
npm clean-install
219-
220-
# Rebuild static assets
221-
openedx-assets build --env=dev
222-
223-
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 <https://docs.python.org/3/library/functions.html#breakpoint>`__ with ``breakpoint()`` anywhere in your code and run::
224-
225-
tutor dev start --mount=/path/to/edx-platform lms
226-
227-
The default debugger is ``ipdb.set_trace``. ``PYTHONBREAKPOINT`` can be modified by setting an environment variable in the Docker imamge.
228-
229-
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``.
230-
231-
232237
XBlock and edx-platform plugin development
233238
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234239

tutor/commands/jobs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from tutor import config as tutor_config
1313
from tutor import env, fmt, hooks
14+
from tutor.hooks import priorities
1415

1516

1617
class DoGroup(click.Group):
@@ -40,6 +41,15 @@ def _add_core_init_tasks() -> None:
4041
("mysql", env.read_core_template_file("jobs", "init", "mysql.sh"))
4142
)
4243
with hooks.Contexts.APP("lms").enter():
44+
hooks.Filters.CLI_DO_INIT_TASKS.add_item(
45+
(
46+
"lms",
47+
env.read_core_template_file("jobs", "init", "mounted-edx-platform.sh"),
48+
),
49+
# If edx-platform is mounted, then we may need to perform some setup
50+
# before other initialization scripts can be run.
51+
priority=priorities.HIGH,
52+
)
4353
hooks.Filters.CLI_DO_INIT_TASKS.add_item(
4454
("lms", env.read_core_template_file("jobs", "init", "lms.sh"))
4555
)

tutor/templates/build/openedx/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ RUN openedx-assets themes \
207207
# Create a data directory, which might be used (or not)
208208
RUN mkdir /openedx/data
209209

210+
# If this "canary" file is missing from a container, then that indicates that a
211+
# local edx-platform was bind-mounted into that container, thus overwriting the
212+
# canary. This information is useful during edx-platform initialisation.
213+
RUN echo \
214+
"This copy of edx-platform was built into a Docker image." \
215+
> bindmount-canary
216+
210217
# service variant is "lms" or "cms"
211218
ENV SERVICE_VARIANT lms
212219
ENV DJANGO_SETTINGS_MODULE lms.envs.tutor.production
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# When a new local copy of edx-platform is bind-mounted, certain build
2+
# artifacts from the openedx image's edx-platform directory are lost.
3+
# We regenerate them here.
4+
5+
if [[ -f /openedx/edx-platform/bindmount-canary ]] ; then
6+
# If this file exists, then edx-platform has not
7+
# been bind mounted. That is: we are running edx-platform
8+
# from the openedx image. Thus, it is safe to skip the k
9+
# regeneration steps below.
10+
exit
11+
fi
12+
13+
# Regenerate Open_edX.egg-info
14+
pip install -e .
15+
16+
# Regenerate node_modules
17+
npm clean-install
18+
19+
# Regenerate static assets.
20+
openedx-assets build --env=dev
21+

0 commit comments

Comments
 (0)