add_dubbo_ports.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python3
  2. import yaml
  3. from pathlib import Path
  4. repo_root = Path("d:/coding-area/devops/deploy/microservice-helm")
  5. chart_base = repo_root / "charts"
  6. # Dubbo services mapping
  7. dubbo_services = {
  8. 'shop-recycle-account': 2030,
  9. 'shop-recycle-data-statistics': 2028,
  10. 'shop-recycle-dealdata-service': 2032,
  11. 'shop-recycle-dispatcher': 2033,
  12. 'shop-recycle-merchant': 2023,
  13. 'shop-recycle-msg': 2026,
  14. 'shop-recycle-order-center': 2022,
  15. 'shop-recycle-order-search': 2034,
  16. 'shop-recycle-payment': 2027,
  17. 'shop-recycle-pis': 2025,
  18. 'shop-recycle-platform': 2021,
  19. 'shop-recycle-store': 2024,
  20. 'shop-recycle-wechat': 2031,
  21. }
  22. print("为Dubbo服务添加dubbo_port配置...\n")
  23. for service_name, dubbo_port in dubbo_services.items():
  24. values_path = chart_base / service_name / "values.yaml"
  25. if not values_path.exists():
  26. print(f"WARNING: {service_name} values.yaml not found")
  27. continue
  28. try:
  29. with open(values_path, 'r', encoding='utf-8') as f:
  30. values = yaml.safe_load(f)
  31. except Exception as e:
  32. print(f"ERROR reading {service_name}: {e}")
  33. continue
  34. # Add dubbo_port to service section
  35. if 'service' not in values:
  36. values['service'] = {}
  37. values['service']['dubbo_port'] = dubbo_port
  38. # Write back
  39. try:
  40. with open(values_path, 'w', encoding='utf-8') as f:
  41. yaml.dump(values, f, default_flow_style=False, allow_unicode=True, sort_keys=False)
  42. print(f"✓ {service_name}: 添加dubbo_port: {dubbo_port}")
  43. except Exception as e:
  44. print(f"ERROR writing {service_name}: {e}")
  45. print("\n所有Dubbo服务配置完成!")