compose.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from ..core.module import Module
  2. from ..core.registry import registry
  3. class ComposeModule(Module):
  4. """Docker Compose module.
  5. Flat variable names only. Simple, explicit toggles (e.g., traefik_enabled) instead of dotted sections.
  6. """
  7. name = "compose"
  8. description = "Manage Docker Compose configurations"
  9. # Per rule: prefer compose.yaml first, legacy names kept as fallback
  10. files = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"]
  11. # Common Compose variables used across templates. Only variables actually used
  12. # in a given template are kept during merge.
  13. variables_spec = {
  14. # General
  15. "service_name": {"description": "Service name", "type": "str"},
  16. "container_name": {"description": "Container name", "type": "str"},
  17. "container_timezone": {"description": "Container timezone (e.g., Europe/Berlin)", "type": "str"},
  18. "container_loglevel": {
  19. "description": "Container log level",
  20. "type": "enum",
  21. "options": ["debug", "info", "warn", "error"],
  22. "default": "info",
  23. },
  24. "restart_policy": {
  25. "description": "Container restart policy",
  26. "type": "enum",
  27. "options": ["unless-stopped", "always", "on-failure", "no"],
  28. "default": "unless-stopped",
  29. },
  30. # Networking
  31. "network_enabled": {"description": "Enable custom network block", "type": "bool", "default": False},
  32. "network_name": {"description": "Docker network name", "type": "str", "default": "bridge"},
  33. "network_external": {"description": "Use existing Docker network", "type": "bool", "default": True},
  34. # Ports
  35. "ports_enabled": {"description": "Expose ports via 'ports' mapping", "type": "bool", "default": False},
  36. "service_port_http": {"description": "HTTP service port (host)", "type": "int", "default": 8080},
  37. "service_port_https": {"description": "HTTPS service port (host)", "type": "int", "default": 8443},
  38. # Traefik
  39. "traefik_enabled": {"description": "Enable Traefik reverse proxy integration", "type": "bool", "default": False},
  40. "traefik_host": {"description": "Domain name for your service", "type": "hostname"},
  41. "traefik_entrypoint": {"description": "HTTP entrypoint (non-TLS)", "type": "str", "default": "web"},
  42. "traefik_tls_enabled": {"description": "Enable HTTPS/TLS", "type": "bool", "default": True},
  43. "traefik_tls_entrypoint": {"description": "TLS entrypoint", "type": "str", "default": "websecure"},
  44. "traefik_tls_certresolver": {"description": "Traefik certificate resolver name", "type": "str"},
  45. # Docker Swarm
  46. "swarm_enabled": {"description": "Enable Docker Swarm mode", "type": "bool", "default": False},
  47. "swarm_replicas": {"description": "Number of replicas in Swarm", "type": "int", "default": 1},
  48. # Nginx example
  49. "nginx_dashboard_enabled": {"description": "Enable Nginx dashboard", "type": "bool", "default": False},
  50. "nginx_dashboard_port": {"description": "Nginx dashboard port (host)", "type": "int", "default": 8081},
  51. # PostgreSQL integration
  52. "postgres_enabled": {"description": "Enable PostgreSQL integration", "type": "bool", "default": False},
  53. "postgres_host": {"description": "PostgreSQL host", "type": "str", "default": "postgres"},
  54. "postgres_port": {"description": "PostgreSQL port", "type": "int", "default": 5432},
  55. "postgres_database": {"description": "PostgreSQL database name", "type": "str"},
  56. "postgres_user": {"description": "PostgreSQL user", "type": "str"},
  57. "postgres_password": {"description": "PostgreSQL password", "type": "str"},
  58. }
  59. # Register the module
  60. registry.register(ComposeModule)