compose.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. "replica_count": {"description": "Number of replicas in Swarm", "value": 1, "var_type": "integer"}
  32. }
  33. },
  34. "traefik": {
  35. "description": "Variables for Traefik labels",
  36. "vars": {
  37. "traefik_http_port": {"description": "HTTP port for Traefik", "value": 80, "var_type": "integer"},
  38. "traefik_https_port": {"description": "HTTPS port for Traefik", "value": 443, "var_type": "integer"},
  39. "traefik_entrypoints": {"description": "Entry points for Traefik", "value": ["http", "https"], "var_type": "list"}
  40. }
  41. }
  42. }
  43. # Convert dictionary configuration to VariableGroup objects using from_dict
  44. return [VariableGroup.from_dict(name, config) for name, config in variable_sets_config.items()]
  45. def register(self, app):
  46. return super().register(app)