upgrade_strategy 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = re.compile(r'\d+\.\d+\.\d+')
  7. ENUMS = {
  8. 'image': {
  9. 'RE_STABLE_VERSION': RE_STABLE_VERSION,
  10. },
  11. 'apiImage': {
  12. 'RE_STABLE_VERSION': RE_STABLE_VERSION,
  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. if (RE_STABLE_VERSION is None):
  23. continue
  24. tags = {t: t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
  25. version = semantic_versioning(list(tags))
  26. if not version:
  27. continue
  28. if key == 'image':
  29. output['app_version'] = version
  30. output['tags'][key] = tags[version]
  31. return output
  32. if __name__ == '__main__':
  33. try:
  34. versions_json = json.loads(sys.stdin.read())
  35. except ValueError:
  36. raise ValueError('Invalid json specified')
  37. print(json.dumps(newer_mapping(versions_json)))