Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
from typing import Union
from typing import overload

import time
from rich.console import Console, Group
from rich.live import Live
from rich.spinner import Spinner
from rich.text import Text
from rich.padding import Padding


# import fnmatch
# fnmatch.fnmatchcase(env, "*_HOST")
import yaml
Expand Down Expand Up @@ -1664,6 +1672,7 @@ async def run( # pylint: disable=dangerous-default-value
*,
# Intentionally mutable default argument to hold references to tasks
task_reference: set[asyncio.Task] = set(),
printer = None
) -> int | None:
async with self.semaphore:
cmd_args = list(map(str, cmd_args or []))
Expand Down Expand Up @@ -1699,7 +1708,19 @@ async def run( # pylint: disable=dangerous-default-value
err_t.add_done_callback(task_reference.discard)

else:
p = await asyncio.create_subprocess_exec(*cmd_ls, close_fds=False) # pylint: disable=consider-using-with
kwargs = {}
if printer:
kwargs = {
"stdout": subprocess.PIPE,
"stderr":subprocess.PIPE,
}
p = await asyncio.create_subprocess_exec(
*cmd_ls,
close_fds=False,
**kwargs,
) # pylint: disable=consider-using-with
if printer:
await printer(p)

try:
exit_code = await p.wait()
Expand Down Expand Up @@ -3671,9 +3692,43 @@ async def transfer_service_status(
timeout = str_to_seconds(timeout_str)
if timeout is not None:
podman_args.extend(["-t", str(timeout)])
tasks.append(asyncio.create_task(compose.podman.run([], action, podman_args + [target])))
await asyncio.gather(*tasks)

# TODO hardcoded value for my docker-compose.yaml
container = "copr_builder_1"

items = {
"heading": Text.from_markup("[+] Restarting 0/1"),
container: Padding(
Spinner(
"dots",
text=Text("Container {0} Restarting".format(container)),
),
(0, 0, 0, 1),
),
}
group = Group(*items.values())

console = Console()
live = Live(group, refresh_per_second=10, console=console)
live.start()

async def printer(proc, action=action, live=live, items=items):
time.sleep(1)
container = (await proc.stdout.read()).decode("utf-8").strip()
exit_code = await proc.wait()
if action == "restart":
if exit_code:
items[container].renderable = Text.from_markup(f" [red]:x:[/red]Container {container} [red]Failed[/red]")
else:
items[container].renderable = Text.from_markup(f" [green]✔[/green] Container {container} [green]Started[/green]")
live.update(Group(*items.values()))

tasks.append(asyncio.create_task(compose.podman.run([], action, podman_args + [target], printer=printer)))

await asyncio.gather(*tasks)
items["heading"] = Text.from_markup("[blue][+] Restarting 1/1[/blue]")
live.update(Group(*items.values()))
live.stop()

@cmd_run(podman_compose, "start", "start specific services")
async def compose_start(compose: PodmanCompose, args: argparse.Namespace) -> None:
Expand Down
Loading