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.image,
self.command, self.command,
self.name, self.name,
self.ports, {k: (v['host'], v['port']) for k, v in self.ports.items()},
self.volumes, self.volumes,
{k: str(v) for k, v in self.environment.items()}, {k: str(v) for k, v in self.environment.items()},
self.restart_policy, self.restart_policy,

View File

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