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

View File

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