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
32 changes: 30 additions & 2 deletions resources/charts/caddy/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ metadata:
{{- include "caddy.labels" . | nindent 4 }}
data:
Caddyfile: |
{{- .Values.caddyConfig | nindent 4 }}
:80 {
respond /live 200
respond /ready 200

root * /usr/share/caddy
file_server

{{- range .Values.services }}
handle_path {{ .path }}* {
reverse_proxy {{ .host }}:{{ .port }}
}
{{- end }}
}
index: |
{{- .Values.htmlConfig | nindent 4 }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Warnet Dashboard</title>
</head>
<body>
<h1>Welcome to the Warnet dashboard</h1>
<p>You can access the following services:</p>
<ul>
{{- range .Values.services }}
<li><a href="{{ .path }}">{{ .title }}</a></li>
{{- end }}
</ul>
</body>
</html>
36 changes: 0 additions & 36 deletions resources/charts/caddy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,3 @@ volumeMounts:
subPath: index

port: 80

caddyConfig: |
:80 {
respond /live 200
respond /ready 200

root * /usr/share/caddy
file_server

handle_path /fork-observer/* {
reverse_proxy fork-observer:2323
}

handle_path /grafana/* {
reverse_proxy loki-grafana:80
}

}

htmlConfig: |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Welcome to the Warnet dashboard</h1>
<p>You can access the following services:</p>
<ul>
<li><a href="/grafana/">Grafana</a></li>
<li><a href="/fork-observer/">Fork Observer</a></li>
</ul>
</body>
</html>
27 changes: 26 additions & 1 deletion src/warnet/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,32 @@ def deploy_caddy(directory: Path, debug: bool):
if not network_file.get(name, {}).get("enabled", False):
return

cmd = f"{HELM_COMMAND} {name} {CADDY_CHART} --namespace {namespace} --create-namespace"
# configure reverse proxy to webservers in the network
services = []
# built-in services
if check_logging_required(directory):
services.append(
{"title": "Grafana", "path": "/grafana/", "host": "loki-grafana", "port": 80}
)
if network_file.get("fork_observer", {}).get("enabled", False):
services.append(
{
"title": "Fork Observer",
"path": "/fork-observer/",
"host": "fork-observer",
"port": 2323,
}
)
# add any extra services
services += network_file.get("services", {})

click.echo(f"Adding services to dashboard: {json.dumps(services, indent=2)}")

cmd = (
f"{HELM_COMMAND} {name} {CADDY_CHART} "
f"--namespace {namespace} --create-namespace "
f"--set-json services='{json.dumps(services)}'"
)
if debug:
cmd += " --debug"

Expand Down
5 changes: 5 additions & 0 deletions test/data/services/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ fork_observer:
enabled: true
caddy:
enabled: true
services:
- title: Ringo REST
path: /ringo/
host: ringo.default
port: 18443
30 changes: 20 additions & 10 deletions test/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class ServicesTest(TestBase):
def __init__(self):
super().__init__()
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "services"
self.ingress_ip = None

def run_test(self):
try:
self.setup_network()
self.get_ingress_ip()
self.check_fork_observer()
self.check_extra_services()
finally:
self.cleanup()

Expand All @@ -29,25 +32,25 @@ def setup_network(self):
self.wait_for_all_tanks_status(target="running")
self.wait_for_all_edges()

def check_fork_observer(self):
self.log.info("Creating chain split")
self.warnet("bitcoin rpc john createwallet miner")
self.warnet("bitcoin rpc john -generate 1")

def get_ingress_ip(self):
self.log.info("Waiting for ingress controller")
wait_for_ingress_controller()

self.log.info("Waiting for ingress host")
ingress_ip = None
attempts = 100
while not ingress_ip:
ingress_ip = get_ingress_ip_or_host()
while not self.ingress_ip:
self.ingress_ip = get_ingress_ip_or_host()
attempts -= 1
if attempts < 0:
raise Exception("Never got ingress host")
sleep(1)

def check_fork_observer(self):
self.log.info("Creating chain split")
self.warnet("bitcoin rpc john createwallet miner")
self.warnet("bitcoin rpc john -generate 1")

# network id is 0xDEADBE in decimal
fo_data_uri = f"http://{ingress_ip}/fork-observer/api/14593470/data.json"
fo_data_uri = f"http://{self.ingress_ip}/fork-observer/api/14593470/data.json"

def call_fo_api():
# if on minikube remember to run `minikube tunnel` for this test to run
Expand Down Expand Up @@ -77,6 +80,13 @@ def call_fo_api():
lambda: len(json.loads(self.warnet("bitcoin rpc george getpeerinfo"))) > 1
)

def check_extra_services(self):
self.log.info("Checking extra web services added to caddy")
uri = f"http://{self.ingress_ip}/ringo/rest/chaininfo.json"
rest_data = requests.get(uri)
rest_json = rest_data.json()
assert rest_json["chain"] == "regtest"


if __name__ == "__main__":
test = ServicesTest()
Expand Down