__init__.py 2.6 KB

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