diff --git a/CHANGELOG.md b/CHANGELOG.md index e18b348..791c87f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Note: Breaking changes between versions are indicated by "💥". ## v12.1.5 (2021-10-25) - 💥[Improvement] Change the `settheme` command such that, by default, a custom theme is assigned to the LMS and the CMS, both in production and development mode. +- [Bugfix] Check Docker memory allocation on macOS when running tutor local commands (#463) ## v12.1.4 (2021-10-11) diff --git a/tutor/commands/local.py b/tutor/commands/local.py index ce3b041..3ed3621 100644 --- a/tutor/commands/local.py +++ b/tutor/commands/local.py @@ -37,6 +37,7 @@ def docker_compose(root: str, config: Config, *command: str) -> int: @click.pass_obj def local(context: Context) -> None: context.docker_compose_func = docker_compose + utils.check_macos_memory() @click.command(help="Configure and run Open edX from scratch") diff --git a/tutor/utils.py b/tutor/utils.py index 30c9a01..697de02 100644 --- a/tutor/utils.py +++ b/tutor/utils.py @@ -244,3 +244,36 @@ def check_output(*command: str) -> bytes: raise exceptions.TutorError( "Command failed: {}".format(" ".join(command)) ) from e + + +def check_macos_memory() -> None: + """ + Try to assert that the RAM allocated to the Docker VM on macOS is at least 4 GB. + """ + if sys.platform != "darwin": + return + + try: + settings_path = ( + "{}/Library/Group Containers/group.com.docker/settings.json".format( + os.path.expanduser("~") + ) + ) + with open(settings_path) as fp: + data = json.load(fp) + except Exception as e: + # Ignore any IO and JSON parse errors + return + + if "memoryMiB" not in data or not isinstance(data["memoryMiB"], int): + # Ignore absent / erratic values (Docker creates the file with the default setting of 2048 explicitly + # written in, so we shouldn't need to assume a default value here). + return + + if data["memoryMiB"] < 4096: + raise exceptions.TutorError( + ( + "Docker must be allocated at least 4 GB of memory on macOS (found {} MB). " + + "Please follow instructions from https://docs.tutor.overhang.io/install.html" + ).format(data["memoryMiB"]) + )