# HG changeset patch # User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr> # Date 1677165920 -3600 # Thu Feb 23 16:25:20 2023 +0100 # Node ID 7aff1069ce825f479fcd54e93260d56daef40552 # Parent 109730cd95f5cf873d4d4ac8cb56897d1ef5d744 🚑 docker_dev_start: Change how odoo sources is mounted in the image. It leaves the installed module path alone and also avoids ending up with empty directory in the odoo clone’s odoo/addons directory. diff --git a/NEWS.rst b/NEWS.rst --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,13 @@ History ======= +19.0.2 +------ + +docker_dev_start: Change how odoo sources is mounted in the image. +It leaves the installed module path alone and also avoids ending up with empty directory in the odoo clone’s +``odoo/addons`` directory. + 19.0.1 ------ diff --git a/odoo_scripts/docker_client.py b/odoo_scripts/docker_client.py --- a/odoo_scripts/docker_client.py +++ b/odoo_scripts/docker_client.py @@ -12,17 +12,7 @@ from docker.models.containers import Container # type: ignore[import] from docker.types import Mount # type: ignore[import] -from .config import ( - ODOO_7, - ODOO_8, - ODOO_9, - ODOO_10, - ODOO_11, - ODOO_13, - ODOO_15, - ODOO_16, - Configuration, -) +from .config import ODOO_7, ODOO_8, ODOO_9, ODOO_10, Configuration _logger = logging.getLogger(__name__) @@ -230,20 +220,17 @@ cls._replace_then_print(replaces, log) -def pythons_used(config) -> Tuple: - pythons: Tuple - if config.odoo_type == ODOO_10: - pythons = ("python2.7",) - elif config.odoo_type == ODOO_11: - pythons = ("python3.5", "python3.6", "python3.8") - elif config.odoo_type == ODOO_13: - pythons = ("python3.8",) - elif config.odoo_type in (ODOO_15, ODOO_16): - pythons = ( - "python3.9", - "python3.10", +def get_odoo_base_path(config: Configuration) -> str: + """Return value of env ODOO_BASE_PATH in the local image name.""" + image = DockerClient.client.images.list(config.local_image_name) + if not image: + raise Exception( + "Image %s is not built, needed to be inspected", config.local_image_name ) - return pythons + for env in image[0].attrs["Config"]["Env"]: + if env.startswith("ODOO_BASE_PATH="): + return env[15:] + raise Exception("Missing ODOO_BASE_PATH in the image") def modules_mount(config: Configuration) -> Tuple[List[Mount], Dict[str, str]]: @@ -253,30 +240,16 @@ project_path = config.path mount_list: List[Mount] = [] mount_dict: Dict[str, str] = {} - target_paths: List[str] if config.odoo_type in (ODOO_7, ODOO_8, ODOO_9, ODOO_10): - target_paths = ["/opt/odoo/sources/odoo/addons"] - elif config.odoo_type in ( - ODOO_11, - ODOO_13, - ODOO_15, - ): - target_paths = [ - f"/usr/local/lib/{python}/dist-packages/odoo/addons" - for python in pythons_used(config) - ] + target_path = "/opt/odoo/sources/odoo/addons" else: - target_paths = [ - f"/opt/odoo/lib/{python}/site-packages/odoo/addons" - for python in pythons_used(config) - ] + target_path = get_odoo_base_path(config) + "/addons" - for target_path in target_paths: - for module in modules: - full_target_path = os.path.join(target_path, os.path.basename(module)) - full_project_path = os.path.realpath(os.path.join(project_path, module)) - mount_list.append(Mount(full_target_path, full_project_path, "bind")) - mount_dict[full_target_path] = full_project_path + for module in modules: + full_target_path = os.path.join(target_path, os.path.basename(module)) + full_project_path = os.path.realpath(os.path.join(project_path, module)) + mount_list.append(Mount(full_target_path, full_project_path, "bind")) + mount_dict[full_target_path] = full_project_path return mount_list, mount_dict @@ -285,21 +258,24 @@ """Return a list of mounts for all the anthem songs present in the super project.""" project_path = os.path.realpath(config.path) mounts: List[Mount] = [] - # also mount songs for anthem to avoid having to rebuild the image when they - # are changed. + # No anthem on old ODOO + if config.odoo_type in (ODOO_7, ODOO_8, ODOO_9, ODOO_10): + return mounts + # Mount songs for anthem to avoid having to rebuild the image when they are changed. + # Assume they are in songs/something and put in the image in the same place Odoo is + # installed. if os.path.exists("songs"): for root, dirs, _files in os.walk("songs"): for directory in dirs: - # with older odoo this will not be set - for python in pythons_used(config): - mounts.append( - Mount( - f"/usr/local/lib/{python}/dist-packages/{root}/{directory}", - os.path.join(project_path, root, directory), - "bind", - read_only=True, - ) + mounts.append( + Mount( + os.path.dirname(get_odoo_base_path(config)) + + f"/{root}/{directory}", + os.path.join(project_path, root, directory), + "bind", + read_only=True, ) + ) return mounts @@ -311,38 +287,34 @@ mounts.append(Mount("/opt/odoo/sources/odoo", source_path, "bind")) else: install_path = ( - "/usr/local/lib/%s/dist-packages/odoo" - if config.odoo_type - in ( - ODOO_9, - ODOO_10, - ODOO_11, - ODOO_13, - ODOO_15, - ) - else "/opt/odoo/lib/%s/site-packages/odoo" + "/usr/local/lib/python2.7/dist-packages/odoo" + if config.odoo_type in (ODOO_9, ODOO_10) + else get_odoo_base_path(config) ) - for python in pythons_used(config): + for entry in os.listdir(os.path.join(full_source_path, "odoo")): + if entry != "addons": + mounts.append( + Mount( + install_path + "/" + entry, + os.path.join(full_source_path, "odoo", entry), + "bind", + ) + ) + for entry in os.listdir(os.path.join(full_source_path, "odoo", "addons")): + # for directory in dirs: mounts.append( Mount( - install_path % python, - os.path.join(full_source_path, "odoo"), + install_path + "/addons/" + entry, + os.path.join(full_source_path, "odoo", "addons", entry), "bind", ) ) - # iterate on all the modules, avoids - addons_path = os.path.join(full_source_path, "addons") + # iterate on all the modules, avoids + for entry in os.listdir(os.path.join(full_source_path, "addons")): mounts.append( Mount( - install_path % python + "/addons", - addons_path, - "bind", - ) - ) - mounts.append( - Mount( - install_path % python + "/addons/base", - os.path.join(full_source_path, "odoo", "addons", "base"), + install_path + "/addons/" + entry, + os.path.join(full_source_path, "addons", entry), "bind", ) )