-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
42 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
poetry run up ansible --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import pluggy | ||
from .containers import Containers | ||
from dataclasses import dataclass | ||
from typing import List | ||
|
||
hookimpl = pluggy.HookimplMarker("up") | ||
pm = pluggy.PluginManager("up") | ||
containers = Containers() | ||
|
||
def match_prompt(prompt, head, image): | ||
if not prompt: | ||
return None | ||
if prompt[0] == head: | ||
return image | ||
return None | ||
|
||
# https://docker-py.readthedocs.io/en/stable/containers.html | ||
@dataclass | ||
class RunConfig: | ||
name: str | ||
image: str | ||
command: List[str] | ||
environment: dict[str, str] | ||
ports: dict[str, str] | ||
auto_remove: bool = True | ||
network_mode: str = "host" | ||
# volumes: dict[str, str] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
import logging as log | ||
from dataclasses import dataclass | ||
import docker | ||
|
||
@dataclass | ||
class ContainerRun: | ||
"""Specify the parameters for a container run""" | ||
image: str | ||
prompt: list[str] | ||
|
||
from up_cli import RunConfig | ||
|
||
class DockerContainers: | ||
def run(self, run: ContainerRun): | ||
def run(self, run: RunConfig): | ||
log.debug("Running container: %s", run) | ||
client = docker.from_env() | ||
image = run.image | ||
prompt = run.prompt | ||
#TODO: Catch errors, print properly | ||
#TODO: Catch errors, print properly, pass all params | ||
result = client.containers.run( | ||
image=image, | ||
command=prompt, | ||
auto_remove=True) | ||
image=run.image, | ||
command=run.command, | ||
auto_remove=run.auto_remove) | ||
log.info("container result") | ||
log.info("%s", result) | ||
log.debug("Container run done") | ||
|
||
class Containers: | ||
delegate = DockerContainers() | ||
|
||
def run(self, run: ContainerRun): | ||
self.delegate.run(run) | ||
def run(self, run: RunConfig): | ||
self.delegate.run(run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import pluggy | ||
|
||
|
||
hookspec = pluggy.HookspecMarker("up") | ||
|
||
RunConfigs = List[float] | ||
Prompt = list[str] | ||
|
||
@hookspec(firstresult=True) | ||
def image_for_prompt(prompt: list[str]) -> str: | ||
"""Present the image in which the prompt will be executed""" | ||
def to_run_configs(prompt: Prompt) -> RunConfigs: | ||
"""Present run configurations to execute for prompt""" | ||
|
||
@hookspec(firstresult=True) | ||
def substitutions_for_prompt(prompt: list[str]) -> list[list[str]]: | ||
"""Present the substitutions for the prompt""" | ||
|
||
# TODO: Variables and Volumes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters