note

This is not an official guide! This is just a log of my (Kyle McCormick's) experiences running Tutor locally, both for my own reference, and for the community’s reference as we work to improve Tutor and it’s official docs via the Tutor Adoption Initiative.

This is not an official guide! This is just a log of my (Kyle McCormick's) experiences running Tutor locally, both for my own reference, and for the community’s reference as we work to improve Tutor and it’s official docs via the Tutor Adoption Initiative.

Task 1: Set up Tutor for local development

Goal

Relevant Tutor Docs

Issues Encountered

Successful Approach

# Clone edx-platform and switch to my branch.
$ git clone git@github.com:openedx/edx-platform
$ (cd edx-platform && git checkout $B)

# Install Tutor Nightly.
$ virtualenv tutor-venv
$ source tutor-venv/bin/activate
$ git clone --branch nightly git@github.com:overhangio/tutor
$ cd tutor
$ pip install -r requirements/dev.txt
$ pip install -e .

# Provision Tutor.
$ tutor local quickstart
$ tutor local stop

# Copy edx-platform virtual environment to host.
$ tutor dev start lms
$ tutor dev bindmount lms /openedx/venv
$ tutor dev stop lms
$ tutor dev dc rm

# Configure Tutor to mount your local edx-platform and virtual environment
# by writing a env/dev/docker-compose.override.yml file to your Tutor env.
# The syntax for each mount is $HOST_PATH:$DOCKER_PATH.
# Be sure to substitute in the appropriate $HOST_PATH for each mount.
$ cat > $(tutor config printroot)/env/dev/docker-compose.override.yml <<- EOF
version: "3.7"
services:
  lms:
    volumes:
      - /home/kyle/openedx/edx-platform:/openedx/edx-platform
      - /home/kyle/.local/share/tutor-nightly/volumes/venv:/openedx/venv
  cms:
    volumes:
      - /home/kyle/openedx/edx-platform:/openedx/edx-platform
      - /home/kyle/.local/share/tutor-nightly/volumes/venv:/openedx/venv
  lms-worker:
    volumes:
      - /home/kyle/openedx/edx-platform:/openedx/edx-platform
      - /home/kyle/.local/share/tutor-nightly/volumes/venv:/openedx/venv
  cms-worker:
    volumes:
      - /home/kyle/openedx/edx-platform:/openedx/edx-platform
      - /home/kyle/.local/share/tutor-nightly/volumes/venv:/openedx/venv
EOF

# Install requirements, provision demo course, admin user and static assets.
$ tutor dev run lms make requirements
$ tutor dev run lms npm install
$ tutor dev run lms openedx-assets build --env=dev
$ tutor dev createuser admin admin@example.com --password admin --staff --superuser
$ tutor dev importdemocourse

# (NOT REQUIRED - JUST EXAMPLES) Run tests, linting, and a management command.
$ tutor dev run lms pytest path/to/some/code
$ tutor dev run lms pylint path/to/some/code
$ tutor dev run lms ./manage.py lms run_some_management_command
                            
# Run LMS and CMS.
$ tutor dev start -d lms cms

Suggested Improvements

This was just a first pass at suggested improvements. We’ve been iterating these ideas in some GitHub issues:

# Clone edx-platform and switch to my branch.
$ git clone git@github.com:openedx/edx-platform
$ (cd edx-platform && git checkout $B)

# Install Tutor Nightly.
$ virtualenv tutor-venv
$ source tutor-venv/bin/activate
# Either:
 $ git clone --branch nightly git@github.com:overhangio/tutor
 $ cd tutor
 $ make requirements
# OR:
 # tutor-nightly could be a metapackage depending on the latest nightly (`N.dev`) tutor release
 $ pip install tutor-nightly

# Configure mounting:
#   * from my edx-platform to the container's /openedx/edx-platform, and
#   * from the default location in tutor-nightly config to /openedx/venv.
$ tutor config save --set OPENEDX_MOUNTS=/home/kyle/openedx/edx-platfrom:/openedx/edx-platform,/openedx/venv

# Provision Tutor, to include a default user as well as static assets.
$ tutor dev quickinit

# Run tests, linting, and a management command.
$ tutor dev run bash
app@lms$ pytest path/to/some/code
app@lms$ pylint path/to/some/code
app@lms$ ./manage.py lms run_some_management_command
app@lms$ exit
                            
# Run LMS, with virtual environment and application code from host.
$ tutor dev runserver -d lms cms

Task 2: Set up Tutor in a local Kubernetes (k8s) cluster

Goal

Run LMS, CMS and the Learning MFE in a k8s cluster on my local machine using Tutor

Relevant Tutor Docs

https://docs.tutor.overhang.io/k8s.html

Notes

Stream of consciousness… follow-up items are denoted with (blue star)

References

1: Old pods aren't getting destroyed

$  tutor k8s start mfe
kubectl get namespaces openedx
NAME      STATUS   AGE
openedx   Active   12h
Namespace already exists: skipping creation.
kubectl apply --kustomize /home/kyle/.local/share/tutor-nightly/env --selector app.kubernetes.io/name=mfe
The Deployment "mfe" is invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app.kubernetes.io/instance":"openedx-KXV0satwwOtuGRz7lwgslwU7", "app.kubernetes.io/managed-by":"tutor", "app.kubernetes.io/name":"mfe", "app.kubernetes.io/part-of":"openedx"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable
Error: Command failed with status 1: kubectl apply --kustomize /home/kyle/.local/share/tutor-nightly/env --selector app.kubernetes.io/name=mfe
$ tutor k8s stop
kubectl delete --namespace openedx --selector=app.kubernetes.io/instance=openedx-KXV0satwwOtuGRz7lwgslwU7,app.kubernetes.io/component!=loadbalancer deployments,services,configmaps,jobs
service "cms" deleted
service "elasticsearch" deleted
service "lms" deleted
service "mfe" deleted
service "mongodb" deleted
service "mysql" deleted
service "redis" deleted
service "smtp" deleted
configmap "caddy-config-b9gk6kf847" deleted
configmap "openedx-config-kkhkt28hth" deleted
configmap "openedx-settings-cms-bkft5k2b4h" deleted
configmap "openedx-settings-lms-h25dtdkdh2" deleted
configmap "redis-config-fccm65mh4m" deleted
$ kubectl --namespace=openedx get pods
NAME                            READY   STATUS             RESTARTS      AGE
caddy-85589d6669-dnf65          1/1     Running            1 (11m ago)   52m
cms-7dd67c5f55-b4rvb            1/1     Running            1 (11m ago)   52m
cms-job-20220303113051-lrzh5    0/1     Completed          0             51m
cms-worker-67846c7d7b-t2djr     1/1     Running            1 (11m ago)   52m
elasticsearch-d8b6859f7-7rfmr   1/1     Running            1 (11m ago)   52m
lms-788dfd9669-spgdw            1/1     Running            1 (11m ago)   52m
lms-job-20220303113217-gwj82    0/1     Completed          0             50m
lms-worker-794866f475-zhzzb     1/1     Running            1 (11m ago)   52m
mfe-7757f78d77-qcpmr            0/1     ImagePullBackOff   0             49m
mongodb-f4f6dc446-jn7ck         1/1     Running            1 (11m ago)   52m
mysql-7cb5f98d7-tlf76           1/1     Running            1 (11m ago)   52m
redis-7ddff4c6dd-hcxb6          1/1     Running            1 (11m ago)   52m
smtp-7454bf587b-6cl9l           1/1     Running            1 (11m ago)   52m
$ tutor k8s stop
kubectl delete --namespace openedx --selector=app.kubernetes.io/instance=openedx-KXV0satwwOtuGRz7lwgslwU7,app.kubernetes.io/component!=loadbalancer deployments,services,configmaps,jobs
No resources found
$