Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 20 additions & 10 deletions ctf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.")
Expand All @@ -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()
Expand Down
16 changes: 9 additions & 7 deletions ctf/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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"])
Expand All @@ -316,6 +319,7 @@ def deploy(
subprocess.run(
args=[
"incus",
f"--project={track.name}",
"config",
"device",
"add",
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading