mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-13 14:43:03 +00:00
feat: make it possible to override local docker-compose job
Previously, it was possible to override docker-compose services, but not jobs. This requirement has appeared because some people need to override project-wide MTU settings. See: https://discuss.overhang.io/t/problem-fetching-saml-idp-metadata/1330/23
This commit is contained in:
parent
1411e5a0ff
commit
d3bfc4fb87
@ -4,6 +4,8 @@ Note: Breaking changes between versions are indicated by "💥".
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
- 💥[Feature] Make it possible to override local job configuration. This deprecates the older model for running jobs which dates back from a long time ago.
|
||||||
|
|
||||||
## v12.0.4 (2021-08-12)
|
## v12.0.4 (2021-08-12)
|
||||||
|
|
||||||
- [Security] Apply security patch [28442](https://github.com/edx/edx-platform/pull/28442).
|
- [Security] Apply security patch [28442](https://github.com/edx/edx-platform/pull/28442).
|
||||||
|
@ -280,3 +280,5 @@ You might want to customize the docker-compose services listed in ``$(tutor conf
|
|||||||
vim $(tutor config printroot)/env/local/docker-compose.override.yml
|
vim $(tutor config printroot)/env/local/docker-compose.override.yml
|
||||||
|
|
||||||
The values in this file will override the values from ``docker-compose.yml`` and ``docker-compose.prod.yml``, as explained in the `docker-compose documentation <https://docs.docker.com/compose/extends/#adding-and-overriding-configuration>`__.
|
The values in this file will override the values from ``docker-compose.yml`` and ``docker-compose.prod.yml``, as explained in the `docker-compose documentation <https://docs.docker.com/compose/extends/#adding-and-overriding-configuration>`__.
|
||||||
|
|
||||||
|
Similarly, the job service configuration can be overridden by creating a ``docker-compose.jobs.override.yml`` file in that same folder.
|
||||||
|
@ -10,7 +10,6 @@ from .. import env as tutor_env
|
|||||||
from ..exceptions import TutorError
|
from ..exceptions import TutorError
|
||||||
from .. import fmt
|
from .. import fmt
|
||||||
from .. import jobs
|
from .. import jobs
|
||||||
from .. import serialize
|
|
||||||
from ..types import Config
|
from ..types import Config
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from .context import Context
|
from .context import Context
|
||||||
@ -33,49 +32,24 @@ class ComposeJobRunner(jobs.BaseJobRunner):
|
|||||||
service does not exist, run the service from good old regular
|
service does not exist, run the service from good old regular
|
||||||
docker-compose.yml.
|
docker-compose.yml.
|
||||||
"""
|
"""
|
||||||
jobs_path = tutor_env.pathjoin(self.root, "local", "docker-compose.jobs.yml")
|
run_command = [
|
||||||
job_service_name = "{}-job".format(service)
|
|
||||||
opts = [] if utils.is_a_tty() else ["-T"]
|
|
||||||
if job_service_name in serialize.load(open(jobs_path).read())["services"]:
|
|
||||||
return self.docker_compose_func(
|
|
||||||
self.root,
|
|
||||||
self.config,
|
|
||||||
"-f",
|
"-f",
|
||||||
jobs_path,
|
tutor_env.pathjoin(self.root, "local", "docker-compose.jobs.yml"),
|
||||||
"run",
|
]
|
||||||
*opts,
|
override_path = tutor_env.pathjoin(
|
||||||
"--rm",
|
self.root, "local", "docker-compose.jobs.override.yml"
|
||||||
job_service_name,
|
|
||||||
"sh",
|
|
||||||
"-e",
|
|
||||||
"-c",
|
|
||||||
command,
|
|
||||||
)
|
|
||||||
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 "),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
if os.path.exists(override_path):
|
||||||
|
run_command += ["-f", override_path]
|
||||||
|
run_command += ["run", "--rm"]
|
||||||
|
if not utils.is_a_tty():
|
||||||
|
run_command += ["-T"]
|
||||||
|
job_service_name = "{}-job".format(service)
|
||||||
return self.docker_compose_func(
|
return self.docker_compose_func(
|
||||||
self.root,
|
self.root,
|
||||||
self.config,
|
self.config,
|
||||||
"run",
|
*run_command,
|
||||||
*opts,
|
job_service_name,
|
||||||
"--rm",
|
|
||||||
service,
|
|
||||||
"sh",
|
"sh",
|
||||||
"-e",
|
"-e",
|
||||||
"-c",
|
"-c",
|
||||||
|
@ -58,7 +58,7 @@ class K8sJobRunner(jobs.BaseJobRunner):
|
|||||||
)
|
)
|
||||||
if job_name == name:
|
if job_name == name:
|
||||||
return job
|
return job
|
||||||
raise ValueError("Could not find job '{}'".format(name))
|
raise exceptions.TutorError("Could not find job '{}'".format(name))
|
||||||
|
|
||||||
def active_job_names(self) -> List[str]:
|
def active_job_names(self) -> List[str]:
|
||||||
"""
|
"""
|
||||||
@ -75,27 +75,7 @@ class K8sJobRunner(jobs.BaseJobRunner):
|
|||||||
|
|
||||||
def run_job(self, service: str, command: str) -> int:
|
def run_job(self, service: str, command: str) -> int:
|
||||||
job_name = "{}-job".format(service)
|
job_name = "{}-job".format(service)
|
||||||
try:
|
|
||||||
job = self.load_job(job_name)
|
job = self.load_job(job_name)
|
||||||
except ValueError:
|
|
||||||
message = (
|
|
||||||
"The '{job_name}' kubernetes job does not exist in the list of job "
|
|
||||||
"runners. 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_name=job_name,
|
|
||||||
command=command.replace("\n", "\n "),
|
|
||||||
)
|
|
||||||
fmt.echo_alert(message)
|
|
||||||
wait_for_pod_ready(self.config, service)
|
|
||||||
return kubectl_exec(self.config, service, command)
|
|
||||||
# Create a unique job name to make it deduplicate jobs and make it easier to
|
# Create a unique job name to make it deduplicate jobs and make it easier to
|
||||||
# find later. Logs of older jobs will remain available for some time.
|
# find later. Logs of older jobs will remain available for some time.
|
||||||
job_name += "-" + datetime.now().strftime("%Y%m%d%H%M%S")
|
job_name += "-" + datetime.now().strftime("%Y%m%d%H%M%S")
|
||||||
|
Loading…
Reference in New Issue
Block a user