Handle the non-root perms case specifically too
							parent
							
								
									ad0ace2528
								
							
						
					
					
						commit
						df04ccb845
					
				| 
						 | 
					@ -23,7 +23,6 @@ from typing import (
 | 
				
			||||||
    # Any,
 | 
					    # Any,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
from contextlib import asynccontextmanager as acm
 | 
					from contextlib import asynccontextmanager as acm
 | 
				
			||||||
from requests.exceptions import ConnectionError
 | 
					 | 
				
			||||||
# import time
 | 
					# import time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import trio
 | 
					import trio
 | 
				
			||||||
| 
						 | 
					@ -32,6 +31,8 @@ import tractor
 | 
				
			||||||
import docker
 | 
					import docker
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
from docker.models.containers import Container
 | 
					from docker.models.containers import Container
 | 
				
			||||||
 | 
					from docker.errors import DockerException
 | 
				
			||||||
 | 
					from requests.exceptions import ConnectionError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ..log import get_logger  # , get_console_log
 | 
					from ..log import get_logger  # , get_console_log
 | 
				
			||||||
from ..config import _config_dir
 | 
					from ..config import _config_dir
 | 
				
			||||||
| 
						 | 
					@ -87,20 +88,27 @@ async def open_docker(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
) -> docker.DockerClient:
 | 
					) -> docker.DockerClient:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    client: Optional[docker.DockerClient] = None
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        client = docker.DockerClient(
 | 
					        client = docker.DockerClient(
 | 
				
			||||||
            base_url=url,
 | 
					            base_url=url,
 | 
				
			||||||
            **kwargs
 | 
					            **kwargs
 | 
				
			||||||
        ) if url else docker.from_env(**kwargs)
 | 
					        ) if url else docker.from_env(**kwargs)
 | 
				
			||||||
    except (
 | 
					        yield client
 | 
				
			||||||
        ConnectionError,
 | 
					    except ConnectionError:
 | 
				
			||||||
        docker.errors.DockerException,
 | 
					        # prolly no daemon started
 | 
				
			||||||
    ):
 | 
					 | 
				
			||||||
        raise DockerNotStarted('!?!?')
 | 
					        raise DockerNotStarted('!?!?')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    except DockerException as err:
 | 
				
			||||||
        yield client
 | 
					        # could be more specific so let's check if it's just perms.
 | 
				
			||||||
 | 
					        if 'PermissionError' in err.args[0]:
 | 
				
			||||||
 | 
					            raise DockerException('You dint run as root yo!')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # not perms?
 | 
				
			||||||
 | 
					        raise
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    finally:
 | 
					    finally:
 | 
				
			||||||
 | 
					        if client:
 | 
				
			||||||
            # for c in client.containers.list():
 | 
					            # for c in client.containers.list():
 | 
				
			||||||
            #     c.kill()
 | 
					            #     c.kill()
 | 
				
			||||||
            client.close()
 | 
					            client.close()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue