diff --git a/exegol/config/ConstantConfig.py b/exegol/config/ConstantConfig.py index 3110d10e..3a59e536 100644 --- a/exegol/config/ConstantConfig.py +++ b/exegol/config/ConstantConfig.py @@ -23,7 +23,8 @@ class ConstantConfig: exegol_config_path: Path = Path().home() / ".exegol" # Docker Desktop for mac config file docker_desktop_mac_config_path = Path().home() / "Library/Group Containers/group.com.docker/settings.json" - docker_desktop_windows_config_path = Path().home() / "AppData/Roaming/Docker/settings.json" + docker_desktop_windows_config_short_path = "AppData/Roaming/Docker/settings.json" + docker_desktop_windows_config_path = Path().home() / docker_desktop_windows_config_short_path # Install mode, check if Exegol has been git cloned or installed using pip package git_source_installation: bool = (src_root_path_obj / '.git').is_dir() pip_installed: bool = src_root_path_obj.name == "site-packages" diff --git a/exegol/config/EnvInfo.py b/exegol/config/EnvInfo.py index 65200301..135d806d 100644 --- a/exegol/config/EnvInfo.py +++ b/exegol/config/EnvInfo.py @@ -3,7 +3,7 @@ import platform from enum import Enum from pathlib import Path -from typing import Optional, Any, List +from typing import Optional, List, Dict from exegol.config.ConstantConfig import ConstantConfig from exegol.utils.ExeLog import logger @@ -149,6 +149,11 @@ def isMacHost(cls) -> bool: """Return true if macOS is detected on the host""" return cls.getHostOs() == cls.HostOs.MAC + @classmethod + def isLinuxHost(cls) -> bool: + """Return true if Linux is detected on the host""" + return cls.getHostOs() == cls.HostOs.LINUX + @classmethod def isWaylandAvailable(cls) -> bool: """Return true if wayland is detected on the host""" @@ -185,7 +190,7 @@ def getShellType(cls): return "Unknown" @classmethod - def getDockerDesktopSettings(cls) -> Optional[Any]: + def getDockerDesktopSettings(cls) -> Dict: """Applicable only for docker desktop on macos""" if cls.isDockerDesktop(): if cls.__docker_desktop_resource_config is None: @@ -194,20 +199,35 @@ def getDockerDesktopSettings(cls) -> Optional[Any]: elif cls.is_windows_shell: path = ConstantConfig.docker_desktop_windows_config_path else: - return None - # TODO support from WSL shell + # Find docker desktop config + path = None + for i in Path("/mnt/c/Users").glob(f"*/{ConstantConfig.docker_desktop_windows_config_short_path}"): + path = i + logger.debug(f"Docker desktop config found at {path}") + break + if path is None: + return {} try: with open(path, 'r') as docker_desktop_config: cls.__docker_desktop_resource_config = json.load(docker_desktop_config) except FileNotFoundError: logger.warning(f"Docker Desktop configuration file not found: '{path}'") - return None + return {} return cls.__docker_desktop_resource_config - return None + return {} @classmethod def getDockerDesktopResources(cls) -> List[str]: - config = cls.getDockerDesktopSettings() - if config: - return config.get('filesharingDirectories', []) - return [] + return cls.getDockerDesktopSettings().get('filesharingDirectories', []) + + @classmethod + def isHostNetworkAvailable(cls) -> bool: + if cls.isLinuxHost(): + return True + elif cls.isOrbstack(): + return True + elif cls.isDockerDesktop(): + res = cls.getDockerDesktopSettings().get('hostNetworkingEnabled', False) + return res if res is not None else False + logger.warning("Unknown or not supported environment for host network mode.") + return False diff --git a/exegol/model/ContainerConfig.py b/exegol/model/ContainerConfig.py index b15d7a7c..2f6de105 100644 --- a/exegol/model/ContainerConfig.py +++ b/exegol/model/ContainerConfig.py @@ -838,10 +838,13 @@ def setNetworkMode(self, host_mode: Optional[bool]): logger.warning("Host mode cannot be set with NAT ports configured. Disabling the shared network mode.") host_mode = False if EnvInfo.isDockerDesktop() and host_mode: - logger.warning("Docker desktop (Windows & macOS) does not support sharing of host network interfaces.") - logger.verbose("Official doc: https://docs.docker.com/network/host/") - logger.info("To share network ports between the host and exegol, use the [bright_blue]--port[/bright_blue] parameter.") - host_mode = False + if not EnvInfo.isHostNetworkAvailable(): + logger.warning("Host network mode for Docker desktop (Windows & macOS) is not available.") + logger.verbose("Official doc: https://docs.docker.com/network/drivers/host/#docker-desktop") + logger.info("To share network ports between the host and exegol, use the [bright_blue]--port[/bright_blue] parameter.") + host_mode = False + else: + logger.warning("Docker desktop host network mode is enabled but in beta. Everything might not work as you expect.") self.__network_host = host_mode def setPrivileged(self, status: bool = True): diff --git a/exegol/utils/GuiUtils.py b/exegol/utils/GuiUtils.py index 52a7aca0..607a912e 100644 --- a/exegol/utils/GuiUtils.py +++ b/exegol/utils/GuiUtils.py @@ -154,6 +154,7 @@ def __checkDockerDesktopResourcesConfig() -> bool: mount /tmp/.X11-unix for display sharing. Return True if the configuration is correct and /tmp is part of the whitelisted resources """ + # Function not used for now because the X11 socket cannot be used for now with Docker Desktop docker_config = EnvInfo.getDockerDesktopResources() logger.debug(f"Docker Desktop configuration filesharingDirectories: {docker_config}") return '/tmp' in docker_config