Add comprehensive Docker containers management page with filtering, search, bulk actions, and enhanced container control with state verification

This commit is contained in:
2025-12-15 23:54:45 -05:00
parent 68a9b0f390
commit 230387a14e
50 changed files with 10856 additions and 35 deletions
+64
View File
@@ -16,6 +16,8 @@ from app.schemas.docker import (
EnableDockerRequest,
DockerContainerListResponse,
DockerContainerResponse,
DockerContainerAggregatedResponse,
DockerContainerAggregatedListResponse,
DockerImageListResponse,
DockerImageExtendedListResponse,
DockerImageExtendedResponse,
@@ -130,6 +132,68 @@ async def collect_all_docker_hosts(
# === Containers ===
@router.get("/containers", response_model=DockerContainerAggregatedListResponse)
async def get_all_containers(
state: Optional[str] = Query(None, description="Filter by state (running, exited, paused, etc.)"),
compose_project: Optional[str] = Query(None, description="Filter by compose project"),
health: Optional[str] = Query(None, description="Filter by health status"),
host_id: Optional[str] = Query(None, description="Filter by specific host"),
api_key_valid: bool = Depends(verify_api_key),
db_session: AsyncSession = Depends(get_db),
):
"""List all containers across all Docker hosts."""
container_repo = DockerContainerRepository(db_session)
host_repo = HostRepository(db_session)
# Get host filter if provided
host_ids = [host_id] if host_id else None
# Fetch containers
containers = await container_repo.list_all(
state=state,
compose_project=compose_project,
health=health,
host_ids=host_ids
)
counts = await container_repo.count_all()
# Build host lookup for names/IPs
hosts = await host_repo.list_all()
host_map = {h.id: {"name": h.name, "ip": h.ip_address} for h in hosts}
# Build response with host info
container_responses = []
for c in containers:
host_info = host_map.get(c.host_id, {"name": "Unknown", "ip": "Unknown"})
container_responses.append(DockerContainerAggregatedResponse(
id=c.id,
host_id=c.host_id,
host_name=host_info["name"],
host_ip=host_info["ip"],
container_id=c.container_id,
name=c.name,
image=c.image,
state=c.state,
status=c.status,
health=c.health,
ports=c.ports,
labels=c.labels,
compose_project=c.compose_project,
created_at=c.created_at,
last_update_at=c.last_update_at
))
return DockerContainerAggregatedListResponse(
containers=container_responses,
total=counts.get("total", 0),
running=counts.get("running", 0),
stopped=counts.get("stopped", 0),
paused=counts.get("paused", 0),
hosts_count=counts.get("hosts_count", 0),
last_update=counts.get("last_update")
)
@router.get("/hosts/{host_id}/containers", response_model=DockerContainerListResponse)
async def get_containers(
host_id: str,