compose.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from ..core.module import Module
  2. from ..core.variables import VariableGroup, Variable, VariableManager
  3. from ..core.registry import register_module
  4. @register_module(
  5. name="compose",
  6. description="Manage Docker Compose configurations and services",
  7. files=["docker-compose.yml", "compose.yml", "docker-compose.yaml", "compose.yaml"]
  8. )
  9. class ComposeModule(Module):
  10. """Module for managing Compose configurations and services."""
  11. def __init__(self):
  12. # name, description, and files are automatically injected by the decorator!
  13. vars = self._init_vars()
  14. super().__init__(name=self.name, description=self.description, files=self.files, vars=vars)
  15. def _init_vars(self):
  16. """Initialize default variables for the compose module."""
  17. # Define variable sets configuration as a dictionary
  18. variable_sets_config = {
  19. "general": {
  20. "description": "General variables for compose services",
  21. "vars": {
  22. "service_name": {"description": "Name of the service", "value": None},
  23. "container_name": {"description": "Name of the container", "value": None},
  24. "docker_image": {"description": "Docker image to use", "value": "nginx:latest"},
  25. "restart_policy": {"description": "Restart policy", "value": "unless-stopped"}
  26. }
  27. },
  28. "swarm": {
  29. "description": "Variables for Docker Swarm deployment",
  30. "vars": {
  31. "swarm": {"description": "Enable Docker Swarm mode", "value": False, "var_type": "boolean"},
  32. "swarm_replicas": {"description": "Number of replicas in Swarm", "value": 1, "var_type": "integer"},
  33. "replica_count": {"description": "Number of replicas in Swarm", "value": 1, "var_type": "integer"}
  34. }
  35. },
  36. "networking": {
  37. "description": "Network and port configuration",
  38. "vars": {
  39. "service_port": {"description": "Service port mapping", "value": {"http": 8080, "https": 8443}, "var_type": "dict"},
  40. "docker_network": {"description": "Docker network name", "value": "bridge"}
  41. }
  42. },
  43. "traefik": {
  44. "description": "Variables for Traefik labels",
  45. "vars": {
  46. "traefik": {"description": "Enable Traefik labels", "value": False, "var_type": "boolean"},
  47. "traefik_host": {"description": "Traefik host rule", "value": "example.com"},
  48. "traefik_tls": {"description": "Enable TLS for Traefik", "value": True, "var_type": "boolean"},
  49. "traefik_certresolver": {"description": "Traefik certificate resolver", "value": "letsencrypt"},
  50. "traefik_http_port": {"description": "HTTP port for Traefik", "value": 80, "var_type": "integer"},
  51. "traefik_https_port": {"description": "HTTPS port for Traefik", "value": 443, "var_type": "integer"},
  52. "traefik_entrypoints": {"description": "Entry points for Traefik", "value": ["http", "https"], "var_type": "list"}
  53. }
  54. }
  55. }
  56. # Convert dictionary configuration to VariableGroup objects using from_dict
  57. return [VariableGroup.from_dict(name, config) for name, config in variable_sets_config.items()]
  58. def register(self, app):
  59. return super().register(app)