odoo-deploy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- odoo_deploy/__init__.py +18 -0
- odoo_deploy/actions.py +332 -0
- odoo_deploy/aggregate.py +1140 -0
- odoo_deploy/builders/__init__.py +33 -0
- odoo_deploy/builders/base.py +348 -0
- odoo_deploy/builders/docker.py +84 -0
- odoo_deploy/builders/podman.py +86 -0
- odoo_deploy/builders/zip.py +109 -0
- odoo_deploy/catalog/17.0.yaml +15 -0
- odoo_deploy/catalog/18.0.yaml +15 -0
- odoo_deploy/catalog/19.0.yaml +18 -0
- odoo_deploy/catalog/20.0.yaml +18 -0
- odoo_deploy/catalog.py +164 -0
- odoo_deploy/cli.py +840 -0
- odoo_deploy/config.py +148 -0
- odoo_deploy/deploy_assets.py +67 -0
- odoo_deploy/dev_requirements.py +183 -0
- odoo_deploy/init_project.py +660 -0
- odoo_deploy/ops.py +543 -0
- odoo_deploy/templates/deploy/.env.prod.example +72 -0
- odoo_deploy/templates/deploy/.env.staging.example +36 -0
- odoo_deploy/templates/deploy/bootstrap-instance.sh +341 -0
- odoo_deploy/templates/deploy/install-docker.sh +9 -0
- odoo_deploy/templates/deploy/install-podman.sh +10 -0
- odoo_deploy/templates/deploy/prod.yaml +139 -0
- odoo_deploy/templates/deploy/staging.yaml +90 -0
- odoo_deploy/templates/docker/Dockerfile +121 -0
- odoo_deploy/templates/docker/docker-bake.hcl +28 -0
- odoo_deploy/templates/docker/entrypoint.py +96 -0
- odoo_deploy/templates/zip/install.sh +41 -0
- odoo_deploy/templates/zip/odoo.service +17 -0
- odoo_deploy/venv.py +419 -0
- odoo_deploy-0.1.0.dist-info/METADATA +109 -0
- odoo_deploy-0.1.0.dist-info/RECORD +37 -0
- odoo_deploy-0.1.0.dist-info/WHEEL +4 -0
- odoo_deploy-0.1.0.dist-info/entry_points.txt +2 -0
- odoo_deploy-0.1.0.dist-info/licenses/LICENSE +661 -0
odoo_deploy/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
# Copyright 2026 - Ronald Portier (Open Eye Development)
|
|
3
|
+
"""odoo-deploy — stateless CLI that builds deployment-ready Odoo artifacts.
|
|
4
|
+
|
|
5
|
+
The tool consumes a per-company project repository (manifest + supporting
|
|
6
|
+
files) and produces one of three artifact types:
|
|
7
|
+
|
|
8
|
+
- zip + systemd service templates (Debian host with system Python/Postgres)
|
|
9
|
+
- Docker images (staging = demo on + Mailhog, prod = no demo + real SMTP)
|
|
10
|
+
- Debian package (designed but deferred in v1)
|
|
11
|
+
|
|
12
|
+
All artifacts are self-contained: no git-aggregate, git, or other build
|
|
13
|
+
tooling is needed at runtime — all code is baked in at build time.
|
|
14
|
+
|
|
15
|
+
The tool itself is stateless: the project repository IS the state.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.0"
|
odoo_deploy/actions.py
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
# Copyright 2026 - Ronald Portier (Open Eye Development)
|
|
3
|
+
"""``odoo-deploy <action>`` — operate on a dev Odoo instance.
|
|
4
|
+
|
|
5
|
+
Actions (flat subcommands, matching the existing ``bin/`` scripts):
|
|
6
|
+
|
|
7
|
+
- ``run`` Run Odoo in the foreground (for debugging).
|
|
8
|
+
- ``start`` Start the instance (systemd in prod, foreground in dev).
|
|
9
|
+
- ``stop`` Stop the instance (systemd in prod, remind Ctrl-C in dev).
|
|
10
|
+
- ``status`` Show instance status (systemctl or pgrep).
|
|
11
|
+
- ``install`` Install Odoo modules (``-i``).
|
|
12
|
+
- ``update`` Update Odoo modules (``-u``, defaults to ``base``).
|
|
13
|
+
- ``test`` Run tests for modules (``-i`` + ``--test-enable``).
|
|
14
|
+
|
|
15
|
+
Dev vs. prod detection: the presence of ``/etc/systemd/system/odoo-<instance>.service``
|
|
16
|
+
means production (systemd manages the lifecycle). Absence means dev
|
|
17
|
+
(run in foreground, no sudo).
|
|
18
|
+
|
|
19
|
+
Instance name resolution (priority):
|
|
20
|
+
1. ``--instance`` flag
|
|
21
|
+
2. ``project`` field in ``project.yaml``
|
|
22
|
+
3. ``basename(dirname(project_dir))`` if the project dir is named ``odoo``
|
|
23
|
+
(sat-compat: sat instances live at ``~/odoo-dev/<inst>/odoo/``)
|
|
24
|
+
4. ``basename(project_dir)``
|
|
25
|
+
|
|
26
|
+
Database name = instance name (convention; overridable later via project.yaml).
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
import os
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
from dataclasses import dataclass
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
|
|
35
|
+
import yaml
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ActionError(Exception):
|
|
39
|
+
"""Raised when an action cannot complete (missing files, etc.)."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _info(msg: str) -> None:
|
|
43
|
+
print(f"[INFO] {msg}", file=sys.stderr)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _warn(msg: str) -> None:
|
|
47
|
+
print(f"[WARN] {msg}", file=sys.stderr)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _error(msg: str) -> None:
|
|
51
|
+
print(f"[ERROR] {msg}", file=sys.stderr)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# ─── instance detection ───────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class Instance:
|
|
59
|
+
"""Resolved paths and metadata for an Odoo instance."""
|
|
60
|
+
|
|
61
|
+
project_dir: Path
|
|
62
|
+
instance: str
|
|
63
|
+
python: Path
|
|
64
|
+
odoo_bin: Path
|
|
65
|
+
config: Path
|
|
66
|
+
db: str
|
|
67
|
+
service: str
|
|
68
|
+
is_dev: bool
|
|
69
|
+
|
|
70
|
+
def require(self, *paths: Path, what: str) -> None:
|
|
71
|
+
"""Check that required paths exist; raise ActionError if not."""
|
|
72
|
+
missing = [p for p in paths if not p.exists()]
|
|
73
|
+
if missing:
|
|
74
|
+
raise ActionError(
|
|
75
|
+
f"missing {what}:\n "
|
|
76
|
+
+ "\n ".join(str(p) for p in missing)
|
|
77
|
+
+ "\nHint: run `odoo-deploy aggregate` first."
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def read_manifest(project_dir: Path) -> dict:
|
|
82
|
+
"""Read project.yaml if it exists; return empty dict otherwise."""
|
|
83
|
+
manifest = project_dir / "project.yaml"
|
|
84
|
+
if not manifest.exists():
|
|
85
|
+
return {}
|
|
86
|
+
data = yaml.safe_load(manifest.read_text(encoding="utf-8"))
|
|
87
|
+
return data if isinstance(data, dict) else {}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def detect_instance(project_dir: Path, explicit: str | None = None) -> Instance:
|
|
91
|
+
"""Detect the instance configuration from the project directory.
|
|
92
|
+
|
|
93
|
+
Raises ActionError if the project directory doesn't exist.
|
|
94
|
+
"""
|
|
95
|
+
project_dir = project_dir.resolve()
|
|
96
|
+
if not project_dir.is_dir():
|
|
97
|
+
raise ActionError(f"project directory not found: {project_dir}")
|
|
98
|
+
|
|
99
|
+
# Resolve instance name.
|
|
100
|
+
if explicit:
|
|
101
|
+
instance = explicit
|
|
102
|
+
else:
|
|
103
|
+
manifest = read_manifest(project_dir)
|
|
104
|
+
instance = manifest.get("project") or ""
|
|
105
|
+
if not instance:
|
|
106
|
+
# sat-compat: if the dir is named "odoo", the instance is the
|
|
107
|
+
# parent dir name (sat instances live at ~/odoo-dev/<inst>/odoo/).
|
|
108
|
+
if project_dir.name == "odoo":
|
|
109
|
+
instance = project_dir.parent.name
|
|
110
|
+
else:
|
|
111
|
+
instance = project_dir.name
|
|
112
|
+
|
|
113
|
+
# Paths.
|
|
114
|
+
python = project_dir / ".venv" / "bin" / "python"
|
|
115
|
+
odoo_bin = project_dir / "parts" / "odoo" / "odoo-bin"
|
|
116
|
+
config = project_dir / "etc" / "odoo.conf"
|
|
117
|
+
db = instance
|
|
118
|
+
service = f"odoo-{instance}"
|
|
119
|
+
|
|
120
|
+
# Dev/prod: presence of systemd service file = production.
|
|
121
|
+
svc_file = Path("/etc/systemd/system") / f"{service}.service"
|
|
122
|
+
is_dev = not svc_file.exists()
|
|
123
|
+
|
|
124
|
+
return Instance(
|
|
125
|
+
project_dir=project_dir,
|
|
126
|
+
instance=instance,
|
|
127
|
+
python=python,
|
|
128
|
+
odoo_bin=odoo_bin,
|
|
129
|
+
config=config,
|
|
130
|
+
db=db,
|
|
131
|
+
service=service,
|
|
132
|
+
is_dev=is_dev,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# ─── helpers ─────────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _require_runtime(inst: Instance) -> None:
|
|
140
|
+
"""Check that the instance is ready to run Odoo (venv, source, config)."""
|
|
141
|
+
inst.require(inst.python, what="Python venv")
|
|
142
|
+
inst.require(inst.odoo_bin, what="Odoo source")
|
|
143
|
+
inst.require(inst.config, what="Odoo config")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _run_odoo(inst: Instance, *args: str) -> int:
|
|
147
|
+
"""Run odoo-bin with the given args. Returns the exit code."""
|
|
148
|
+
cmd = [str(inst.python), str(inst.odoo_bin), "--config", str(inst.config), *args]
|
|
149
|
+
return subprocess.run(cmd, cwd=str(inst.project_dir)).returncode
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _exec_odoo(inst: Instance, *args: str) -> None:
|
|
153
|
+
"""Exec odoo-bin, replacing the current process (for `run`)."""
|
|
154
|
+
os.execv(
|
|
155
|
+
str(inst.python),
|
|
156
|
+
[str(inst.python), str(inst.odoo_bin), "--config", str(inst.config), *args],
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _systemctl(inst: Instance, action: str) -> bool:
|
|
161
|
+
"""Run systemctl start/stop on the instance service. Returns True on success."""
|
|
162
|
+
_info(f"{action.capitalize()}ing {inst.service}...")
|
|
163
|
+
result = subprocess.run(["sudo", "systemctl", action, inst.service])
|
|
164
|
+
return result.returncode == 0
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _check_service_active(inst: Instance) -> bool:
|
|
168
|
+
"""Check if the systemd service is active."""
|
|
169
|
+
result = subprocess.run(
|
|
170
|
+
["systemctl", "is-active", "--quiet", inst.service],
|
|
171
|
+
)
|
|
172
|
+
return result.returncode == 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# ─── actions ─────────────────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def run(inst: Instance, extra_args: list[str]) -> None:
|
|
179
|
+
"""Run Odoo in the foreground. Auto-enables --dev=all in dev mode."""
|
|
180
|
+
_require_runtime(inst)
|
|
181
|
+
args: list[str] = []
|
|
182
|
+
if inst.is_dev:
|
|
183
|
+
args.append("--dev=all")
|
|
184
|
+
args.extend(extra_args)
|
|
185
|
+
_info(
|
|
186
|
+
f"Running Odoo (instance: {inst.instance}, {'dev' if inst.is_dev else 'prod'})"
|
|
187
|
+
)
|
|
188
|
+
_exec_odoo(inst, *args)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def start(inst: Instance) -> None:
|
|
192
|
+
"""Start the Odoo instance."""
|
|
193
|
+
if inst.is_dev:
|
|
194
|
+
_info("Dev instance — starting in foreground (Ctrl-C to stop)...")
|
|
195
|
+
# In dev, start = run in foreground.
|
|
196
|
+
_require_runtime(inst)
|
|
197
|
+
_exec_odoo(inst, "--dev=all")
|
|
198
|
+
return
|
|
199
|
+
# Production: systemd.
|
|
200
|
+
if not _systemctl(inst, "start"):
|
|
201
|
+
_error(
|
|
202
|
+
f"{inst.service} failed to start. Check: journalctl -u {inst.service} -n 50"
|
|
203
|
+
)
|
|
204
|
+
raise ActionError(f"{inst.service} failed to start")
|
|
205
|
+
import time
|
|
206
|
+
|
|
207
|
+
time.sleep(3)
|
|
208
|
+
if _check_service_active(inst):
|
|
209
|
+
_info(f"{inst.service} is running.")
|
|
210
|
+
else:
|
|
211
|
+
_error(
|
|
212
|
+
f"{inst.service} failed to start. Check: journalctl -u {inst.service} -n 50"
|
|
213
|
+
)
|
|
214
|
+
raise ActionError(f"{inst.service} failed to start")
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def stop(inst: Instance) -> None:
|
|
218
|
+
"""Stop the Odoo instance."""
|
|
219
|
+
if inst.is_dev:
|
|
220
|
+
_info("Dev instance has no service to stop.")
|
|
221
|
+
_info("Press Ctrl-C in the terminal running `odoo-deploy run`.")
|
|
222
|
+
return
|
|
223
|
+
_systemctl(inst, "stop")
|
|
224
|
+
_info(f"{inst.service} stopped.")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def status(inst: Instance) -> int:
|
|
228
|
+
"""Show the status of the Odoo instance. Returns exit code (0=running)."""
|
|
229
|
+
if inst.is_dev:
|
|
230
|
+
# pgrep for the odoo-bin process belonging to this instance.
|
|
231
|
+
result = subprocess.run(
|
|
232
|
+
["pgrep", "-f", f"odoo-bin.*{inst.instance}"],
|
|
233
|
+
capture_output=True,
|
|
234
|
+
text=True,
|
|
235
|
+
)
|
|
236
|
+
pids = result.stdout.strip().split()
|
|
237
|
+
if pids:
|
|
238
|
+
_info(f"Odoo is running (PID: {' '.join(pids)})")
|
|
239
|
+
subprocess.run(["ps", "-o", "pid,etime,args", "-p", *pids])
|
|
240
|
+
return 0
|
|
241
|
+
_info("Odoo is not running. Start with: odoo-deploy run")
|
|
242
|
+
return 1
|
|
243
|
+
# Production: systemctl status.
|
|
244
|
+
result = subprocess.run(["systemctl", "status", inst.service])
|
|
245
|
+
return result.returncode
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def install(inst: Instance, modules: list[str]) -> None:
|
|
249
|
+
"""Install Odoo modules: stop service, install, restart (in prod)."""
|
|
250
|
+
if not modules:
|
|
251
|
+
raise ActionError(
|
|
252
|
+
"no modules specified. Usage: odoo-deploy install <module ...>"
|
|
253
|
+
)
|
|
254
|
+
_require_runtime(inst)
|
|
255
|
+
mods_str = ",".join(modules)
|
|
256
|
+
_info(f"Installing module(s): {mods_str}")
|
|
257
|
+
|
|
258
|
+
if not inst.is_dev:
|
|
259
|
+
_systemctl(inst, "stop")
|
|
260
|
+
|
|
261
|
+
_info(f"Installing module(s): {mods_str}...")
|
|
262
|
+
code = _run_odoo(inst, "-d", inst.db, "-i", mods_str, "--stop-after-init")
|
|
263
|
+
if code != 0:
|
|
264
|
+
raise ActionError(f"install failed (exit {code})")
|
|
265
|
+
|
|
266
|
+
if not inst.is_dev:
|
|
267
|
+
if not _systemctl(inst, "start"):
|
|
268
|
+
raise ActionError(f"{inst.service} failed to start after install")
|
|
269
|
+
import time
|
|
270
|
+
|
|
271
|
+
time.sleep(3)
|
|
272
|
+
if _check_service_active(inst):
|
|
273
|
+
_info(f"{inst.service} is running.")
|
|
274
|
+
else:
|
|
275
|
+
raise ActionError(
|
|
276
|
+
f"{inst.service} failed to start. Check: journalctl -u {inst.service} -n 50"
|
|
277
|
+
)
|
|
278
|
+
else:
|
|
279
|
+
_info("Install complete. Start with: odoo-deploy run")
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def update(inst: Instance, modules: list[str]) -> None:
|
|
283
|
+
"""Update Odoo modules: stop service, upgrade, restart (in prod)."""
|
|
284
|
+
mods = modules or ["base"]
|
|
285
|
+
_require_runtime(inst)
|
|
286
|
+
mods_str = ",".join(mods)
|
|
287
|
+
_info(f"Updating module(s): {mods_str}")
|
|
288
|
+
|
|
289
|
+
if not inst.is_dev:
|
|
290
|
+
_systemctl(inst, "stop")
|
|
291
|
+
|
|
292
|
+
_info(f"Upgrading module(s): {mods_str}...")
|
|
293
|
+
code = _run_odoo(inst, "-d", inst.db, "-u", mods_str, "--stop-after-init")
|
|
294
|
+
if code != 0:
|
|
295
|
+
raise ActionError(f"update failed (exit {code})")
|
|
296
|
+
|
|
297
|
+
if not inst.is_dev:
|
|
298
|
+
if not _systemctl(inst, "start"):
|
|
299
|
+
raise ActionError(f"{inst.service} failed to start after update")
|
|
300
|
+
import time
|
|
301
|
+
|
|
302
|
+
time.sleep(3)
|
|
303
|
+
if _check_service_active(inst):
|
|
304
|
+
_info(f"{inst.service} is running.")
|
|
305
|
+
else:
|
|
306
|
+
raise ActionError(
|
|
307
|
+
f"{inst.service} failed to start. Check: journalctl -u {inst.service} -n 50"
|
|
308
|
+
)
|
|
309
|
+
else:
|
|
310
|
+
_info("Update complete. Start with: odoo-deploy run")
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def test(inst: Instance, modules: list[str]) -> None:
|
|
314
|
+
"""Run tests for one or more Odoo modules. Does NOT interact with the service."""
|
|
315
|
+
if not modules:
|
|
316
|
+
raise ActionError("no modules specified. Usage: odoo-deploy test <module ...>")
|
|
317
|
+
_require_runtime(inst)
|
|
318
|
+
mods_str = ",".join(modules)
|
|
319
|
+
_info(f"Testing module(s): {mods_str}")
|
|
320
|
+
code = _run_odoo(
|
|
321
|
+
inst,
|
|
322
|
+
"-d",
|
|
323
|
+
inst.db,
|
|
324
|
+
"-i",
|
|
325
|
+
mods_str,
|
|
326
|
+
"--test-enable",
|
|
327
|
+
"--log-level=test",
|
|
328
|
+
"--stop-after-init",
|
|
329
|
+
)
|
|
330
|
+
if code != 0:
|
|
331
|
+
raise ActionError(f"test failed (exit {code})")
|
|
332
|
+
_info("Test run complete.")
|