upgrade_strategy 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python3
  2. import json
  3. import re
  4. import sys
  5. from catalog_update.upgrade_strategy import semantic_versioning
  6. RE_STABLE_VERSION_BASE = r'v\d+\.\d+\.\d+'
  7. ENUMS = {
  8. 'image': {
  9. 'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}'),
  10. },
  11. 'pluginsImage': {
  12. 'RE_STABLE_VERSION': re.compile(rf'{RE_STABLE_VERSION_BASE}-plugins'),
  13. },
  14. }
  15. def newer_mapping(image_tags):
  16. output = {
  17. "tags": {},
  18. "app_version": ""
  19. }
  20. for key in image_tags.keys():
  21. RE_STABLE_VERSION = ENUMS[key].get('RE_STABLE_VERSION', None) if key in ENUMS else None
  22. tags = {t.strip('v').strip('-plugins'): t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
  23. version = semantic_versioning(list(tags))
  24. if not version:
  25. continue
  26. if key == 'image':
  27. output['app_version'] = version
  28. output['tags'][key] = tags[version]
  29. return output
  30. if __name__ == '__main__':
  31. try:
  32. versions_json = json.loads(sys.stdin.read())
  33. except ValueError:
  34. raise ValueError('Invalid json specified')
  35. print(json.dumps(newer_mapping(versions_json)))