edd-tool 0.2.1__tar.gz → 0.2.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edd-tool
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: EDD deployment and plugin management tool
5
5
  Author-email: Ewan Barr <ebarr@mpifr-bonn.mpg.de>
6
6
  License: Copyright 2025 Ewan Barr
@@ -18,7 +18,8 @@ Project-URL: Bug Tracker, https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer/is
18
18
  Requires-Python: >=3.11
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
- Requires-Dist: ansible-core<2.20,>=2.14
21
+ Requires-Dist: ansible>=12.0.0
22
+ Requires-Dist: requests
22
23
  Dynamic: license-file
23
24
 
24
25
  # EDD Tool
@@ -55,8 +56,8 @@ edd-tool --help
55
56
  $ edd-tool deploy --h
56
57
  usage: edd-tool deploy [-h] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--site-repo SITE_REPO] [--version VERSION]
57
58
  [--deploy-dir DEPLOY_DIR] [--inventory INVENTORY] [--vault-pass-file VAULT_PASS_FILE]
58
- [--site-config SITE_CONFIG] [--plugin-install-method {galaxy,git-submodule}] [--no-pullremote]
59
- [--force] [--dry-run]
59
+ [--site-config SITE_CONFIG] [--plugin-install-method {galaxy,git-submodule}] [--no-pullremote] [--force]
60
+ [--dry-run] [--ansible-args ANSIBLE_ARGS]
60
61
  [config_profile]
61
62
 
62
63
  positional arguments:
@@ -81,6 +82,8 @@ options:
81
82
  --no-pullremote Skip pullremote tag
82
83
  --force Force overwrite of deployment directory
83
84
  --dry-run Dry run the deployment
85
+ --ansible-args ANSIBLE_ARGS
86
+ Quoted string of extra ansible-playbook args
84
87
  ```
85
88
 
86
89
  ## Deployment profiles
@@ -32,8 +32,8 @@ edd-tool --help
32
32
  $ edd-tool deploy --h
33
33
  usage: edd-tool deploy [-h] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--site-repo SITE_REPO] [--version VERSION]
34
34
  [--deploy-dir DEPLOY_DIR] [--inventory INVENTORY] [--vault-pass-file VAULT_PASS_FILE]
35
- [--site-config SITE_CONFIG] [--plugin-install-method {galaxy,git-submodule}] [--no-pullremote]
36
- [--force] [--dry-run]
35
+ [--site-config SITE_CONFIG] [--plugin-install-method {galaxy,git-submodule}] [--no-pullremote] [--force]
36
+ [--dry-run] [--ansible-args ANSIBLE_ARGS]
37
37
  [config_profile]
38
38
 
39
39
  positional arguments:
@@ -58,6 +58,8 @@ options:
58
58
  --no-pullremote Skip pullremote tag
59
59
  --force Force overwrite of deployment directory
60
60
  --dry-run Dry run the deployment
61
+ --ansible-args ANSIBLE_ARGS
62
+ Quoted string of extra ansible-playbook args
61
63
  ```
62
64
 
63
65
  ## Deployment profiles
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "edd-tool"
7
- version = "0.2.1"
7
+ version = "0.2.3"
8
8
  description = "EDD deployment and plugin management tool"
9
9
  dynamic = ["readme"]
10
10
  license = { file = "LICENSE" }
@@ -13,7 +13,8 @@ authors = [
13
13
  ]
14
14
  requires-python = ">=3.11"
15
15
  dependencies = [
16
- "ansible-core>=2.14,<2.20",
16
+ "ansible>=12.0.0",
17
+ "requests"
17
18
  ]
18
19
 
19
20
  [project.scripts]
@@ -36,4 +37,4 @@ where = ["src"]
36
37
  Homepage = "https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer"
37
38
  Documentation = "https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer"
38
39
  Repository = "https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer.git"
39
- "Bug Tracker" = "https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer/issues"
40
+ "Bug Tracker" = "https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer/issues"
@@ -7,6 +7,7 @@ import json
7
7
  import logging
8
8
  import os
9
9
  import pprint
10
+ import shlex
10
11
  import warnings
11
12
  import io
12
13
  from contextlib import contextmanager, redirect_stdout, redirect_stderr
@@ -33,6 +34,49 @@ logger = logging.getLogger("edd-installer")
33
34
  SESSION = requests.Session()
34
35
  SESSION.verify = False
35
36
 
37
+ class VaultString(str):
38
+ """A string subclass to mark values coming from !vault tags."""
39
+ pass
40
+
41
+
42
+ class Loader(yaml.SafeLoader):
43
+ """
44
+ Custom YAML Loader that preserves !vault blocks from Ansible YAML files.
45
+ Instead of trying to decrypt them, it stores them as VaultString objects.
46
+ """
47
+ pass
48
+
49
+
50
+ class Dumper(yaml.SafeDumper):
51
+ """
52
+ Custom YAML Dumper that knows how to re-emit VaultString values
53
+ using the !vault tag exactly as they appeared.
54
+ """
55
+ pass
56
+
57
+
58
+ def vault_constructor(loader, node):
59
+ """
60
+ Called when the YAML parser encounters a !vault tag.
61
+ Simply store the raw scalar content as a VaultString.
62
+ """
63
+ value = loader.construct_scalar(node)
64
+ return VaultString(value)
65
+
66
+
67
+ def vault_representer(dumper, data):
68
+ """
69
+ Called when dumping a VaultString.
70
+ Emits the data as a literal block scalar with the !vault tag.
71
+ """
72
+ # Use style='|' to preserve multi-line formatting
73
+ return dumper.represent_scalar('!vault', data, style='|')
74
+
75
+
76
+ # Register the constructors and representers
77
+ Loader.add_constructor('!vault', vault_constructor)
78
+ Dumper.add_representer(VaultString, vault_representer)
79
+
36
80
  def ensure_rc_file():
37
81
  """Ensure that ~/.edd-tool.rc exists. Create from template if missing."""
38
82
  rc_file = Path.home() / ".edd-tool.rc"
@@ -158,7 +202,7 @@ def print_report(report):
158
202
  if removed:
159
203
  logger.info(f"[-] {repo}:{short_digest} --> removed tags: {', '.join(removed)}")
160
204
 
161
- def run_cmd(cmd, cwd=None, check=True, env=None):
205
+ def run_cmd(cmd, cwd=None, check=True, env=None, log_func=None):
162
206
  """
163
207
  Run a subprocess command and stream its output into the logger.
164
208
 
@@ -171,6 +215,9 @@ def run_cmd(cmd, cwd=None, check=True, env=None):
171
215
  Returns:
172
216
  int: Return code of the command
173
217
  """
218
+ if not log_func:
219
+ log_func = logger.info
220
+
174
221
  logger.debug(f"Running command: {' '.join(cmd)}")
175
222
  process = subprocess.Popen(
176
223
  cmd,
@@ -184,7 +231,7 @@ def run_cmd(cmd, cwd=None, check=True, env=None):
184
231
 
185
232
  # Stream output live into logger
186
233
  for line in process.stdout:
187
- logger.info(line.rstrip())
234
+ log_func(line.rstrip())
188
235
 
189
236
  process.wait()
190
237
 
@@ -248,12 +295,13 @@ def clone_or_copy_site_repo(site_repo_path, deploy_dir, branch=None):
248
295
  deploy_dir (str|Path): Deployment directory
249
296
  branch (str, optional): Branch or tag to checkout
250
297
  """
251
- logger.info(f"Cloning repository from {site_repo_path} into {deploy_dir}")
298
+ logger.debug(f"Cloning repository from {site_repo_path} into {deploy_dir}")
252
299
  if branch:
253
300
  run_cmd(["git", "clone", "--single-branch", "--depth", "1", "--branch",
254
- branch, site_repo_path, str(deploy_dir)])
301
+ branch, site_repo_path, str(deploy_dir)], log_func=logger.debug)
255
302
  else:
256
- run_cmd(["git", "clone", "--single-branch", "--depth", "1", site_repo_path, str(deploy_dir)])
303
+ run_cmd(["git", "clone", "--single-branch", "--depth", "1", site_repo_path, str(deploy_dir)],
304
+ log_func=logger.debug)
257
305
 
258
306
 
259
307
  def parse_inventory(inventory_source, vault_pass_file=None):
@@ -312,7 +360,7 @@ def display_vars(vars_dict):
312
360
  Args:
313
361
  vars_dict (dict): Dictionary of variables
314
362
  """
315
- logger.info(pprint.pformat(vars_dict, indent=2))
363
+ logger.debug(pprint.pformat(vars_dict, indent=2))
316
364
 
317
365
 
318
366
  def install_plugins(plugins, method="galaxy"):
@@ -333,17 +381,17 @@ def install_plugins(plugins, method="galaxy"):
333
381
  for p in plugins:
334
382
  req_file.write(f" - type: git\n source: {p['source']}\n version: \"{p['version']}\"\n")
335
383
  req_file.close()
336
- run_cmd(["ansible-galaxy", "collection", "install", "-r", req_file.name, "-p", "./ansible_collections/"])
384
+ run_cmd(["ansible-galaxy", "collection", "install", "-r", req_file.name, "-p", "./ansible_collections/"], log_func=logger.debug)
337
385
  elif method == "git-submodule":
338
- run_cmd(["git", "submodule", "update", "--init", "--recursive"])
339
- run_cmd(["git", "submodule", "update", "--remote", "--recursive"])
386
+ run_cmd(["git", "submodule", "update", "--init", "--recursive"], log_func=logger.debug)
387
+ run_cmd(["git", "submodule", "update", "--remote", "--recursive"], log_func=logger.debug)
340
388
  else:
341
389
  raise NotImplementedError(f"Plugin install method '{method}' is unsupported")
342
390
 
343
391
 
344
- def run_playbook(inventory, vault_args, site_config, tags=None, dry_run=False):
392
+ def run_playbook(inventory, vault_args, site_config, tags=None, dry_run=False, extra_args_str=None):
345
393
  """
346
- Run an Ansible playbook.
394
+ Run an Ansible playbook with optional extra args as a quoted string.
347
395
 
348
396
  Args:
349
397
  inventory (str): Inventory path
@@ -351,19 +399,30 @@ def run_playbook(inventory, vault_args, site_config, tags=None, dry_run=False):
351
399
  site_config (str): Playbook YAML file
352
400
  tags (str, optional): Tags to limit execution
353
401
  dry_run (bool): If True, log the command instead of running
402
+ extra_args_str (str): String of extra args to pass to ansible-playbook (quoted)
354
403
  """
355
404
  collections = (Path().cwd() / "ansible_collections").absolute()
356
405
  env = os.environ.copy()
357
406
  env['ANSIBLE_COLLECTIONS_PATH'] = str(collections)
358
-
359
- cmd = ["ansible-playbook", "-i", inventory] + vault_args + [site_config]
407
+
408
+ # Safely tokenize the extra args string
409
+ extra_args = shlex.split(extra_args_str) if extra_args_str else []
410
+
411
+ cmd = ["ansible-playbook", "-i", inventory] + vault_args
412
+ if extra_args_str:
413
+ cmd.extend(shlex.split(extra_args_str))
360
414
  if tags:
361
415
  cmd.extend(["--tags", tags])
416
+ cmd.append(site_config)
362
417
 
363
418
  if dry_run:
364
419
  logger.info("Would run: %s", " ".join(cmd))
365
420
  else:
366
- run_cmd(cmd, env=env)
421
+ # avoid the logger by using a direct run call
422
+ subprocess.run(cmd, env=env, check=True)
423
+
424
+
425
+
367
426
 
368
427
  def cmd_install(args):
369
428
  """
@@ -411,22 +470,125 @@ def cmd_install(args):
411
470
 
412
471
  if not args.no_pullremote:
413
472
  logger.info("Pulling docker images")
414
- registry = f"https://{vars_dict["docker_registry"]}:{vars_dict["docker_registry_port"]}"
473
+ registry = f"https://{vars_dict['docker_registry']}:{vars_dict['docker_registry_port']}"
415
474
  logger.debug("Taking registry snapshot before pullremote...")
416
475
  before_state = snapshot_registry(registry)
417
476
  logger.debug(before_state)
418
477
  run_playbook(args.inventory, vault_args, args.site_config,
419
- tags="pullremote", dry_run=args.dry_run)
478
+ tags="pullremote", dry_run=args.dry_run,
479
+ extra_args_str=args.ansible_args)
420
480
  after_state = snapshot_registry(registry)
421
481
  logger.debug("Taking registry snapshow after pullremote")
422
482
  logger.debug(after_state)
423
483
  report = compare_snapshots(before_state, after_state)
424
484
  print_report(report)
425
485
  logger.info("Running deployment")
426
- run_playbook(args.inventory, vault_args, args.site_config, dry_run=args.dry_run)
486
+ run_playbook(args.inventory, vault_args, args.site_config,
487
+ dry_run=args.dry_run, extra_args_str=args.ansible_args)
427
488
  logger.info("Deployment finished")
428
489
 
490
+ def replace_plugins(fname, replacement):
491
+ replacement_lines = replacement.splitlines()
492
+ with open(fname, "r") as f:
493
+ lines = f.readlines()
494
+ output_lines = []
495
+ in_plugin_block = False
496
+ for ii, line in enumerate(lines):
497
+ if line.startswith("EDD_PLUGIN"):
498
+ in_plugin_block = True
499
+ continue
500
+ if in_plugin_block:
501
+ if line.startswith(" ") or line.startswith("-") or not line:
502
+ continue
503
+ else:
504
+ in_plugin_block = False
505
+ for replacement_line in replacement_lines:
506
+ output_lines.append(replacement_line)
507
+ else:
508
+ output_lines.append(line)
509
+ with open(fname, "w") as f:
510
+ for line in output_lines:
511
+ if not line.endswith("\n"):
512
+ line = line + "\n"
513
+ f.write(line)
514
+
515
+ def get_tags_and_branches(url):
516
+ out = subprocess.check_output(["git", "ls-remote", "--tags", "--heads", "--refs", url])
517
+ lines = out.decode().splitlines()
518
+ tags, branches = [], []
519
+ for line in lines:
520
+ if "/tags/" in line:
521
+ tags.append(line.split("/tags/")[-1].strip())
522
+ elif "/heads/" in line:
523
+ branches.append(line.split("/heads/")[-1].strip())
524
+ return tags, branches
525
+
526
+ def update_plugin_list(all_yaml_path, version_map):
527
+ with open(all_yaml_path, "r") as f:
528
+ raw_yaml = yaml.load(f.read(), Loader=Loader)
529
+ plugin_yaml = raw_yaml["EDD_PLUGINS"]
530
+ for p in plugin_yaml:
531
+ p['version'] = str(version_map[p['name']])
532
+ plugin_txt = yaml.dump({"EDD_PLUGINS": plugin_yaml}, Dumper=Dumper, indent=2)
533
+ logger.info(f"Updated EDD plugin yaml:\n{plugin_txt}")
534
+ replace_plugins(all_yaml_path, plugin_txt)
535
+
536
+ def cmd_update_plugins(args):
537
+ """
538
+ Pluging update command handler.
429
539
 
540
+ Args:
541
+ args (Namespace): Parsed command-line arguments
542
+ """
543
+ deploy_dir = args.deploy_dir or default_deployment_dir(args)
544
+ logger.info("Creating deployment directory: %s", deploy_dir)
545
+ deploy_dir = create_deployment_dir(deploy_dir, force=args.force)
546
+
547
+ # Resolve vault password file
548
+ vault_pass_file = None
549
+ if args.vault_pass_file:
550
+ vault_pass_file = str(Path(args.vault_pass_file).expanduser().absolute())
551
+ elif os.getenv("ANSIBLE_VAULT_PASSWORD_FILE"):
552
+ vault_pass_file = os.getenv("ANSIBLE_VAULT_PASSWORD_FILE")
553
+ logger.debug(f"Using vault password file from environment: {vault_pass_file}")
554
+
555
+ with working_directory(deploy_dir):
556
+ logger.info("Cloning site repository: %s (version: %s)", args.site_repo, args.version)
557
+ clone_or_copy_site_repo(args.site_repo, "./", branch=args.version)
558
+ logger.info("Parsing ansible inventory")
559
+ with suppress_ansible_warnings():
560
+ vars_dict, plugins = parse_inventory(args.inventory, vault_pass_file)
561
+ version_map = {}
562
+ for p in plugins:
563
+ logger.debug(f"Pulling tags and branches for {p['name']}")
564
+ tags, branches = get_tags_and_branches(p['source'])
565
+ if p['version'] in branches:
566
+ logger.warning(f"{p['name']} is set to the {p['version']} branch and will not be updated.")
567
+ version_map[p['name']] = p['version']
568
+ elif not tags:
569
+ logger.warning(f"No tags available for {p['name']}, version will stay as {p['version']}")
570
+ version_map[p['name']] = p['version']
571
+ else:
572
+ new_tag = sorted(tags)[-1]
573
+ if new_tag == p['version']:
574
+ logger.info(f"{p['name']} already on latest tag ({p['version']})")
575
+ version_map[p['name']] = p['version']
576
+ else:
577
+ logger.info(f"{p['name']} updated {p['version']} --> {new_tag}")
578
+ version_map[p['name']] = new_tag
579
+ # here we need to load the orginal file without templating
580
+ all_yaml_path = os.path.join(args.inventory, "group_vars", "all.yml")
581
+ update_plugin_list(all_yaml_path, version_map)
582
+ if args.commit:
583
+ run_cmd(["git", "add", all_yaml_path], log_func=logger.info)
584
+ run_cmd(["git", "commit", "-m", "[edd-tool] bump plugin versions"], log_func=logger.info)
585
+ logger.warning("Committing currently disabled until branch policy determined")
586
+ #run_cmd(["git", "push"], log_func=logger.info)
587
+
588
+ # TODO: Clean this up and break into functions
589
+ # TODO: Add logic to only update tags and avoid updating branches
590
+
591
+
430
592
  def load_rc_config(profile):
431
593
  """
432
594
  Load configuration profile from ~/.edd-tool.rc.
@@ -485,6 +647,9 @@ def main():
485
647
  parser = argparse.ArgumentParser(prog="edd-tool", description="EDD Installer Tool")
486
648
  subparsers = parser.add_subparsers(dest="command", required=True)
487
649
 
650
+ ##########
651
+ # Deploy #
652
+ ##########
488
653
  sp_install = subparsers.add_parser(
489
654
  "deploy",
490
655
  help="Install and deploy EDD backend instance",
@@ -508,12 +673,42 @@ def main():
508
673
  sp_install.add_argument("--no-pullremote", action="store_true", help="Skip pullremote tag")
509
674
  sp_install.add_argument("--force", action="store_true", help="Force overwrite of deployment directory")
510
675
  sp_install.add_argument("--dry-run", action="store_true", help="Dry run the deployment")
676
+ sp_install.add_argument(
677
+ "--ansible-args",
678
+ help="Quoted string of extra ansible-playbook args"
679
+ )
511
680
  sp_install.set_defaults(func=cmd_install)
512
681
 
682
+ ##########
683
+ # Plugin #
684
+ ##########
685
+ sp_update_plugins = subparsers.add_parser(
686
+ "update-plugins",
687
+ help="Update EDD plugins",
688
+ parents=[parent_parser]
689
+ )
690
+ sp_update_plugins.add_argument(
691
+ "config_profile",
692
+ nargs="?",
693
+ help="Optional profile name from ~/.edd-tool.rc (e.g. 'production', 'devel')"
694
+ )
695
+ sp_update_plugins.add_argument("--site-repo", help="Git URL of the EDD site repository")
696
+ sp_update_plugins.add_argument("--version", default=None, help="Branch or tag for the site repository")
697
+ sp_update_plugins.add_argument("--deploy-dir", default=None, help="Deployment directory")
698
+ sp_update_plugins.add_argument("--inventory", help="Ansible inventory path (file, dir, or script)")
699
+ sp_update_plugins.add_argument(
700
+ "--vault-pass-file",
701
+ help="Path to vault password file (defaults to $ANSIBLE_VAULT_PASSWORD_FILE if set)"
702
+ )
703
+ sp_update_plugins.add_argument("--site-config", help="Path to site configuration YAML")
704
+ sp_update_plugins.add_argument("--force", action="store_true", help="Force overwrite of deployment directory")
705
+ sp_update_plugins.add_argument("--commit", action="store_true", help="Commit plugin changes back to the repository")
706
+ sp_update_plugins.set_defaults(func=cmd_update_plugins)
707
+
513
708
  args = parser.parse_args()
514
709
 
515
710
  # Apply profile defaults if specified
516
- if args.command == "deploy" and args.config_profile:
711
+ if args.config_profile:
517
712
  try:
518
713
  profile_data = load_rc_config(args.config_profile)
519
714
  merge_args_with_profile(args, profile_data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edd-tool
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: EDD deployment and plugin management tool
5
5
  Author-email: Ewan Barr <ebarr@mpifr-bonn.mpg.de>
6
6
  License: Copyright 2025 Ewan Barr
@@ -18,7 +18,8 @@ Project-URL: Bug Tracker, https://gitlab.mpcdf.mpg.de/mpifr-bdg/edd_installer/is
18
18
  Requires-Python: >=3.11
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
- Requires-Dist: ansible-core<2.20,>=2.14
21
+ Requires-Dist: ansible>=12.0.0
22
+ Requires-Dist: requests
22
23
  Dynamic: license-file
23
24
 
24
25
  # EDD Tool
@@ -55,8 +56,8 @@ edd-tool --help
55
56
  $ edd-tool deploy --h
56
57
  usage: edd-tool deploy [-h] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--site-repo SITE_REPO] [--version VERSION]
57
58
  [--deploy-dir DEPLOY_DIR] [--inventory INVENTORY] [--vault-pass-file VAULT_PASS_FILE]
58
- [--site-config SITE_CONFIG] [--plugin-install-method {galaxy,git-submodule}] [--no-pullremote]
59
- [--force] [--dry-run]
59
+ [--site-config SITE_CONFIG] [--plugin-install-method {galaxy,git-submodule}] [--no-pullremote] [--force]
60
+ [--dry-run] [--ansible-args ANSIBLE_ARGS]
60
61
  [config_profile]
61
62
 
62
63
  positional arguments:
@@ -81,6 +82,8 @@ options:
81
82
  --no-pullremote Skip pullremote tag
82
83
  --force Force overwrite of deployment directory
83
84
  --dry-run Dry run the deployment
85
+ --ansible-args ANSIBLE_ARGS
86
+ Quoted string of extra ansible-playbook args
84
87
  ```
85
88
 
86
89
  ## Deployment profiles
@@ -0,0 +1,2 @@
1
+ ansible>=12.0.0
2
+ requests
@@ -1 +0,0 @@
1
- ansible-core<2.20,>=2.14
File without changes
File without changes