Add initial docker-volume support (#9)

* Add initial docker-volume support

* Lint

Co-authored-by: reivilibre <38398653+reivilibre@users.noreply.github.com>
This commit is contained in:
Merikei 2020-11-01 09:42:00 +00:00 committed by GitHub
parent 6c5cd04d35
commit c1ed0bd51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from scone.default.utensils.docker_utensils import (
DockerContainerRun,
DockerVolumeCreate,
DockerNetworkCreate,
)
from scone.head.kitchen import Kitchen
@ -23,9 +24,22 @@ class DockerContainer(Recipe):
)
class DockerVolume(Recipe):
_NAME = "docker-volume"
def __init__(self, recipe_context: RecipeContext, args: dict, head):
super().__init__(recipe_context, args, head)
self.name = check_type(args.get("name"), str)
async def cook(self, kitchen: Kitchen) -> None:
kitchen.get_dependency_tracker()
await kitchen.ut1areq(DockerVolumeCreate(self.name), DockerVolumeCreate.Result)
class DockerNetwork(Recipe):
_NAME = "docker-network"
def __init__(self, recipe_context: RecipeContext, args: dict, head):
super().__init__(recipe_context, args, head)
@ -51,3 +65,4 @@ class DockerNetwork(Recipe):
),
DockerNetworkCreate.Result,
)

View File

@ -44,6 +44,25 @@ class DockerContainerRun(Utensil):
await channel.send(DockerContainerRun.Result(name=container.name))
@attr.s(auto_attribs=True)
class DockerVolumeCreate(Utensil):
name: str
@attr.s(auto_attribs=True)
class Result:
name: str
async def execute(self, channel: Channel, worktop: Worktop):
try:
volume = _docker_client().volume.create(self.name)
except docker.errors.APIError:
# the docker server returned an error
await channel.send(None)
return
await channel.send(DockerVolumeCreate.Result(name=volume.name))
@attr.s(auto_attribs=True)
class DockerNetworkCreate(Utensil):
name: str
@ -52,7 +71,7 @@ class DockerNetworkCreate(Utensil):
enable_ipv6: Optional[bool]
attachable: Optional[bool]
ingress: Optional[bool]
@attr.s(auto_attribs=True)
class Result:
name: str
@ -67,10 +86,9 @@ class DockerNetworkCreate(Utensil):
attachable=self.attachable,
ingress=self.ingress,
)
except docker.errors.APIError:
# the docker server returned an error
await channel.send(None)
return
await channel.send(DockerContainerRun.Result(name=network.name))