Skip to content

Commit

Permalink
Allow to list images without docker cli installed (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Gruzinov authored Nov 22, 2019
1 parent d8347c2 commit 01af5ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.D/1071.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Now `neuro images` do not require the installed Docker.
40 changes: 24 additions & 16 deletions neuromation/api/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,7 @@ def __init__(self, core: _Core, config: _Config) -> None:
self._core = core
self._config = config
self._temporary_images: Set[str] = set()
try:
self._docker = aiodocker.Docker()
except ValueError as error:
if re.match(
r".*Either DOCKER_HOST or local sockets are not available.*", f"{error}"
):
raise DockerError(
900,
{
"message": "Docker engine is not available. "
"Please specify DOCKER_HOST variable "
"if you are using remote docker engine"
},
)
raise
self.__docker: Optional[aiodocker.Docker] = None
self._registry = _Registry(
self._core.session,
self._config.cluster_config.registry_url.with_path("/v2/"),
Expand All @@ -52,11 +38,33 @@ def __init__(self, core: _Core, config: _Config) -> None:
self._config.auth_token.username,
)

@property
def _docker(self) -> aiodocker.Docker:
if not self.__docker:
try:
self.__docker = aiodocker.Docker()
except ValueError as error:
if re.match(
r".*Either DOCKER_HOST or local sockets are not available.*",
f"{error}",
):
raise DockerError(
900,
{
"message": "Docker engine is not available. "
"Please specify DOCKER_HOST variable "
"if you are using remote docker engine"
},
)
raise
return self.__docker

async def _close(self) -> None:
for image in self._temporary_images:
with contextlib.suppress(DockerError, aiohttp.ClientError):
await self._docker.images.delete(image)
await self._docker.close()
if self.__docker is not None:
await self.__docker.close()
await self._registry.close()

def _auth(self) -> Dict[str, str]:
Expand Down

0 comments on commit 01af5ca

Please sign in to comment.