diff --git a/CHANGELOG.md b/CHANGELOG.md index dc09df1756f7ec617dd4ae74f3847d49c1bf3b2f..02822c4ca4e8cd0feb1b20fae04f3bb51396d863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Note: Breaking changes between versions are indicated by "💥". +## Unreleased + +- [Improvement] Add environment variables to silence ``docker`` and ``docker-compose`` commands. (#268) + ## 3.8.0 (2019-11-22) - [Improvement] Add `k8s-deployments-nginx-volume-mounts` patch diff --git a/docs/local.rst b/docs/local.rst index 01464fc777f2051153ac4a4c724f20f71aa11718..8b63cce78f79d6c690f021c874d24b7ce6ae568c 100644 --- a/docs/local.rst +++ b/docs/local.rst @@ -88,6 +88,16 @@ Finally, tracking logs that store `user events <https://edx.readthedocs.io/proje $(tutor config printroot)/data/lms/logs/tracking.log $(tutor config printroot)/data/cms/logs/tracking.log +Docker command verbosity +~~~~~~~~~~~~~~~~~~~~~~~~ + +The verbosity of ``docker`` and ``docker-compose`` commands can be adjusted by setting the values of the ``DOCKER_LOG_LEVEL`` and ``COMPOSE_LOG_LEVEL`` environment variables. For instance, to silence all output:: + + export DOCKER_LOG_LEVEL=fatal # one of "debug", "info", "warn", "error", "fatal" + export COMPOSE_LOG_LEVEL=critical # one of "debug", "info", "warn", "error", "critical" + +Note that the "fatal" error level is called "critical in docker-compose. + Extra commands -------------- diff --git a/tutor/utils.py b/tutor/utils.py index 979a652f784cf3a009a97301a9340b2b811623e9..4f97549378e8fc521d6f274b8ec650c33108e805 100644 --- a/tutor/utils.py +++ b/tutor/utils.py @@ -11,6 +11,9 @@ from . import exceptions from . import fmt +DOCKER_LOG_LEVEL = os.environ.get("TUTOR_DOCKER_LOG_LEVEL") +COMPOSE_LOG_LEVEL = os.environ.get("TUTOR_COMPOSE_LOG_LEVEL") + def ensure_file_directory_exists(path): """ Create file's base directory if it does not exist. @@ -74,7 +77,10 @@ def docker(*command): raise exceptions.TutorError( "docker is not installed. Please follow instructions from https://docs.docker.com/install/" ) - return execute("docker", *command) + docker_command = ["docker"] + if DOCKER_LOG_LEVEL: + docker_command.append("--log-level=" + DOCKER_LOG_LEVEL.lower()) + return execute(*docker_command, *command) def docker_compose(*command): @@ -82,7 +88,10 @@ def docker_compose(*command): raise exceptions.TutorError( "docker-compose is not installed. Please follow instructions from https://docs.docker.com/compose/install/" ) - return execute("docker-compose", *command) + docker_compose_command = ["docker-compose"] + if COMPOSE_LOG_LEVEL: + docker_compose_command.append("--log-level=" + COMPOSE_LOG_LEVEL.upper()) + return execute(*docker_compose_command, *command) def kubectl(*command):