upgrade_strategy 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. 'frontendImage': {
  12. 'RE_STABLE_VERSION': RE_STABLE_VERSION,
  13. },
  14. 'nginxImage': {
  15. 'RE_STABLE_VERSION': RE_STABLE_VERSION,
  16. },
  17. }
  18. def newer_mapping(image_tags):
  19. output = {
  20. "tags": {},
  21. "app_version": ""
  22. }
  23. for key in image_tags.keys():
  24. RE_STABLE_VERSION = ENUMS[key].get('RE_STABLE_VERSION', None) if key in ENUMS else None
  25. if (RE_STABLE_VERSION is None):
  26. continue
  27. tags = {t: t for t in image_tags[key] if RE_STABLE_VERSION.fullmatch(t)}
  28. version = semantic_versioning(list(tags))
  29. if not version:
  30. continue
  31. if key == 'image':
  32. output['app_version'] = version
  33. output['tags'][key] = tags[version]
  34. return output
  35. if __name__ == '__main__':
  36. try:
  37. versions_json = json.loads(sys.stdin.read())
  38. except ValueError:
  39. raise ValueError('Invalid json specified')
  40. print(json.dumps(newer_mapping(versions_json)))