Add initial docker-image support (#10)

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

View File

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

View File

@ -44,6 +44,26 @@ class DockerContainerRun(Utensil):
await channel.send(DockerContainerRun.Result(name=container.name))
@attr.s(auto_attribs=True)
class DockerImagePull(Utensil):
repository: str
tag: str
@attr.s(auto_attribs=True)
class Result:
id: str
async def execute(self, channel: Channel, worktop: Worktop):
try:
image = _docker_client().images.pull(self.repository, self.tag)
except docker.errors.APIError:
# the docker server returned an error
await channel.send(None)
return
await channel.send(DockerImagePull.Result(id=image.id))
@attr.s(auto_attribs=True)
class DockerVolumeCreate(Utensil):
name: str