__init__.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 ValidationConfig, validate_templates
  7. from ...core.registry import registry
  8. from .validate import ComposeDockerValidator
  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. kind_validator_class = ComposeDockerValidator
  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. all_templates: Annotated[
  27. bool,
  28. Option("--all", help="Validate all Compose templates (default when no template ID is provided)"),
  29. ] = False,
  30. verbose: Annotated[bool, Option("--verbose", "-v", help="Show detailed validation information")] = False,
  31. semantic: Annotated[
  32. bool,
  33. Option(
  34. "--semantic/--no-semantic",
  35. help="Enable semantic validation for rendered files",
  36. ),
  37. ] = True,
  38. matrix: Annotated[
  39. bool,
  40. Option(
  41. "--matrix",
  42. help="Validate all reachable dependency states for a single template",
  43. ),
  44. ] = False,
  45. kind: Annotated[
  46. bool,
  47. Option(
  48. "--kind",
  49. help="Enable dependency-matrix Docker Compose validation",
  50. ),
  51. ] = False,
  52. docker: Annotated[
  53. bool,
  54. Option(
  55. "--docker/--no-docker",
  56. help="Alias for --kind Docker Compose validation",
  57. ),
  58. ] = False,
  59. docker_test_all: Annotated[
  60. bool,
  61. Option(
  62. "--docker-test-all",
  63. help="Alias for --matrix --kind Docker Compose validation. Requires --docker.",
  64. ),
  65. ] = False,
  66. ) -> None:
  67. """Validate Compose templates."""
  68. kind_enabled = kind or docker or docker_test_all
  69. matrix_enabled = matrix or docker_test_all
  70. kind_validator = self.kind_validator_class(verbose).validate_rendered_files if kind_enabled else None
  71. validate_templates(
  72. self,
  73. template_id,
  74. path,
  75. ValidationConfig(
  76. verbose=verbose,
  77. semantic=semantic,
  78. matrix=matrix_enabled,
  79. kind=kind_enabled,
  80. all_templates=all_templates,
  81. kind_validator=kind_validator,
  82. ),
  83. )
  84. registry.register(ComposeModule)