Add `--limit=myplugin` option to `init` commands

This makes it possible to run "init" for some services only, which is
useful during debugging.
This commit is contained in:
Régis Behmo 2020-06-01 22:38:04 +02:00
parent a6c9bba3bf
commit 872a33414a
5 changed files with 37 additions and 23 deletions

View File

@ -2,6 +2,10 @@
Note: Breaking changes between versions are indicated by "💥".
## Unreleased
- [Feature] Add `--limit=myplugin` option to `init` commands for limit execution of initialisation to certain services and plugins
## v3.12.6 (2020-06-01)
- [Improvement] Add `dig`, `ping` utilities to openedx-dev Docker image

View File

@ -165,11 +165,12 @@ def execute(context, args):
@click.command(help="Initialise all applications")
@click.option("-l", "--limit", help="Limit initialisation to this service or plugin")
@click.pass_obj
def init(context):
def init(context, limit):
config = tutor_config.load(context.root)
runner = ScriptRunner(context.root, config, context.docker_compose)
scripts.initialise(runner)
scripts.initialise(runner, limit_to=limit)
@click.command(

View File

@ -36,7 +36,7 @@ def quickstart(context, non_interactive):
click.echo(fmt.title("Starting the platform"))
start.callback()
click.echo(fmt.title("Database creation and migrations"))
init.callback()
init.callback(limit=None)
@click.command(help="Run all configured Open edX services")
@ -116,14 +116,15 @@ def delete(context, yes):
@click.command(help="Initialise all applications")
@click.option("-l", "--limit", help="Limit initialisation to this service or plugin")
@click.pass_obj
def init(context):
def init(context, limit):
config = tutor_config.load(context.root)
runner = K8sScriptRunner(context.root, config)
for service in ["mysql", "elasticsearch", "mongodb"]:
if tutor_config.is_service_activated(config, service):
wait_for_pod_ready(config, service)
scripts.initialise(runner)
scripts.initialise(runner, limit_to=limit)
@click.command(help="Create an Open edX user and interactively set their password")

View File

@ -57,7 +57,7 @@ def quickstart(context, non_interactive, pullimages_):
click.echo(fmt.title("Starting the platform in detached mode"))
compose.start.callback(True, [])
click.echo(fmt.title("Database creation and migrations"))
compose.init.callback()
compose.init.callback(limit=None)
echo_platform_info(config)

View File

@ -27,28 +27,36 @@ class BaseRunner:
yield from plugins.iter_hooks(self.config, hook)
def initialise(runner):
def initialise(runner, limit_to=None):
fmt.echo_info("Initialising all services...")
runner.run_job_from_template("mysql", "hooks", "mysql", "init")
if limit_to is None or limit_to == "mysql":
runner.run_job_from_template("mysql", "hooks", "mysql", "init")
for plugin_name, hook in runner.iter_plugin_hooks("pre-init"):
for service in hook:
fmt.echo_info(
"Plugin {}: running pre-init for service {}...".format(
plugin_name, service
if limit_to is None or limit_to == plugin_name:
for service in hook:
fmt.echo_info(
"Plugin {}: running pre-init for service {}...".format(
plugin_name, service
)
)
runner.run_job_from_template(
service, plugin_name, "hooks", service, "pre-init"
)
)
runner.run_job_from_template(
service, plugin_name, "hooks", service, "pre-init"
)
for service in ["lms", "cms", "forum"]:
fmt.echo_info("Initialising {}...".format(service))
runner.run_job_from_template(service, "hooks", service, "init")
if limit_to is None or limit_to == service:
fmt.echo_info("Initialising {}...".format(service))
runner.run_job_from_template(service, "hooks", service, "init")
for plugin_name, hook in runner.iter_plugin_hooks("init"):
for service in hook:
fmt.echo_info(
"Plugin {}: running init for service {}...".format(plugin_name, service)
)
runner.run_job_from_template(service, plugin_name, "hooks", service, "init")
if limit_to is None or limit_to == plugin_name:
for service in hook:
fmt.echo_info(
"Plugin {}: running init for service {}...".format(
plugin_name, service
)
)
runner.run_job_from_template(
service, plugin_name, "hooks", service, "init"
)
fmt.echo_info("All services initialised.")