Skip to content

Commit 20c2214

Browse files
committed
feat(update): add repo_subdir support for monorepo deployments
1 parent 1cadb31 commit 20c2214

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

SPEC.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ file values, which take precedence over built-in defaults.
8989
**Signature**
9090

9191
```bash
92-
deploy [--config FILE] configure <instance_name> [<ssh_host>] [<repo_url>] [--type odoo|python|service] [-p <ssh_port>]
92+
deploy [--config FILE] configure <instance_name> [<ssh_host>] [<repo_url>] [--type odoo|python|service] [-p <ssh_port>] [--force] [--repo-subdir <subdir>]
9393
```
9494

9595
**Arguments**
@@ -98,15 +98,16 @@ deploy [--config FILE] configure <instance_name> [<ssh_host>] [<repo_url>] [--ty
9898
|----------------|------------------------|------------------------------------------------------------------------------|
9999
| `instance_name` | Always | Logical name for the instance (used for paths and service name) |
100100
| `ssh_host` | If not in config | SSH target, or `localhost` / omit to deploy locally without SSH |
101-
| `ssh_port` | If not in config | SSH port, default 22 |
102101
| `repo_url` | If not in config | Git repository URL (e.g. `git@github.com:org/repo.git`) |
103102

104103
**Options**
105104

106105
| Option | Default | Description |
107106
|----------------|----------|-----------------------------------------------------------------------------------------------------|
108107
| `--type` | auto | Deployment type: `odoo`, `python`, or `service`; auto-detected from instance name prefix if omitted |
108+
| `-p` | `22` | SSH port, default 22 |
109109
| `--force` | `False` | Re-run steps 3–4 even if the instance directory already exists |
110+
| `--repo-subdir`| `None` | Subdirectory within the repository to work on, if any |
110111

111112
**Steps (executed in order)**
112113

@@ -170,7 +171,7 @@ deploy [--config FILE] configure <instance_name> [<ssh_host>] [<repo_url>] [--ty
170171
**Signature**
171172
172173
```bash
173-
deploy [--config FILE] update <instance_name> [<ssh_host>] [-p <ssh_port>] [--type odoo|python|service] [--db DATABASE]
174+
deploy [--config FILE] update <instance_name> [<ssh_host>] [-p <ssh_port>] [--type odoo|python|service] [--db DATABASE] [--ignore-hooks] [--repo-subdir <subdir>]
174175
```
175176
176177
**Arguments**
@@ -179,15 +180,16 @@ deploy [--config FILE] update <instance_name> [<ssh_host>] [-p <ssh_port>] [--ty
179180
|----------------|------------------------|------------------------------------------------------------------------------|
180181
| `instance_name` | Always | Name of the previously configured instance |
181182
| `ssh_host` | If not in config | SSH target, or `localhost` / omit to deploy locally without SSH |
182-
| `ssh_port` | If not in config | SSH port, default 22 |
183183
184184
**Options**
185185
186186
| Option | Default | Description |
187187
|--------------------|-------------------|----------------------------------------------------------|
188188
| `--type` | auto | Deployment type: `odoo`, `python`, or `service`; auto-detected from instance name prefix if omitted |
189+
| `-p` | `22` | SSH port, default 22 |
189190
| `--db` | `<instance_name>` | (Odoo only) Override the target database name |
190191
| `--ignore-hooks` | `False` | Skip all hook execution |
192+
| `--repo-subdir` | `None` | Subdirectory within the repository to work on, if any |
191193
192194
**Hooks**
193195

deploy/command/update.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
default=False,
3939
help="Skip all hook execution.",
4040
)
41+
@click.option(
42+
"--repo-subdir",
43+
"repo_subdir",
44+
default=None,
45+
help="Subdirectory within the repo to use as the service root (for monorepos).",
46+
)
4147
@click.pass_context
4248
def update( # noqa: C901
4349
ctx: click.Context,
@@ -47,6 +53,7 @@ def update( # noqa: C901
4753
db: str | None,
4854
ssh_port: int | None,
4955
ignore_hooks: bool,
56+
repo_subdir: str | None,
5057
) -> None:
5158
"""Update an existing deployment instance."""
5259
cfg = load_config(ctx.obj["config"], instance_name)
@@ -58,6 +65,7 @@ def update( # noqa: C901
5865
ssh_port=ssh_port,
5966
deploy_type=deploy_type,
6067
db=db,
68+
repo_subdir=repo_subdir,
6169
)
6270
except ValueError as exc:
6371
raise click.ClickException(click.style(str(exc), fg="red")) from exc
@@ -71,6 +79,8 @@ def update( # noqa: C901
7179
executor = Executor(eff_ssh_host, ctx.obj["verbose"], ssh_port=eff_ssh_port)
7280
home_dir = executor.capture("echo $HOME")
7381
instance_path = f"{home_dir}/{instance_name}"
82+
eff_repo_subdir: str | None = opts.get("repo_subdir")
83+
service_path = f"{instance_path}/{eff_repo_subdir}" if eff_repo_subdir else instance_path
7484

7585
def run_hooks(hook_name: str) -> bool:
7686
"""Execute all commands for *hook_name*. Returns True if all succeeded."""
@@ -127,18 +137,18 @@ def run_hooks(hook_name: str) -> bool:
127137
# Step 6: Update dependencies / rebuild
128138
click.secho("\nUpdating dependencies…", fg="green")
129139
try:
140+
executor.run(
141+
"if [ -f addons/repos.yaml ]; then cd addons/ && gitaggregate -c repos.yaml; fi",
142+
cwd=instance_path,
143+
)
130144
if eff_type == "odoo":
131-
executor.run(
132-
"if [ -f addons/repos.yaml ]; then cd addons/ && gitaggregate -c repos.yaml; fi",
133-
cwd=instance_path,
134-
)
135145
executor.run("odoo-venv update .venv --backup --yes", cwd=instance_path)
136146
elif eff_type == "python":
137-
setup_python_deps(executor, instance_path)
147+
setup_python_deps(executor, service_path)
138148
else: # service
139149
build_cmd: str | None = opts.get("build")
140150
if build_cmd:
141-
executor.run(build_cmd, cwd=instance_path)
151+
executor.run(build_cmd, cwd=service_path)
142152
except ExecutorError as exc:
143153
run_hooks("post-update")
144154
run_hooks("post-update-fail")

0 commit comments

Comments
 (0)