1717
1818import aiodocker
1919from aiodocker .images import DockerImages
20+ from aiohttp import ClientSession , ClientTimeout , UnixConnector
2021import attr
2122from awesomeversion import AwesomeVersion , AwesomeVersionCompareException
2223from docker import errors as docker_errors
@@ -211,7 +212,10 @@ def __init__(self, coresys: CoreSys):
211212 # We keep both until we can fully refactor to aiodocker
212213 self ._dockerpy : DockerClient | None = None
213214 self .docker : aiodocker .Docker = aiodocker .Docker (
214- url = f"unix:/{ str (SOCKET_DOCKER )} " , api_version = "auto"
215+ url = "unix://localhost" , # dummy hostname for URL composition
216+ connector = (connector := UnixConnector (SOCKET_DOCKER .as_posix ())),
217+ session = ClientSession (connector = connector , timeout = ClientTimeout (900 )),
218+ api_version = "auto" ,
215219 )
216220
217221 self ._network : DockerNetwork | None = None
@@ -221,11 +225,13 @@ def __init__(self, coresys: CoreSys):
221225
222226 async def post_init (self ) -> Self :
223227 """Post init actions that must be done in event loop."""
228+ # Use /var/run/docker.sock for this one so aiodocker and dockerpy don't
229+ # share the same handle. Temporary fix while refactoring this client out
224230 self ._dockerpy = await asyncio .get_running_loop ().run_in_executor (
225231 None ,
226232 partial (
227233 DockerClient ,
228- base_url = f"unix:/{ str ( SOCKET_DOCKER )} " ,
234+ base_url = f"unix://var { SOCKET_DOCKER . as_posix ( )} " ,
229235 version = "auto" ,
230236 timeout = 900 ,
231237 ),
@@ -433,20 +439,16 @@ async def pull_image(
433439 raises only if the get fails afterwards. Additionally it fires progress reports for the pull
434440 on the bus so listeners can use that to update status for users.
435441 """
436-
437- def api_pull ():
438- pull_log = self .dockerpy .api .pull (
439- repository , tag = tag , platform = platform , stream = True , decode = True
442+ async for e in self .images .pull (
443+ repository , tag = tag , platform = platform , stream = True
444+ ):
445+ entry = PullLogEntry .from_pull_log_dict (job_id , e )
446+ if entry .error :
447+ raise entry .exception
448+ await asyncio .gather (
449+ * self .sys_bus .fire_event (BusEvent .DOCKER_IMAGE_PULL_UPDATE , entry )
440450 )
441- for e in pull_log :
442- entry = PullLogEntry .from_pull_log_dict (job_id , e )
443- if entry .error :
444- raise entry .exception
445- self .sys_loop .call_soon_threadsafe (
446- self .sys_bus .fire_event , BusEvent .DOCKER_IMAGE_PULL_UPDATE , entry
447- )
448451
449- await self .sys_run_in_executor (api_pull )
450452 sep = "@" if tag .startswith ("sha256:" ) else ":"
451453 return await self .images .inspect (f"{ repository } { sep } { tag } " )
452454
0 commit comments