Skip to content

Commit 8379740

Browse files
committed
feat(cli): integrate Docker driver
- Register DockerDriver in DRIVER_BY_NAME - test-cmdeploy: dispatch to driver class from container metadata - Fix _print_builder_repos to use driver REPO_NAME (avoids dupes)
1 parent 71f4cd3 commit 8379740

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

src/cmlxc/cli.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""cmlxc -- Manage local chatmail relay containers via Incus.
22
33
Standard workflow:
4-
init -> deploy-cmdeploy/deploy-madmail -> test-cmdeploy/test-madmail/test-mini.
4+
init -> deploy-cmdeploy/deploy-madmail/docker deploy -> test-*/test-mini.
55
"""
66

77
import argparse
@@ -22,6 +22,7 @@
2222
)
2323
from cmlxc.driver_base import __version__
2424
from cmlxc.driver_cmdeploy import CmdeployDriver
25+
from cmlxc.driver_docker import DockerDriver
2526
from cmlxc.driver_madmail import MadmailDriver, print_admin_info
2627
from cmlxc.incus import Incus, _is_ip_address, check_cgroup_compat
2728
from cmlxc.output import Out
@@ -259,13 +260,25 @@ def _add_test_relay_args(parser):
259260

260261
def test_cmdeploy_cmd_options(parser):
261262
_add_test_relay_args(parser)
263+
parser.add_argument(
264+
"--relay-ref",
265+
default=None,
266+
help="Override relay git ref for tests (default: SHA from deployed image label).",
267+
)
262268

263269

264270
def test_cmdeploy_cmd(args, out):
265271
"""Run cmdeploy integration tests inside the builder container."""
266272
ix = Incus(out)
267273
ct = ix.get_running_relay(args.relay)
268-
driver = CmdeployDriver(ct, out)
274+
drv_cls = DRIVER_BY_NAME.get(ct.driver_name)
275+
if drv_cls is None:
276+
out.red(
277+
f"Warning: unknown driver {ct.driver_name!r} for"
278+
f" {ct.shortname}, falling back to cmdeploy."
279+
)
280+
drv_cls = CmdeployDriver
281+
driver = drv_cls(ct, out)
269282
if not driver.check_init():
270283
return 1
271284

@@ -295,6 +308,8 @@ def test_cmdeploy_cmd(args, out):
295308
drv2 = DRIVER_BY_NAME[ct2.driver_name](ct2, out)
296309
second_domain = drv2.get_test_domain_or_ip()
297310

311+
if args.relay_ref is not None:
312+
os.environ["RELAY_REF"] = args.relay_ref
298313
return driver.run_tests(second_domain=second_domain)
299314

300315

@@ -520,11 +535,16 @@ def _print_container_status(out, c, ix):
520535

521536
def _print_builder_repos(out, ct):
522537
try:
523-
for name in DRIVER_BY_NAME:
524-
path = f"/root/{name}-git-main"
538+
seen = set()
539+
for name, drv_cls in DRIVER_BY_NAME.items():
540+
repo = drv_cls.REPO_NAME
541+
if repo in seen:
542+
continue
543+
seen.add(repo)
544+
path = f"/root/{repo}-git-main"
525545
status = ct.get_repo_status(path)
526546
if status:
527-
out.print(f"{name}: {status}")
547+
out.print(f"{repo}: {status}")
528548
except Exception:
529549
out.print("repos: (unavailable)")
530550

@@ -605,7 +625,11 @@ def _print_dns_forwarding_status(out, dns_ip, *, host=False):
605625
("destroy", destroy_cmd, destroy_cmd_options),
606626
]
607627

608-
DRIVER_BY_NAME = {"cmdeploy": CmdeployDriver, "madmail": MadmailDriver}
628+
DRIVER_BY_NAME = {
629+
"cmdeploy": CmdeployDriver,
630+
"docker": DockerDriver,
631+
"madmail": MadmailDriver,
632+
}
609633

610634

611635
def _add_subcommand(subparsers, name, func, addopts, shared):

0 commit comments

Comments
 (0)