| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- """Docker Swarm module with compose-compatible validation."""
- from __future__ import annotations
- import logging
- from typing import Annotated
- from typer import Argument, Option
- from ...core.module import Module
- from ...core.module.base_commands import ValidationConfig, validate_templates
- from ...core.registry import registry
- from ..compose.validate import ComposeDockerValidator
- logger = logging.getLogger(__name__)
- class SwarmModule(Module):
- """Docker Swarm module."""
- name = "swarm"
- description = "Manage Docker Swarm stack templates"
- kind_validator_class = ComposeDockerValidator
- def validate( # noqa: PLR0913
- self,
- template_id: Annotated[
- str | None,
- Argument(help="Template ID to validate (omit to validate all templates)"),
- ] = None,
- *,
- path: Annotated[
- str | None,
- Option("--path", help="Path to template directory for validation"),
- ] = None,
- all_templates: Annotated[
- bool,
- Option("--all", help="Validate all Swarm templates (default when no template ID is provided)"),
- ] = False,
- verbose: Annotated[bool, Option("--verbose", "-v", help="Show detailed validation information")] = False,
- semantic: Annotated[
- bool,
- Option(
- "--semantic/--no-semantic",
- help="Enable semantic validation for rendered files",
- ),
- ] = True,
- matrix: Annotated[
- bool,
- Option(
- "--matrix",
- help="Validate all reachable dependency states for a single template",
- ),
- ] = False,
- kind: Annotated[
- bool,
- Option(
- "--kind",
- help="Enable dependency-matrix Docker Compose validation",
- ),
- ] = False,
- docker: Annotated[
- bool,
- Option(
- "--docker/--no-docker",
- help="Alias for --kind Docker Compose validation",
- ),
- ] = False,
- docker_test_all: Annotated[
- bool,
- Option(
- "--docker-test-all",
- help="Alias for --matrix --kind Docker Compose validation",
- ),
- ] = False,
- ) -> None:
- """Validate Swarm templates."""
- kind_enabled = kind or docker or docker_test_all
- matrix_enabled = matrix or docker_test_all
- kind_validator = self.kind_validator_class(verbose).validate_rendered_files if kind_enabled else None
- validate_templates(
- self,
- template_id,
- path,
- ValidationConfig(
- verbose=verbose,
- semantic=semantic,
- matrix=matrix_enabled,
- kind=kind_enabled,
- all_templates=all_templates,
- kind_validator=kind_validator,
- ),
- )
- registry.register(SwarmModule)
|