diff --git a/scone/default/recipes/docker.py b/scone/default/recipes/docker.py index ef966ad..be0f4c2 100644 --- a/scone/default/recipes/docker.py +++ b/scone/default/recipes/docker.py @@ -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, ) diff --git a/scone/default/utensils/docker_utensils.py b/scone/default/utensils/docker_utensils.py index d0b275d..95ce197 100644 --- a/scone/default/utensils/docker_utensils.py +++ b/scone/default/utensils/docker_utensils.py @@ -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: