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 (
|
from scone.default.utensils.docker_utensils import (
|
||||||
DockerContainerRun,
|
DockerContainerRun,
|
||||||
|
DockerImagePull,
|
||||||
DockerVolumeCreate,
|
DockerVolumeCreate,
|
||||||
DockerNetworkCreate,
|
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):
|
class DockerVolume(Recipe):
|
||||||
_NAME = "docker-volume"
|
_NAME = "docker-volume"
|
||||||
|
|
||||||
@ -65,4 +82,3 @@ class DockerNetwork(Recipe):
|
|||||||
),
|
),
|
||||||
DockerNetworkCreate.Result,
|
DockerNetworkCreate.Result,
|
||||||
)
|
)
|
||||||
|
|
@ -44,6 +44,26 @@ class DockerContainerRun(Utensil):
|
|||||||
await channel.send(DockerContainerRun.Result(name=container.name))
|
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)
|
@attr.s(auto_attribs=True)
|
||||||
class DockerVolumeCreate(Utensil):
|
class DockerVolumeCreate(Utensil):
|
||||||
name: str
|
name: str
|
||||||
|
Loading…
Reference in New Issue
Block a user