Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Note

This document is incomplete

Before You Start

Create a Dockerfile for Your Service

  • Create a Dockerfile at tutormyplugin/templates/myplugin/build/myplugin/Dockerfile

    • If you aren’t sure what your service needs take a look at tutor-contrib-exams as a minimal example

    • This section could probably use more guidance on Dockerfiles

  • Add an image build hook to tutormyplugin/plugin.py

    Code Block
    languagepy
    ################# Docker image management
    # To build an image with `tutor images build myimage`, add a Dockerfile to templates/exams/build/myimage and write:
    hooks.Filters.IMAGES_BUILD.add_item((
        "myplugin",
        ("plugins", "myplugin", "build", "myplugin"),
        "{{ MYPLUGIN_DOCKER_IMAGE }}",
        (),
    ))
  • Take note of MYPLUGIN_DOCKER_IMAGE we need to define this config value in plugin.py as well

    Code Block
    languagepy
    ########################################
    # CONFIGURATION
    ########################################
    
    hooks.Filters.CONFIG_DEFAULTS.add_items(
        [
            # Add your new settings that have default values here.
            # Each new setting is a pair: (setting_name, default_value).
            # Prefix your setting names with 'MYPLUGIN_'.
            ("MYPLUGIN_VERSION", __version__),
            ("MYPLUGIN_DOCKER_IMAGE", f'myplugin:{__version__}'),
        ]
    )
    
  • Add docker-compose patches to tutormyplugin/patches to get your service running locally

Setup Django Settings and Configuration Values

TODO

Provisioning and Initialization Tasks

...

  • Create tutor django settings file(s) for your app inside templates/myplugin/apps/setttings/tutor.

    • at minimum you’ll need templates/myplugin/apps/settings/tutor/development.py

  • These files will get mounted into your service's 'settings' folder so you can simply import the existing settings in the repository. This way you only need to define settings that are different in your tutor environment such as urls.

  • To create additional tutor configuration values that will get rendered you can do that under the CONFIGURATION section of plugin.py(we did this for MYPLUGIN_DOCKER_IMAGE above)

  • Mimimal example of tutor/development.py

    Code Block
    languagepy
    # tutor/development.py
    
    from ..local import * # import local setttins from repo
    ROOT_URL = "http://{{MYPLUGIN_HOST}}:1111" # MYPLUGIN_HOST defined in plugin.yml
    
    {{ patch("exams-development-settings") }}
  • If you have common settings across all environments you can create a partial file to reuse in each environment. See https://github.com/overhangio/tutor-discovery/blob/master/tutordiscovery/templates/discovery/apps/settings/partials/common.py as an example in course-discovery.

Provisioning and Initialization Jobs

You service likely has some steps to create database users, run migrations, and run management commands. In devstack these were typically part of a provision script.

  • For commands that will run against your service, such as running ‘migrate’, add to templates/myplugin/jobs/MYPLUGIN/init

  • Commands that would run against the mysql container, such as creating a default database user, would get added to templates/myplugin/jobs/MYSQL/init

  • And so on, where the parent folder indicates the container the script will get executed on

  • See edx-exams as an example

Test it all out

  • Install a local copy of your plugin

    Code Block
    pip install -e ./myplugin-project-folder
  • Enable your plugin

    Code Block
    tutor plugins enable myplugin
  • Generate config with your plugin enabled

    Code Block
    tutor config save
  • Run init tasks

    Code Block
    tutor dev init