diff --git a/tutor/commands/dev.py b/tutor/commands/dev.py index 68fbebe..b625642 100644 --- a/tutor/commands/dev.py +++ b/tutor/commands/dev.py @@ -1,5 +1,6 @@ import click +from .. import config as tutor_config from .. import env as tutor_env from .. import fmt from .. import utils @@ -27,6 +28,24 @@ edx_platform_development_settings_option = click.option( ) +@click.command( + help="Run all or a selection of configured Open edX services in development mode" +) +@click.option("-d", "--detach", is_flag=True, help="Start in daemon mode") +@click.argument("services", metavar="service", nargs=-1) +@click.pass_obj +def start(context, detach, services): + """ + TODO document this + """ + command = ["up", "--remove-orphans"] + if detach: + command.append("-d") + + config = tutor_config.load(context.root) + docker_compose(context.root, config, *command, *services) + + @click.command( help="Run a command in one of the containers", context_settings={"ignore_unknown_options": True}, @@ -43,8 +62,10 @@ def run(context, edx_platform_path, edx_platform_settings, service, command, arg run_command.append(command) if args: run_command += args + + config = tutor_config.load(context.root) docker_compose_run( - context.root, edx_platform_path, edx_platform_settings, *run_command + context.root, config, edx_platform_path, edx_platform_settings, *run_command ) @@ -61,7 +82,9 @@ def execute(context, service, command, args): exec_command = ["exec", service, command] if args: exec_command += args - docker_compose(context.root, *exec_command) + + config = tutor_config.load(context.root) + docker_compose(context.root, config, *exec_command) @click.command(help="Run a development server") @@ -70,13 +93,15 @@ def execute(context, service, command, args): @click.argument("service", type=click.Choice(["lms", "cms"])) @click.pass_obj def runserver(context, edx_platform_path, edx_platform_settings, service): - port = service_port(service) + port = 8000 if service == "lms" else 8001 fmt.echo_info( "The {} service will be available at http://localhost:{}".format(service, port) ) + config = tutor_config.load(context.root) docker_compose_run( context.root, + config, edx_platform_path, edx_platform_settings, "-p", @@ -92,33 +117,33 @@ def runserver(context, edx_platform_path, edx_platform_settings, service): @click.command(help="Stop a running development platform") @click.pass_obj def stop(context): - docker_compose(context.root, "rm", "--stop", "--force") + config = tutor_config.load(context.root) + docker_compose(context.root, config, "rm", "--stop", "--force") -def docker_compose_run(root, edx_platform_path, edx_platform_settings, *command): +def docker_compose_run( + root, config, edx_platform_path, edx_platform_settings, *command +): run_command = ["run", "--rm", "-e", "SETTINGS={}".format(edx_platform_settings)] if edx_platform_path: run_command += ["--volume={}:/openedx/edx-platform".format(edx_platform_path)] run_command += command - docker_compose(root, *run_command) + docker_compose(root, config, *run_command) -def docker_compose(root, *command): +def docker_compose(root, config, *command): return utils.docker_compose( "-f", tutor_env.pathjoin(root, "local", "docker-compose.yml"), "-f", tutor_env.pathjoin(root, "dev", "docker-compose.yml"), "--project-name", - "tutor_dev", + config["DEV_PROJECT_NAME"], *command ) -def service_port(service): - return 8000 if service == "lms" else 8001 - - +dev.add_command(start) dev.add_command(run) dev.add_command(execute) dev.add_command(runserver) diff --git a/tutor/templates/config.yml b/tutor/templates/config.yml index 47fc8bb..eb24535 100644 --- a/tutor/templates/config.yml +++ b/tutor/templates/config.yml @@ -27,6 +27,7 @@ OPENEDX_AWS_SECRET_ACCESS_KEY: "" ANDROID_RELEASE_STORE_PASSWORD: "android store password" ANDROID_RELEASE_KEY_PASSWORD: "android release key password" ANDROID_RELEASE_KEY_ALIAS: "android release key alias" +DEV_PROJECT_NAME: "tutor_dev" DOCKER_IMAGE_OPENEDX: "overhangio/openedx:{{ TUTOR_VERSION }}" DOCKER_IMAGE_OPENEDX_DEV: "overhangio/openedx-dev:{{ TUTOR_VERSION }}" DOCKER_IMAGE_ANDROID: "overhangio/openedx-android:{{ TUTOR_VERSION }}"