Skip to content

Commit 1429a31

Browse files
committed
deploy caddy
1 parent bc02ce6 commit 1429a31

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/warnet/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
FORK_OBSERVER_CHART = str(CHARTS_DIR.joinpath("fork-observer"))
3333
COMMANDER_CHART = str(CHARTS_DIR.joinpath("commander"))
3434
NAMESPACES_CHART_LOCATION = CHARTS_DIR.joinpath("namespaces")
35+
FORK_OBSERVER_CHART = str(files("resources.charts").joinpath("fork-observer"))
36+
CADDY_CHART = str(files("resources.charts").joinpath("caddy"))
37+
3538
DEFAULT_NETWORK = Path("6_node_bitcoin")
3639
DEFAULT_NAMESPACES = Path("two_namespaces_two_users")
3740

src/warnet/deploy.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .constants import (
88
BITCOIN_CHART_LOCATION,
9+
CADDY_CHART,
910
DEFAULTS_FILE,
1011
DEFAULTS_NAMESPACE_FILE,
1112
FORK_OBSERVER_CHART,
@@ -45,6 +46,7 @@ def deploy(directory, debug):
4546
deploy_logging_stack(directory, debug)
4647
deploy_network(directory, debug)
4748
deploy_fork_observer(directory, debug)
49+
deploy_caddy(directory, debug)
4850
elif (directory / NAMESPACES_FILE).exists():
4951
deploy_namespaces(directory)
5052
else:
@@ -90,6 +92,25 @@ def deploy_logging_stack(directory: Path, debug: bool):
9092
return True
9193

9294

95+
def deploy_caddy(directory: Path, debug: bool):
96+
network_file_path = directory / NETWORK_FILE
97+
with network_file_path.open() as f:
98+
network_file = yaml.safe_load(f)
99+
100+
# Only start if configured in the network file
101+
if not network_file.get("fork_observer", {}).get("enabled", False):
102+
return
103+
104+
namespace = get_default_namespace()
105+
cmd = f"{HELM_COMMAND} 'caddy' {CADDY_CHART} --namespace {namespace}"
106+
if debug:
107+
cmd += " --debug"
108+
109+
if not stream_command(cmd):
110+
click.echo(f"Failed to run Helm command: {cmd}")
111+
return
112+
113+
93114
def deploy_fork_observer(directory: Path, debug: bool):
94115
network_file_path = directory / NETWORK_FILE
95116
with network_file_path.open() as f:

src/warnet/network.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from .bitcoin import _rpc
88
from .constants import (
9+
CHARTS_DIR,
10+
DEFAULT_NETWORK,
911
NETWORK_DIR,
1012
SCENARIOS_DIR,
1113
)
@@ -41,6 +43,15 @@ def copy_network_defaults(directory: Path):
4143
NETWORK_DIR,
4244
["node-defaults.yaml", "__pycache__", "__init__.py"],
4345
)
46+
# Copy caddy files to the network directory
47+
networks_dir = directory / NETWORK_DIR.name
48+
copy_caddy_files(networks_dir / DEFAULT_NETWORK)
49+
50+
51+
def copy_caddy_files(directory: Path):
52+
"""Copy caddy files to the specified directory"""
53+
copy_defaults(directory, "caddy", CHARTS_DIR.joinpath("caddy"), [])
54+
print(f"Copied caddy files to {directory / 'caddy'}")
4455

4556

4657
def copy_scenario_defaults(directory: Path):

0 commit comments

Comments
 (0)