edd-tool 0.2.2__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.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "edd-tool"
7
- version = "0.2.2"
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]
@@ -34,6 +34,49 @@ logger = logging.getLogger("edd-installer")
34
34
  SESSION = requests.Session()
35
35
  SESSION.verify = False
36
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
+
37
80
  def ensure_rc_file():
38
81
  """Ensure that ~/.edd-tool.rc exists. Create from template if missing."""
39
82
  rc_file = Path.home() / ".edd-tool.rc"
@@ -159,7 +202,7 @@ def print_report(report):
159
202
  if removed:
160
203
  logger.info(f"[-] {repo}:{short_digest} --> removed tags: {', '.join(removed)}")
161
204
 
162
- def run_cmd(cmd, cwd=None, check=True, env=None):
205
+ def run_cmd(cmd, cwd=None, check=True, env=None, log_func=None):
163
206
  """
164
207
  Run a subprocess command and stream its output into the logger.
165
208
 
@@ -172,6 +215,9 @@ def run_cmd(cmd, cwd=None, check=True, env=None):
172
215
  Returns:
173
216
  int: Return code of the command
174
217
  """
218
+ if not log_func:
219
+ log_func = logger.info
220
+
175
221
  logger.debug(f"Running command: {' '.join(cmd)}")
176
222
  process = subprocess.Popen(
177
223
  cmd,
@@ -185,7 +231,7 @@ def run_cmd(cmd, cwd=None, check=True, env=None):
185
231
 
186
232
  # Stream output live into logger
187
233
  for line in process.stdout:
188
- logger.info(line.rstrip())
234
+ log_func(line.rstrip())
189
235
 
190
236
  process.wait()
191
237
 
@@ -249,12 +295,13 @@ def clone_or_copy_site_repo(site_repo_path, deploy_dir, branch=None):
249
295
  deploy_dir (str|Path): Deployment directory
250
296
  branch (str, optional): Branch or tag to checkout
251
297
  """
252
- 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}")
253
299
  if branch:
254
300
  run_cmd(["git", "clone", "--single-branch", "--depth", "1", "--branch",
255
- branch, site_repo_path, str(deploy_dir)])
301
+ branch, site_repo_path, str(deploy_dir)], log_func=logger.debug)
256
302
  else:
257
- 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)
258
305
 
259
306
 
260
307
  def parse_inventory(inventory_source, vault_pass_file=None):
@@ -334,10 +381,10 @@ def install_plugins(plugins, method="galaxy"):
334
381
  for p in plugins:
335
382
  req_file.write(f" - type: git\n source: {p['source']}\n version: \"{p['version']}\"\n")
336
383
  req_file.close()
337
- 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)
338
385
  elif method == "git-submodule":
339
- run_cmd(["git", "submodule", "update", "--init", "--recursive"])
340
- 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)
341
388
  else:
342
389
  raise NotImplementedError(f"Plugin install method '{method}' is unsupported")
343
390
 
@@ -371,8 +418,10 @@ def run_playbook(inventory, vault_args, site_config, tags=None, dry_run=False, e
371
418
  if dry_run:
372
419
  logger.info("Would run: %s", " ".join(cmd))
373
420
  else:
374
- from subprocess import run
375
- run(cmd, env=env, check=True)
421
+ # avoid the logger by using a direct run call
422
+ subprocess.run(cmd, env=env, check=True)
423
+
424
+
376
425
 
377
426
 
378
427
  def cmd_install(args):
@@ -438,7 +487,108 @@ def cmd_install(args):
438
487
  dry_run=args.dry_run, extra_args_str=args.ansible_args)
439
488
  logger.info("Deployment finished")
440
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.
441
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
+
442
592
  def load_rc_config(profile):
443
593
  """
444
594
  Load configuration profile from ~/.edd-tool.rc.
@@ -497,6 +647,9 @@ def main():
497
647
  parser = argparse.ArgumentParser(prog="edd-tool", description="EDD Installer Tool")
498
648
  subparsers = parser.add_subparsers(dest="command", required=True)
499
649
 
650
+ ##########
651
+ # Deploy #
652
+ ##########
500
653
  sp_install = subparsers.add_parser(
501
654
  "deploy",
502
655
  help="Install and deploy EDD backend instance",
@@ -526,10 +679,36 @@ def main():
526
679
  )
527
680
  sp_install.set_defaults(func=cmd_install)
528
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
+
529
708
  args = parser.parse_args()
530
709
 
531
710
  # Apply profile defaults if specified
532
- if args.command == "deploy" and args.config_profile:
711
+ if args.config_profile:
533
712
  try:
534
713
  profile_data = load_rc_config(args.config_profile)
535
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.2
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
@@ -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
File without changes