-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-odoo
executable file
·109 lines (88 loc) · 3.97 KB
/
docker-odoo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
import argparse
import os
import re
from pathlib import Path
from subprocess import run
IMAGES = [(18.0, "noble"), (14.0, "jammy"), (6.1, "bionic")]
SRC = Path.home() / "src"
COMMUNITY = SRC / "odoo"
ENTERPRISE = SRC / "enterprise"
THEMES = SRC / "design-themes"
UPGRADE_UTIL = SRC / "upgrade-util"
UPGRADE = SRC / "upgrade"
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--branch", "-b", help="Odoo branch", required=True)
parser.add_argument("--image", help="Docker image")
parser.add_argument("--build", help="Force rebuilding the image", action="store_true")
parser.add_argument("--http-port", "-p", help="HTTP Port", default="8069")
parser.add_argument("--addons-path", help="Addon paths")
parser.add_argument("--upgrade-path", help="Upgrade paths")
parser.add_argument("--database", "-d", help="Database")
parser.add_argument("-m", nargs="+", help="Debugging mode and script line (e.g., -m pudb file.py:42)")
parser.add_argument("--debugpy-wait", help="Asks debugpy to wait for client connection", action="store_true")
args, extra_args = parser.parse_known_args()
longpolling_port = str(int(args.http_port) + 3)
debug_port = 5678 + (int(args.http_port) - 8069)
odoo_branch = args.branch
odoo_path = COMMUNITY / odoo_branch
odoo_release = {}
odoo_release_file = next(path / "release.py" for path in [odoo_path / "odoo", odoo_path / "openerp"] if path.exists)
with odoo_release_file.open() as fp:
exec(fp.read(), {}, odoo_release)
odoo_version = float(".".join(re.findall(r"\d+", odoo_release["version"])[0:2]))
docker_file = args.image if args.image else next(image for version, image in IMAGES if odoo_version >= version)
paths = {}
for path_type in ["addons", "upgrade"]:
if getattr(args, f"{path_type}_path"):
paths[path_type] = [Path(path).expanduser() for path in args.addons_path.split(",")]
if "addons" not in paths:
paths["addons"] = [odoo_path / "addons"]
for path in [ENTERPRISE, THEMES]:
p = path / odoo_branch
if p.exists():
# In 9.0, enterprise must be put before community in addons path,
# for the web from enterprise which overrides the web module from community
paths["addons"].insert(0, p)
break
if "upgrade" not in paths and odoo_version >= 13.0:
# Before 13.0, it's a symlink from `upgrade` to `odoo/addons/base/maintenance`
paths["upgrade"] = [UPGRADE_UTIL / "src", UPGRADE / "migrations"]
if args.database:
extra_args.extend(["--database", args.database])
if odoo_version < 11.0:
extra_args.append(f"--db-filter=^({args.database})$")
mount_odoo_path = Path("/home/odoo") / odoo_path.relative_to(Path.home())
command = ["podman-compose", "run"]
if args.build:
command += ["--build"]
command += ["--rm", "-p", f"{debug_port}:5678", "-v", f"{odoo_path}:{mount_odoo_path}:ro"]
for path_type, dirs in paths.items():
mount_dirs = [Path("/home/odoo") / path.relative_to(Path.home()) for path in dirs]
for path, mount_path in zip(dirs, mount_dirs):
command += ["-v", f"{path}:{mount_path}:ro"]
extra_args.extend([f"--{path_type}-path", ",".join(str(path) for path in mount_dirs)])
if not extra_args or extra_args[0] != "shell":
command += [
"-p",
f"{args.http_port}:8069",
"-p",
f"{longpolling_port}:8072",
]
# Name of the service in the docker-compose file
command += ["odoo"]
python_bin = "python3" if odoo_version >= 11.0 else "python2"
odoo_bin_name = "odoo-bin" if odoo_version > 9.0 else "openerp-server"
odoo_bin = str(mount_odoo_path / odoo_bin_name)
command += [python_bin]
if args.m:
command += ["-m"] + args.m
else:
if python_bin == "python3":
command += ["-Xfrozen_modules=off"]
debugpy = ["-m", "debugpy", "--listen", "0.0.0.0:5678"]
if args.debugpy_wait:
debugpy += ["--wait-for-client"]
command += debugpy
command += [odoo_bin, *extra_args]
run(command, env=dict(os.environ, DOCKERFILE=docker_file), cwd=os.path.dirname(os.path.realpath(__file__)))