XBlock Development
Understanding XBlock Development
There are three broad stages to writing an XBlock and deploying it to an OpenEdX server:
Creating the requisite folder structure and other important files using the XBlock SDK
Creating a git repo for your xblock
Linking the git repo to your OpenEdX server and rebuilding it
Setting up the XBlock SDK and Creating the XBlock files
This can be done on a local machine. Since everything happens over git once you get to the OpenEdX server.
Setting up the SDK
The SDK is needed to create the files and make sure your XBlock has the right directory structure
Documentation for how to set up the SDK is here:
Creating your XBlock
Next, you need to create your XBlock. Important: your XBlock must have the string “XBlock” in its name in order for the OpenEdX development environment to mount it properly. For instance, “autogradingXBlock” is fine, “autograder” is not. It is recommended to put XBlock at the end of the name. Otherwise, follow the instructions here:
This will create an empty XBlock. Note that the installation steps are not strictly required. They are for testing using the XBlock SDK server, which is neither intuitive nor a fully-implemented OpenEdX environment. You can skip that step.
Setting up a git repo
OpenEdX recommends using github and a public repo, since it makes it easier to build the docker images eventually
Navigate to the XBlock directory you just made and add everything, including all subfolders, to a git repo, then push it
Linking the git Repo to an OpenEdX Server and Building It
There are two ways to do this: using local or dev versions of the repo. If you use local, you must rebuild the entire docker image every time you make a change. This is very undesirable for development. If you use dev, you can link it to the repo so that every time something changes the changes are automatically reflected without rebuilding. I have not successfully gotten the dev part to work.
Loading it into Dev
Note: I have not yet gotten this to work. The process involves rebuilding the dev containers, which takes a long time, but you only have to do it once. If it works correctly, the dev container that was built with the XBlock will monitor the directory for changes to the code and automatically reload the XBlock when changes are made.
Steps that only have to happen once per XBlock
Begin by stopping all currently running instances with the following command: tutor dev stop
Clone your git repo for your XBlock onto the machine that is running the OpenEdX dev server
Mount the directory the XBlock was cloned into by running the following command:
tutor mounts add path-to-your-xblock
Rebuild the dev container:
tutor images build openedx-dev
Running the Server with Automatic Reloading
To run the server, use the command: tutor dev start -d
This should automatically reload any changes to the XBlock once they are made
Loading it into local
If you are using tutor local to launch this, for instance to test in a production-like environment, the process involves linking the git repo to the docker images then rebuilding the entire set of docker containers, and finally relaunching the OpenEdX instance.
Begin by stopping all currently running instances with the following command: tutor local stop
Add the git repo to the OpenEdX docker files. For example, say that we have our XBlock at the repo github.com/open-craft-xblock-poll.git (this is from an example in the documentation linked below). Then we would run the following command:
tutor config save --append OPENEDX_EXTRA_PIP_REQUIREMENTS=git+https://github.com/open-craft/xblock-poll.git
Rebuild the docker containers by running the following command: tutor images build openedx
Restart the server by running: tutor local start (or tutor local launch if that doesn’t work)
At this point, your XBlock will be loaded and accessible in a course.