From ea3fbafcafd1719b1dd67db424cb9b9ded5bdfce Mon Sep 17 00:00:00 2001 From: GonzaloRomero Date: Wed, 18 May 2022 11:14:12 -0500 Subject: [PATCH] feat: upgrade to nutmeg --- .gitlab-ci.yml | 2 +- setup.py | 8 +- tutorxqueue/__about__.py | 2 +- tutorxqueue/plugin.py | 79 +++++++++++++++---- tutorxqueue/templates/xqueue/tasks/mysql/init | 4 + .../templates/xqueue/tasks/xqueue/init | 2 + 6 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 tutorxqueue/templates/xqueue/tasks/mysql/init create mode 100644 tutorxqueue/templates/xqueue/tasks/xqueue/init diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ec11db..fda9f24 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ variables: TUTOR_PLUGIN: xqueue TUTOR_IMAGES: xqueue TUTOR_PYPI_PACKAGE: tutor-xqueue - OPENEDX_RELEASE: maple + OPENEDX_RELEASE: nutmeg GITHUB_REPO: overhangio/tutor-xqueue include: diff --git a/setup.py b/setup.py index e7a8051..e117881 100644 --- a/setup.py +++ b/setup.py @@ -31,17 +31,15 @@ setup( long_description_content_type="text/x-rst", packages=find_packages(exclude=["tests*"]), include_package_data=True, - python_requires=">=3.5", - install_requires=["tutor>=13.0.0,<14.0.0", "requests"], - entry_points={"tutor.plugin.v0": ["xqueue = tutorxqueue.plugin"]}, + python_requires=">=3.7", + install_requires=["tutor>=14.0.0,<15.0.0", "requests"], + entry_points={"tutor.plugin.v1": ["xqueue = tutorxqueue.plugin"]}, classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", diff --git a/tutorxqueue/__about__.py b/tutorxqueue/__about__.py index 1311252..2294691 100644 --- a/tutorxqueue/__about__.py +++ b/tutorxqueue/__about__.py @@ -1 +1 @@ -__version__ = "13.0.0" +__version__ = "14.0.0" diff --git a/tutorxqueue/plugin.py b/tutorxqueue/plugin.py index 384376f..4326d86 100644 --- a/tutorxqueue/plugin.py +++ b/tutorxqueue/plugin.py @@ -7,13 +7,14 @@ import pkg_resources import requests from tutor import config as tutor_config +from tutor import hooks as tutor_hooks from tutor.exceptions import TutorError from .__about__ import __version__ config = { - "add": { + "unique": { "AUTH_PASSWORD": "{{ 8|random_string }}", "MYSQL_PASSWORD": "{{ 8|random_string }}", "SECRET_KEY": "{{ 24|random_string }}", @@ -28,25 +29,33 @@ config = { }, } -templates = pkg_resources.resource_filename("tutorxqueue", "templates") -hooks = { - "init": ["mysql", "xqueue"], - "build-image": {"xqueue": "{{ XQUEUE_DOCKER_IMAGE }}"}, - "remote-image": {"xqueue": "{{ XQUEUE_DOCKER_IMAGE }}"}, -} +# Inizialization hooks +tutor_hooks.Filters.COMMANDS_INIT.add_item(( + "mysql", + ("xqueue", "tasks", "mysql", "init"), +)) +tutor_hooks.Filters.COMMANDS_INIT.add_item(( + "xqueue", + ("xqueue", "tasks", "xqueue", "init"), +)) -def patches(): - all_patches = {} - for path in glob( - os.path.join(pkg_resources.resource_filename("tutorxqueue", "patches"), "*") - ): - with open(path) as patch_file: - name = os.path.basename(path) - content = patch_file.read() - all_patches[name] = content - return all_patches +# Image managment +tutor_hooks.Filters.IMAGES_BUILD.add_item(( + "xqueue", + ("plugins", "xqueue", "build", "xqueue"), + "{{ XQUEUE_DOCKER_IMAGE }}", + (), +)) +tutor_hooks.Filters.IMAGES_PULL.add_item(( + "xqueue", + "{{ XQUEUE_DOCKER_IMAGE }}", +)) +tutor_hooks.Filters.IMAGES_PUSH.add_item(( + "xqueue", + "{{ XQUEUE_DOCKER_IMAGE }}", +)) @click.group(help="Interact with the Xqueue server") def command(): @@ -199,3 +208,39 @@ submissions.add_command(count_submissions) submissions.add_command(show_submission) submissions.add_command(grade_submission) command.add_command(submissions) + +####### Boilerplate code +# Add the "templates" folder as a template root +tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item( + pkg_resources.resource_filename("tutorxqueue", "templates") +) +# Render the "build" and "apps" folders +tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items( + [ + ("xqueue/build", "plugins"), + ("xqueue/apps", "plugins"), + ], +) +# Load patches from files +for path in glob( + os.path.join( + pkg_resources.resource_filename("tutorxqueue", "patches"), + "*", + ) +): + with open(path, encoding="utf-8") as patch_file: + tutor_hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read())) +# Add configuration entries +tutor_hooks.Filters.CONFIG_DEFAULTS.add_items( + [ + (f"XQUEUE_{key}", value) + for key, value in config.get("defaults", {}).items() + ] +) +tutor_hooks.Filters.CONFIG_UNIQUE.add_items( + [ + (f"XQUEUE_{key}", value) + for key, value in config.get("unique", {}).items() + ] +) +tutor_hooks.Filters.CONFIG_OVERRIDES.add_items(list(config.get("overrides", {}).items())) diff --git a/tutorxqueue/templates/xqueue/tasks/mysql/init b/tutorxqueue/templates/xqueue/tasks/mysql/init new file mode 100644 index 0000000..aeea8db --- /dev/null +++ b/tutorxqueue/templates/xqueue/tasks/mysql/init @@ -0,0 +1,4 @@ +mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e 'CREATE DATABASE IF NOT EXISTS {{ XQUEUE_MYSQL_DATABASE }};' +mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "CREATE USER IF NOT EXISTS '{{ XQUEUE_MYSQL_USERNAME }}';" +mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "ALTER USER '{{ XQUEUE_MYSQL_USERNAME }}'@'%' IDENTIFIED BY '{{ XQUEUE_MYSQL_PASSWORD }}';" +mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "GRANT ALL ON {{ XQUEUE_MYSQL_DATABASE }}.* TO '{{ XQUEUE_MYSQL_USERNAME }}'@'%';" diff --git a/tutorxqueue/templates/xqueue/tasks/xqueue/init b/tutorxqueue/templates/xqueue/tasks/xqueue/init new file mode 100644 index 0000000..d65fc76 --- /dev/null +++ b/tutorxqueue/templates/xqueue/tasks/xqueue/init @@ -0,0 +1,2 @@ +./manage.py migrate +./manage.py update_users