2020-12-25 21:56:42 +00:00
|
|
|
import os
|
2021-04-06 10:09:00 +00:00
|
|
|
from typing import Callable, List
|
2020-12-25 21:56:42 +00:00
|
|
|
|
2020-01-08 18:38:13 +00:00
|
|
|
import click
|
2021-02-25 08:09:14 +00:00
|
|
|
from mypy_extensions import VarArg
|
2020-01-08 18:38:13 +00:00
|
|
|
|
2020-12-25 21:56:42 +00:00
|
|
|
from .. import bindmounts
|
2020-01-08 18:38:13 +00:00
|
|
|
from .. import config as tutor_config
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
from .. import env as tutor_env
|
2020-12-25 21:56:42 +00:00
|
|
|
from ..exceptions import TutorError
|
2020-01-08 18:38:13 +00:00
|
|
|
from .. import fmt
|
2021-03-13 18:46:44 +00:00
|
|
|
from .. import jobs
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
from .. import serialize
|
2021-04-06 10:09:00 +00:00
|
|
|
from ..types import Config
|
2020-03-27 08:59:11 +00:00
|
|
|
from .. import utils
|
2021-02-25 08:09:14 +00:00
|
|
|
from .context import Context
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
2021-03-13 18:46:44 +00:00
|
|
|
class ComposeJobRunner(jobs.BaseJobRunner):
|
2021-02-25 08:09:14 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
root: str,
|
2021-04-06 10:09:00 +00:00
|
|
|
config: Config,
|
|
|
|
docker_compose_func: Callable[[str, Config, VarArg(str)], int],
|
2021-02-25 08:09:14 +00:00
|
|
|
):
|
2020-01-08 18:38:13 +00:00
|
|
|
super().__init__(root, config)
|
|
|
|
self.docker_compose_func = docker_compose_func
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def run_job(self, service: str, command: str) -> int:
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
"""
|
|
|
|
Run the "{{ service }}-job" service from local/docker-compose.jobs.yml with the
|
|
|
|
specified command. For backward-compatibility reasons, if the corresponding
|
|
|
|
service does not exist, run the service from good old regular
|
|
|
|
docker-compose.yml.
|
|
|
|
"""
|
|
|
|
jobs_path = tutor_env.pathjoin(self.root, "local", "docker-compose.jobs.yml")
|
|
|
|
job_service_name = "{}-job".format(service)
|
2020-04-02 10:36:43 +00:00
|
|
|
opts = [] if utils.is_a_tty() else ["-T"]
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
if job_service_name in serialize.load(open(jobs_path).read())["services"]:
|
2021-02-25 08:09:14 +00:00
|
|
|
return self.docker_compose_func(
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
self.root,
|
|
|
|
self.config,
|
|
|
|
"-f",
|
|
|
|
jobs_path,
|
|
|
|
"run",
|
|
|
|
*opts,
|
|
|
|
"--rm",
|
|
|
|
job_service_name,
|
|
|
|
"sh",
|
|
|
|
"-e",
|
|
|
|
"-c",
|
|
|
|
command,
|
|
|
|
)
|
2021-02-25 08:09:14 +00:00
|
|
|
fmt.echo_alert(
|
|
|
|
(
|
|
|
|
"The '{job_service_name}' service does not exist in {jobs_path}. "
|
|
|
|
"This might be caused by an older plugin. Tutor switched to a job "
|
|
|
|
"runner model for running one-time commands, such as database"
|
|
|
|
" initialisation. For the record, this is the command that we are "
|
|
|
|
"running:\n"
|
|
|
|
"\n"
|
|
|
|
" {command}\n"
|
|
|
|
"\n"
|
|
|
|
"Old-style job running will be deprecated soon. Please inform "
|
|
|
|
"your plugin maintainer!"
|
|
|
|
).format(
|
|
|
|
job_service_name=job_service_name,
|
|
|
|
jobs_path=jobs_path,
|
|
|
|
command=command.replace("\n", "\n "),
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
)
|
2021-02-25 08:09:14 +00:00
|
|
|
)
|
|
|
|
return self.docker_compose_func(
|
|
|
|
self.root,
|
|
|
|
self.config,
|
|
|
|
"run",
|
|
|
|
*opts,
|
|
|
|
"--rm",
|
|
|
|
service,
|
|
|
|
"sh",
|
|
|
|
"-e",
|
|
|
|
"-c",
|
|
|
|
command,
|
|
|
|
)
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(help="Run all or a selection of configured Open edX services")
|
|
|
|
@click.option("-d", "--detach", is_flag=True, help="Start in daemon mode")
|
|
|
|
@click.argument("services", metavar="service", nargs=-1)
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def start(context: Context, detach: bool, services: List[str]) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
command = ["up", "--remove-orphans"]
|
|
|
|
if detach:
|
|
|
|
command.append("-d")
|
|
|
|
|
|
|
|
config = tutor_config.load(context.root)
|
|
|
|
context.docker_compose(context.root, config, *command, *services)
|
|
|
|
|
|
|
|
|
|
|
|
@click.command(help="Stop a running platform")
|
|
|
|
@click.argument("services", metavar="service", nargs=-1)
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def stop(context: Context, services: List[str]) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
config = tutor_config.load(context.root)
|
2020-09-04 10:07:44 +00:00
|
|
|
context.docker_compose(context.root, config, "stop", *services)
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(
|
|
|
|
short_help="Reboot an existing platform",
|
|
|
|
help="This is more than just a restart: with reboot, the platform is fully stopped before being restarted again",
|
|
|
|
)
|
|
|
|
@click.option("-d", "--detach", is_flag=True, help="Start in daemon mode")
|
|
|
|
@click.argument("services", metavar="service", nargs=-1)
|
2021-02-25 08:09:14 +00:00
|
|
|
@click.pass_context
|
|
|
|
def reboot(context: click.Context, detach: bool, services: List[str]) -> None:
|
|
|
|
context.invoke(stop, services=services)
|
|
|
|
context.invoke(start, detach=detach, services=services)
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(
|
|
|
|
short_help="Restart some components from a running platform.",
|
|
|
|
help="""Specify 'openedx' to restart the lms, cms and workers, or 'all' to
|
|
|
|
restart all services. Note that this performs a 'docker-compose restart', so new images
|
|
|
|
may not be taken into account. It is useful for reloading settings, for instance. To
|
|
|
|
fully stop the platform, use the 'reboot' command.""",
|
|
|
|
)
|
2020-03-12 08:52:22 +00:00
|
|
|
@click.argument("services", metavar="service", nargs=-1)
|
2020-01-08 18:38:13 +00:00
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def restart(context: Context, services: List[str]) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
config = tutor_config.load(context.root)
|
|
|
|
command = ["restart"]
|
2020-03-12 08:52:22 +00:00
|
|
|
if "all" in services:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for service in services:
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
if service == "openedx":
|
2020-09-17 10:53:14 +00:00
|
|
|
if config["RUN_LMS"]:
|
2020-03-12 08:52:22 +00:00
|
|
|
command += ["lms", "lms-worker"]
|
2020-09-17 10:53:14 +00:00
|
|
|
if config["RUN_CMS"]:
|
2020-03-12 08:52:22 +00:00
|
|
|
command += ["cms", "cms-worker"]
|
|
|
|
else:
|
|
|
|
command.append(service)
|
2020-01-08 18:38:13 +00:00
|
|
|
context.docker_compose(context.root, config, *command)
|
|
|
|
|
|
|
|
|
|
|
|
@click.command(help="Initialise all applications")
|
2020-06-01 20:38:04 +00:00
|
|
|
@click.option("-l", "--limit", help="Limit initialisation to this service or plugin")
|
2020-01-08 18:38:13 +00:00
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def init(context: Context, limit: str) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
config = tutor_config.load(context.root)
|
2021-03-13 18:46:44 +00:00
|
|
|
runner = ComposeJobRunner(context.root, config, context.docker_compose)
|
|
|
|
jobs.initialise(runner, limit_to=limit)
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(help="Create an Open edX user and interactively set their password")
|
|
|
|
@click.option("--superuser", is_flag=True, help="Make superuser")
|
|
|
|
@click.option("--staff", is_flag=True, help="Make staff user")
|
|
|
|
@click.option(
|
|
|
|
"-p",
|
|
|
|
"--password",
|
|
|
|
help="Specify password from the command line. If undefined, you will be prompted to input a password",
|
|
|
|
)
|
|
|
|
@click.argument("name")
|
|
|
|
@click.argument("email")
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def createuser(
|
|
|
|
context: Context, superuser: str, staff: bool, password: str, name: str, email: str
|
|
|
|
) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
config = tutor_config.load(context.root)
|
2021-03-13 18:46:44 +00:00
|
|
|
runner = ComposeJobRunner(context.root, config, context.docker_compose)
|
|
|
|
command = jobs.create_user_command(superuser, staff, name, email, password=password)
|
Improve job running in local and k8s
Running jobs was previously done with "exec". This was because it
allowed us to avoid copying too much container specification information
from the docker-compose/deployments files to the jobs files. However,
this was limiting:
- In order to run a job, the corresponding container had to be running.
This was particularly painful in Kubernetes, where containers are
crashing as long as migrations are not correctly run.
- Containers in which we need to run jobs needed to be present in the
docker-compose/deployments files. This is unnecessary, for example when
mysql is disabled, or in the case of the certbot container.
Now, we create dedicated jobs files, both for local and k8s deployment.
This introduces a little redundancy, but not too much. Note that
dependent containers are not listed in the docker-compose.jobs.yml file,
so an actual platform is still supposed to be running when we launch the
jobs.
This also introduces a subtle change: now, jobs go through the container
entrypoint prior to running. This is probably a good thing, as it will
avoid forgetting about incorrect environment variables.
In k8s, we find ourselves interacting way too much with the kubectl
utility. Parsing output from the CLI is a pain. So we need to switch to
the native kubernetes client library.
2020-03-25 17:47:36 +00:00
|
|
|
runner.run_job("lms", command)
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
2020-03-13 11:09:48 +00:00
|
|
|
@click.command(
|
|
|
|
help="Set a theme for a given domain name. To reset to the default theme , use 'default' as the theme name."
|
|
|
|
)
|
|
|
|
@click.argument("theme_name")
|
|
|
|
@click.argument("domain_names", metavar="domain_name", nargs=-1)
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def settheme(context: Context, theme_name: str, domain_names: List[str]) -> None:
|
2020-03-13 11:09:48 +00:00
|
|
|
config = tutor_config.load(context.root)
|
2021-03-13 18:46:44 +00:00
|
|
|
runner = ComposeJobRunner(context.root, config, context.docker_compose)
|
2020-03-13 11:09:48 +00:00
|
|
|
for domain_name in domain_names:
|
2021-03-13 18:46:44 +00:00
|
|
|
jobs.set_theme(theme_name, domain_name, runner)
|
2020-03-13 11:09:48 +00:00
|
|
|
|
|
|
|
|
2020-01-08 18:38:13 +00:00
|
|
|
@click.command(help="Import the demo course")
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def importdemocourse(context: Context) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
config = tutor_config.load(context.root)
|
2021-03-13 18:46:44 +00:00
|
|
|
runner = ComposeJobRunner(context.root, config, context.docker_compose)
|
2020-01-08 18:38:13 +00:00
|
|
|
fmt.echo_info("Importing demo course")
|
2021-03-13 18:46:44 +00:00
|
|
|
jobs.import_demo_course(runner)
|
2020-01-08 18:38:13 +00:00
|
|
|
|
|
|
|
|
2020-11-16 11:46:01 +00:00
|
|
|
@click.command(
|
|
|
|
short_help="Run a command in a new container",
|
|
|
|
help=(
|
|
|
|
"Run a command in a new container. This is a wrapper around `docker-compose run`. Any option or argument passed"
|
|
|
|
" to this command will be forwarded to docker-compose. Thus, you may use `-v` or `-p` to mount volumes and"
|
|
|
|
" expose ports."
|
|
|
|
),
|
|
|
|
context_settings={"ignore_unknown_options": True},
|
|
|
|
)
|
|
|
|
@click.argument("args", nargs=-1, required=True)
|
2021-02-25 08:09:14 +00:00
|
|
|
@click.pass_context
|
|
|
|
def run(context: click.Context, args: List[str]) -> None:
|
2020-12-25 21:56:42 +00:00
|
|
|
extra_args = ["--rm"]
|
2020-11-16 11:46:01 +00:00
|
|
|
if not utils.is_a_tty():
|
2020-12-25 21:56:42 +00:00
|
|
|
extra_args.append("-T")
|
2021-02-25 08:09:14 +00:00
|
|
|
context.invoke(dc_command, command="run", args=[*extra_args, *args])
|
2020-12-25 21:56:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(
|
|
|
|
name="bindmount",
|
|
|
|
help="Copy the contents of a container directory to a ready-to-bind-mount host directory",
|
|
|
|
)
|
|
|
|
@click.argument(
|
|
|
|
"service",
|
|
|
|
)
|
|
|
|
@click.argument("path")
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def bindmount_command(context: Context, service: str, path: str) -> None:
|
2020-12-25 21:56:42 +00:00
|
|
|
config = tutor_config.load(context.root)
|
|
|
|
host_path = bindmounts.create(
|
|
|
|
context.root, config, context.docker_compose, service, path
|
|
|
|
)
|
|
|
|
fmt.echo_info(
|
|
|
|
"Bind-mount volume created at {}. You can now use it in all `local` and `dev` commands with the `--volume={}` option.".format(
|
|
|
|
host_path, path
|
|
|
|
)
|
|
|
|
)
|
2020-11-16 11:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(
|
|
|
|
short_help="Run a command in a running container",
|
|
|
|
help=(
|
|
|
|
"Run a command in a running container. This is a wrapper around `docker-compose exec`. Any option or argument"
|
|
|
|
" passed to this command will be forwarded to docker-compose. Thus, you may use `-e` to manually define"
|
|
|
|
" environment variables."
|
|
|
|
),
|
|
|
|
context_settings={"ignore_unknown_options": True},
|
|
|
|
name="exec",
|
|
|
|
)
|
|
|
|
@click.argument("args", nargs=-1, required=True)
|
2021-02-25 08:09:14 +00:00
|
|
|
@click.pass_context
|
|
|
|
def execute(context: click.Context, args: List[str]) -> None:
|
|
|
|
context.invoke(dc_command, command="exec", args=args)
|
2020-11-16 11:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(
|
|
|
|
short_help="View output from containers",
|
|
|
|
help="View output from containers. This is a wrapper around `docker-compose logs`.",
|
|
|
|
)
|
|
|
|
@click.option("-f", "--follow", is_flag=True, help="Follow log output")
|
|
|
|
@click.option("--tail", type=int, help="Number of lines to show from each container")
|
|
|
|
@click.argument("service", nargs=-1)
|
2021-02-25 08:09:14 +00:00
|
|
|
@click.pass_context
|
|
|
|
def logs(context: click.Context, follow: bool, tail: bool, service: str) -> None:
|
2020-12-25 21:56:42 +00:00
|
|
|
args = []
|
2020-11-16 11:46:01 +00:00
|
|
|
if follow:
|
2020-12-25 21:56:42 +00:00
|
|
|
args.append("--follow")
|
2020-11-16 11:46:01 +00:00
|
|
|
if tail is not None:
|
2020-12-25 21:56:42 +00:00
|
|
|
args += ["--tail", str(tail)]
|
|
|
|
args += service
|
2021-02-25 08:09:14 +00:00
|
|
|
context.invoke(dc_command, command="logs", args=args)
|
2020-12-25 21:56:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command(
|
|
|
|
short_help="Direct interface to docker-compose.",
|
|
|
|
help=(
|
|
|
|
"Direct interface to docker-compose. This is a wrapper around `docker-compose`. Most commands, options and"
|
|
|
|
" arguments passed to this command will be forwarded as-is to docker-compose."
|
|
|
|
),
|
|
|
|
context_settings={"ignore_unknown_options": True},
|
|
|
|
name="dc",
|
|
|
|
)
|
|
|
|
@click.argument("command")
|
|
|
|
@click.argument("args", nargs=-1, required=True)
|
|
|
|
@click.pass_obj
|
2021-02-25 08:09:14 +00:00
|
|
|
def dc_command(context: Context, command: str, args: List[str]) -> None:
|
2020-12-25 21:56:42 +00:00
|
|
|
config = tutor_config.load(context.root)
|
|
|
|
volumes, non_volume_args = bindmounts.parse_volumes(args)
|
|
|
|
volume_args = []
|
|
|
|
for volume_arg in volumes:
|
|
|
|
if ":" not in volume_arg:
|
|
|
|
# This is a bind-mounted volume from the "volumes/" folder.
|
|
|
|
host_bind_path = bindmounts.get_path(context.root, volume_arg)
|
|
|
|
if not os.path.exists(host_bind_path):
|
|
|
|
raise TutorError(
|
|
|
|
(
|
|
|
|
"Bind-mount volume directory {} does not exist. It must first be created"
|
|
|
|
" with the '{}' command."
|
|
|
|
).format(host_bind_path, bindmount_command.name)
|
|
|
|
)
|
|
|
|
volume_arg = "{}:{}".format(host_bind_path, volume_arg)
|
|
|
|
volume_args += ["--volume", volume_arg]
|
|
|
|
context.docker_compose(
|
|
|
|
context.root, config, command, *volume_args, *non_volume_args
|
|
|
|
)
|
2020-11-16 11:46:01 +00:00
|
|
|
|
|
|
|
|
2021-02-25 08:09:14 +00:00
|
|
|
def add_commands(command_group: click.Group) -> None:
|
2020-01-08 18:38:13 +00:00
|
|
|
command_group.add_command(start)
|
|
|
|
command_group.add_command(stop)
|
|
|
|
command_group.add_command(restart)
|
|
|
|
command_group.add_command(reboot)
|
|
|
|
command_group.add_command(init)
|
|
|
|
command_group.add_command(createuser)
|
|
|
|
command_group.add_command(importdemocourse)
|
2020-03-13 11:09:48 +00:00
|
|
|
command_group.add_command(settheme)
|
2020-11-16 11:46:01 +00:00
|
|
|
command_group.add_command(dc_command)
|
|
|
|
command_group.add_command(run)
|
2020-12-25 21:56:42 +00:00
|
|
|
command_group.add_command(bindmount_command)
|
2020-11-16 11:46:01 +00:00
|
|
|
command_group.add_command(execute)
|
|
|
|
command_group.add_command(logs)
|