Add initial docker-image support (#10)
Co-authored-by: reivilibre <38398653+reivilibre@users.noreply.github.com>
This commit is contained in:
parent
c1ed0bd51b
commit
6c5c14a58b
@ -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"
|
||||
|
||||
@ -51,7 +68,7 @@ class DockerNetwork(Recipe):
|
||||
self.attachable = check_type_opt(args.get("attachable"), bool)
|
||||
self.scope = check_type_opt(args.get("scope"), str)
|
||||
self.ingress = check_type_opt(args.get("ingress"), bool)
|
||||
|
||||
|
||||
async def cook(self, kitchen: Kitchen) -> None:
|
||||
kitchen.get_dependency_tracker()
|
||||
await kitchen.ut1areq(
|
||||
@ -65,4 +82,3 @@ class DockerNetwork(Recipe):
|
||||
),
|
||||
DockerNetworkCreate.Result,
|
||||
)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user