upgrade_strategy_disable 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python3
  2. import json
  3. import sys
  4. import re
  5. from catalog_update.upgrade_strategy import semantic_versioning
  6. from catalog_validation.exceptions import ValidationException
  7. version_regx = r'[\w]*-v[0-9]+.[0-9]+.[0-9]+-go[0-9]+.[0-9].+[0-9]+'
  8. version_with_arch = version_regx + r'[-\w]*'
  9. sub_go_version = r'-go[0-9]+.[0-9].+[0-9]+[-\w]*'
  10. version_hash = r'[\w]*-v'
  11. app_version_regx = 'v[0-9]+.[0-9]+.[0-9]'
  12. def newer_mapping(image_tags):
  13. key = list(image_tags.keys())[0]
  14. tags = {}
  15. for tag in image_tags[key]:
  16. match = re.fullmatch(version_with_arch, tag)
  17. if match:
  18. removed_go_arch_version = re.sub(sub_go_version, '', tag)
  19. app_version = re.sub(version_hash, '', removed_go_arch_version)
  20. if tags.get(app_version):
  21. tags.get(app_version).append(tag)
  22. else:
  23. tags[app_version] = [tag]
  24. version = semantic_versioning(list(tags))
  25. if not version:
  26. return {}
  27. version_tag = tags[version][0]
  28. for tag in tags.get(version):
  29. archi = re.sub(version_regx, '', tag)
  30. if archi == 'amd64' or archi == '':
  31. version_tag = tag
  32. break
  33. app_version = re.findall(app_version_regx, version_tag).pop()
  34. return {
  35. 'tags': {key: f'{version_tag}'},
  36. 'app_version': f'{app_version}',
  37. }
  38. if __name__ == '__main__':
  39. try:
  40. versions_json = json.loads(sys.stdin.read())
  41. except ValueError:
  42. raise ValidationException('Invalid JSON')
  43. print(json.dumps(newer_mapping(versions_json)))