6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-12-13 14:43:03 +00:00

fix: require at least 4 GB RAM on macOS for local commands

Adds a check in the 'local' command group that requires at least
4 GB of RAM to be allocated to Docker when running any of the
local subcommands on macOS. This addresses a common issue where
Docker's default setting (2 GB) causes startup to crash with
misleading error messages.
This commit is contained in:
Peter Parkkali 2021-10-19 03:43:53 +03:00 committed by Régis Behmo
parent 01d374d2b1
commit fb2aeefd91
3 changed files with 35 additions and 0 deletions

View File

@ -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)

View File

@ -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")

View File

@ -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"])
)