diff --git a/ctf/__main__.py b/ctf/__main__.py index cd4009b..2c064d2 100644 --- a/ctf/__main__.py +++ b/ctf/__main__.py @@ -8,6 +8,7 @@ import rich import typer from rich.console import Console +from rich.prompt import Prompt from typer import Typer from typing_extensions import Annotated @@ -59,7 +60,7 @@ def check_tool_version() -> None: return with r_context as r: try: - latest_version = json.loads(s=r.read().decode())["tag_name"] + latest_version: str = json.loads(s=r.read().decode())["tag_name"] except Exception as e: LOG.debug(e) LOG.error("Could not verify the latest release.") @@ -77,15 +78,24 @@ def check_tool_version() -> None: compare = 1 break - match compare: - case 0 | 1: - LOG.debug("Script is up to date.") - case -1: - LOG.warning( - f"Script is outdated (current: {current_version}, upstream: {latest_version}). Please update to the latest release before continuing." - ) - if (input("Do you want to continue? [y/N] ").lower() or "n") == "n": - exit(code=0) + match compare: + case 0 | 1: + LOG.debug("Script is up to date.") + case -1: + LOG.warning( + f"Script is outdated (current: {current_version}, upstream: {latest_version}). Please update to the latest release before continuing." + ) + if ( + Prompt.ask( + "Do you want to continue?", + choices=["y", "N"], + case_sensitive=False, + show_default=False, + default="N", + ).lower() + == "n" + ): + raise typer.Exit() @app.callback() diff --git a/ctf/deploy.py b/ctf/deploy.py index c931a57..27b20bc 100644 --- a/ctf/deploy.py +++ b/ctf/deploy.py @@ -275,23 +275,26 @@ def deploy( parse_track_yaml(track_name=track.name) ) - services: list[dict[str, str | int | None]] = [] + services: dict[str, dict[str, str | int | None]] = {} # Combining both service lists until we remove entirely the deprecated services list at the root. if track_yaml.services: for service in track_yaml.services: if not service.dev_port_mapping: continue - services.append(service.model_dump()) + services[service.name] = service.model_dump() if track_yaml.instances: for k, v in track_yaml.instances.root.items(): for service in v.services: if not service.dev_port_mapping: continue - services.append({**service.model_dump(), "address": v.ipv6}) + services[service.name] = { + **service.model_dump(), + "address": v.ipv6, + } - for service in services: + for service_name, service in services.items(): if ( service.get("dev_port_mapping") and ( @@ -304,7 +307,7 @@ def deploy( in ipv6_to_container_name ): LOG.debug( - f"Adding incus proxy for service {track}-{service['name']}-port-{service['port']}" + f"Adding incus proxy for service {track}-{service_name}-port-{service['port']}" ) machine_name = ipv6_to_container_name[ str(service["address"]) @@ -316,6 +319,7 @@ def deploy( subprocess.run( args=[ "incus", + f"--project={track.name}", "config", "device", "add", @@ -324,8 +328,6 @@ def deploy( "proxy", f"listen=tcp:0.0.0.0:{service['dev_port_mapping']}", f"connect=tcp:127.0.0.1:{service['port']}", - "--project", - track.name, ], cwd=path, check=True, diff --git a/pyproject.toml b/pyproject.toml index c62bc42..f997e27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dependencies = [ "typer==0.16.0", "pydantic" ] -version = "4.3.3" +version = "4.3.4" classifiers = [ "Programming Language :: Python :: 3", "Operating System :: OS Independent",