Fix up arguments passed to docker, and remove error suppression

This commit is contained in:
Olivier 'reivilibre' 2021-01-01 12:25:03 +00:00
parent 37343c339e
commit bbd5d6967b
2 changed files with 16 additions and 23 deletions

View File

@ -36,7 +36,7 @@ class DockerContainer(Recipe):
self.image,
self.command,
self.name,
self.ports,
{k: (v['host'], v['port']) for k, v in self.ports.items()},
self.volumes,
{k: str(v) for k, v in self.environment.items()},
self.restart_policy,

View File

@ -90,29 +90,22 @@ class DockerContainerRun(Utensil):
name: str
async def execute(self, channel: Channel, worktop: Worktop):
try:
container = _docker_client().containers.run(
self.image,
self.command,
detach=True,
name=self.name,
ports=self.ports,
volumes=self.volumes,
environment=self.environment,
restart_policy={
"Name": self.restart_policy,
"MaximumRetryCount": 5
}
)
restart_policy = {
"Name": self.restart_policy,
}
if self.restart_policy == 'on-failure':
restart_policy["MaximumRetryCount"] = 5
except docker.errors.ImageNotFound:
# specified image does not exist (or requires login)
await channel.send(None)
return
except docker.errors.APIError:
# the docker server returned an error
await channel.send(None)
return
container = _docker_client().containers.run(
self.image,
self.command,
detach=True,
name=self.name,
ports=self.ports,
volumes=self.volumes,
environment=self.environment,
restart_policy=restart_policy
)
await channel.send(DockerContainerRun.Result(name=container.name))