| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- from ..core.module import Module
- from ..core.variables import VariableGroup, Variable, VariableManager
- from ..core.registry import register_module
- @register_module(
- name="compose",
- description="Manage Docker Compose configurations and services",
- files=["docker-compose.yml", "compose.yml", "docker-compose.yaml", "compose.yaml"]
- )
- class ComposeModule(Module):
- """Module for managing Compose configurations and services."""
- def __init__(self):
- # name, description, and files are automatically injected by the decorator!
- vars = self._init_vars()
- super().__init__(name=self.name, description=self.description, files=self.files, vars=vars)
- def _init_vars(self):
- """Initialize default variables for the compose module."""
-
- # Define variable sets configuration as a dictionary
- variable_sets_config = {
- "general": {
- "description": "General variables for compose services",
- "vars": {
- "service_name": {"description": "Name of the service", "value": None},
- "container_name": {"description": "Name of the container", "value": None},
- "docker_image": {"description": "Docker image to use", "value": "nginx:latest"},
- "restart_policy": {"description": "Restart policy", "value": "unless-stopped"}
- }
- },
- "swarm": {
- "description": "Variables for Docker Swarm deployment",
- "vars": {
- "swarm": {"description": "Enable Docker Swarm mode", "value": False, "var_type": "boolean"},
- "swarm_replicas": {"description": "Number of replicas in Swarm", "value": 1, "var_type": "integer"},
- "replica_count": {"description": "Number of replicas in Swarm", "value": 1, "var_type": "integer"}
- }
- },
- "networking": {
- "description": "Network and port configuration",
- "vars": {
- "service_port": {"description": "Service port mapping", "value": {"http": 8080, "https": 8443}, "var_type": "dict"},
- "docker_network": {"description": "Docker network name", "value": "bridge"}
- }
- },
- "traefik": {
- "description": "Variables for Traefik labels",
- "vars": {
- "traefik": {"description": "Enable Traefik labels", "value": False, "var_type": "boolean"},
- "traefik_host": {"description": "Traefik host rule", "value": "example.com"},
- "traefik_tls": {"description": "Enable TLS for Traefik", "value": True, "var_type": "boolean"},
- "traefik_certresolver": {"description": "Traefik certificate resolver", "value": "letsencrypt"},
- "traefik_http_port": {"description": "HTTP port for Traefik", "value": 80, "var_type": "integer"},
- "traefik_https_port": {"description": "HTTPS port for Traefik", "value": 443, "var_type": "integer"},
- "traefik_entrypoints": {"description": "Entry points for Traefik", "value": ["http", "https"], "var_type": "list"}
- }
- }
- }
- # Convert dictionary configuration to VariableGroup objects using from_dict
- return [VariableGroup.from_dict(name, config) for name, config in variable_sets_config.items()]
- def register(self, app):
- return super().register(app)
|