Refresh docker watch tiles on new containers
This commit is contained in:
@@ -281,10 +281,6 @@ class DockerWatcher:
|
||||
container_id = actor.get("ID", "")
|
||||
attributes = actor.get("Attributes", {})
|
||||
|
||||
# Only handle containers with any webterm label
|
||||
if not _has_webterm_label(attributes):
|
||||
return
|
||||
|
||||
if action == "start":
|
||||
# Get full container info
|
||||
status, body = await self._docker_request("GET", f"/containers/{container_id}/json")
|
||||
@@ -296,6 +292,7 @@ class DockerWatcher:
|
||||
"Names": ["/" + container_info.get("Name", "").lstrip("/")],
|
||||
"Labels": container_info.get("Config", {}).get("Labels", {}),
|
||||
}
|
||||
if _has_webterm_label(container.get("Labels", {})):
|
||||
await self._add_container(container)
|
||||
elif action == "die":
|
||||
await self._remove_container(container_id)
|
||||
|
||||
@@ -221,6 +221,7 @@ class TestDockerWatcherIntegration:
|
||||
async def test_handle_event_without_label(self, session_manager):
|
||||
"""Test that events without our label are ignored."""
|
||||
watcher = DockerWatcher(session_manager)
|
||||
watcher._docker_request = AsyncMock(return_value=(404, ""))
|
||||
|
||||
event = {
|
||||
"Action": "start",
|
||||
@@ -235,6 +236,33 @@ class TestDockerWatcherIntegration:
|
||||
# Should not add container
|
||||
session_manager.add_app.assert_not_called()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_start_event_label_added_after_start(self, session_manager):
|
||||
"""Container that gains label after start is picked up."""
|
||||
watcher = DockerWatcher(session_manager)
|
||||
|
||||
async def mock_request(method, path):
|
||||
if "/containers/" in path and "/json" in path:
|
||||
return (
|
||||
200,
|
||||
'{"Name": "/test-service", "Config": {"Labels": {"webterm-command": "auto"}}}',
|
||||
)
|
||||
return 404, ""
|
||||
|
||||
watcher._docker_request = mock_request
|
||||
|
||||
event = {
|
||||
"Action": "start",
|
||||
"Actor": {
|
||||
"ID": "container123",
|
||||
"Attributes": {}, # Labels not present on event
|
||||
},
|
||||
}
|
||||
|
||||
await watcher._handle_event(event)
|
||||
|
||||
session_manager.add_app.assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("labels", "expected"),
|
||||
|
||||
Reference in New Issue
Block a user