__init__.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """Docker Compose module."""
  2. import logging
  3. from typing import Annotated
  4. from typer import Argument, Option
  5. from ...core.module import Module
  6. from ...core.module.base_commands import validate_templates
  7. from ...core.registry import registry
  8. from .validate import run_docker_validation
  9. logger = logging.getLogger(__name__)
  10. class ComposeModule(Module):
  11. """Docker Compose module with extended validation."""
  12. name = "compose"
  13. description = "Manage Docker Compose configurations"
  14. def validate( # noqa: PLR0913
  15. self,
  16. template_id: Annotated[
  17. str | None,
  18. Argument(help="Template ID to validate (omit to validate all templates)"),
  19. ] = None,
  20. *,
  21. path: Annotated[
  22. str | None,
  23. Option("--path", help="Path to template directory for validation"),
  24. ] = None,
  25. verbose: Annotated[bool, Option("--verbose", "-v", help="Show detailed validation information")] = False,
  26. semantic: Annotated[
  27. bool,
  28. Option(
  29. "--semantic/--no-semantic",
  30. help="Enable semantic validation (Docker Compose schema, etc.)",
  31. ),
  32. ] = True,
  33. docker: Annotated[
  34. bool,
  35. Option(
  36. "--docker/--no-docker",
  37. help="Enable Docker Compose validation using 'docker compose config'",
  38. ),
  39. ] = False,
  40. docker_test_all: Annotated[
  41. bool,
  42. Option(
  43. "--docker-test-all",
  44. help="Test all variable combinations (minimal, maximal, each toggle). Requires --docker",
  45. ),
  46. ] = False,
  47. ) -> None:
  48. """Validate templates for Jinja2 syntax, undefined variables, and semantic correctness.
  49. Extended for Docker Compose with optional docker compose config validation.
  50. Use --docker for single config test, --docker-test-all for comprehensive testing.
  51. Examples:
  52. # Validate specific template
  53. compose validate netbox
  54. # Validate all templates
  55. compose validate
  56. # Validate with Docker Compose config check
  57. compose validate netbox --docker
  58. """
  59. # Run standard validation first
  60. validate_templates(self, template_id, path, verbose, semantic)
  61. # If docker validation is enabled and we have a specific template
  62. if docker and (template_id or path):
  63. run_docker_validation(self, template_id, path, docker_test_all, verbose)
  64. registry.register(ComposeModule)