Add more docker-container features.

This commit is contained in:
Olivier 'reivilibre' 2021-01-01 10:59:44 +00:00
parent cece4ef17a
commit 37a5a2b99f
2 changed files with 20 additions and 7 deletions

View File

@ -18,10 +18,12 @@ class DockerContainer(Recipe):
super().__init__(recipe_context, args, head)
self.image = check_type(args.get("image"), str)
self.command = check_type(args.get("command"), str)
self.command = check_type_opt(args.get("command"), str)
self.name = check_type(args.get("name"), str)
self.volumes = check_type_opt(args.get("volumes"), dict)
self.ports = check_type_opt(args.get("ports"), dict)
self.volumes = check_type(args.get("volumes", dict()), dict)
self.ports = check_type(args.get("ports", dict()), dict)
self.environment = check_type(args.get("environment", dict()), dict)
self.restart_policy = check_type(args.get("restart_policy", "on-failure"), str)
async def cook(self, kitchen: Kitchen) -> None:
kitchen.get_dependency_tracker()
@ -34,8 +36,10 @@ class DockerContainer(Recipe):
self.image,
self.command,
self.name,
self.ports or dict(),
self.volumes or dict(),
self.ports,
self.volumes,
{k: str(v) for k, v in self.environment.items()},
self.restart_policy,
),
DockerContainerRun.Result,
)

View File

@ -67,8 +67,8 @@ class DockerContainerState(Utensil):
class DockerContainerRun(Utensil):
# Name of the image to use to create the container.
image: str
# Command to create the container with.
command: str
# Command to create the container with. Optional.
command: Optional[str]
# Custom name to give the container.
name: str
# Ports to bind inside the container
@ -80,6 +80,10 @@ class DockerContainerRun(Utensil):
# bind = path to bind inside the container
# mode = 'rw' or 'ro'
volumes: Dict[str, Dict[str, str]]
# Environment variables
environment: Dict[str, str]
# Restart policy
restart_policy: str
@attr.s(auto_attribs=True)
class Result:
@ -94,6 +98,11 @@ class DockerContainerRun(Utensil):
name=self.name,
ports=self.ports,
volumes=self.volumes,
environment=self.environment,
restart_policy={
"Name": self.restart_policy,
"MaximumRetryCount": 5
}
)
except docker.errors.ImageNotFound: