Skip to content
Snippets Groups Projects
Commit 7aff1069 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:ambulance: 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.
parent 109730cd
No related branches found
No related tags found
No related merge requests found
......@@ -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
------
......
......@@ -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,16 +220,10 @@
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
)
......@@ -245,5 +229,8 @@
)
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,5 +240,4 @@
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):
......@@ -257,12 +243,3 @@
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:
......@@ -268,6 +245,3 @@
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"
......@@ -273,10 +247,9 @@
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,8 +258,12 @@
"""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:
......@@ -290,13 +267,11 @@
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,
)
......@@ -302,4 +277,5 @@
)
)
return mounts
......@@ -311,14 +287,7 @@
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)
)
......@@ -324,4 +293,14 @@
)
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(
......@@ -326,7 +305,7 @@
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",
)
)
......@@ -330,7 +309,7 @@
"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(
......@@ -335,14 +314,7 @@
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",
)
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment