Skip to content

Commit b454808

Browse files
authored
Merge pull request #742 from pinheadmz/www-plugins
Support extra services in caddy / Warnet dashboard
2 parents 30130eb + 34c7c2f commit b454808

File tree

5 files changed

+81
-49
lines changed

5 files changed

+81
-49
lines changed

resources/charts/caddy/templates/configmap.yaml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ metadata:
66
{{- include "caddy.labels" . | nindent 4 }}
77
data:
88
Caddyfile: |
9-
{{- .Values.caddyConfig | nindent 4 }}
9+
:80 {
10+
respond /live 200
11+
respond /ready 200
12+
13+
root * /usr/share/caddy
14+
file_server
15+
16+
{{- range .Values.services }}
17+
handle_path {{ .path }}* {
18+
reverse_proxy {{ .host }}:{{ .port }}
19+
}
20+
{{- end }}
21+
}
1022
index: |
11-
{{- .Values.htmlConfig | nindent 4 }}
23+
<!DOCTYPE html>
24+
<html lang="en">
25+
<head>
26+
<meta charset="UTF-8">
27+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
28+
<title>Warnet Dashboard</title>
29+
</head>
30+
<body>
31+
<h1>Welcome to the Warnet dashboard</h1>
32+
<p>You can access the following services:</p>
33+
<ul>
34+
{{- range .Values.services }}
35+
<li><a href="{{ .path }}">{{ .title }}</a></li>
36+
{{- end }}
37+
</ul>
38+
</body>
39+
</html>

resources/charts/caddy/values.yaml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -85,39 +85,3 @@ volumeMounts:
8585
subPath: index
8686

8787
port: 80
88-
89-
caddyConfig: |
90-
:80 {
91-
respond /live 200
92-
respond /ready 200
93-
94-
root * /usr/share/caddy
95-
file_server
96-
97-
handle_path /fork-observer/* {
98-
reverse_proxy fork-observer:2323
99-
}
100-
101-
handle_path /grafana/* {
102-
reverse_proxy loki-grafana:80
103-
}
104-
105-
}
106-
107-
htmlConfig: |
108-
<!DOCTYPE html>
109-
<html lang="en">
110-
<head>
111-
<meta charset="UTF-8">
112-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
113-
<title>Welcome</title>
114-
</head>
115-
<body>
116-
<h1>Welcome to the Warnet dashboard</h1>
117-
<p>You can access the following services:</p>
118-
<ul>
119-
<li><a href="/grafana/">Grafana</a></li>
120-
<li><a href="/fork-observer/">Fork Observer</a></li>
121-
</ul>
122-
</body>
123-
</html>

src/warnet/deploy.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,32 @@ def deploy_caddy(directory: Path, debug: bool):
269269
if not network_file.get(name, {}).get("enabled", False):
270270
return
271271

272-
cmd = f"{HELM_COMMAND} {name} {CADDY_CHART} --namespace {namespace} --create-namespace"
272+
# configure reverse proxy to webservers in the network
273+
services = []
274+
# built-in services
275+
if check_logging_required(directory):
276+
services.append(
277+
{"title": "Grafana", "path": "/grafana/", "host": "loki-grafana", "port": 80}
278+
)
279+
if network_file.get("fork_observer", {}).get("enabled", False):
280+
services.append(
281+
{
282+
"title": "Fork Observer",
283+
"path": "/fork-observer/",
284+
"host": "fork-observer",
285+
"port": 2323,
286+
}
287+
)
288+
# add any extra services
289+
services += network_file.get("services", {})
290+
291+
click.echo(f"Adding services to dashboard: {json.dumps(services, indent=2)}")
292+
293+
cmd = (
294+
f"{HELM_COMMAND} {name} {CADDY_CHART} "
295+
f"--namespace {namespace} --create-namespace "
296+
f"--set-json services='{json.dumps(services)}'"
297+
)
273298
if debug:
274299
cmd += " --debug"
275300

test/data/services/network.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ fork_observer:
3535
enabled: true
3636
caddy:
3737
enabled: true
38+
services:
39+
- title: Ringo REST
40+
path: /ringo/
41+
host: ringo.default
42+
port: 18443

test/services_test.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ class ServicesTest(TestBase):
1515
def __init__(self):
1616
super().__init__()
1717
self.network_dir = Path(os.path.dirname(__file__)) / "data" / "services"
18+
self.ingress_ip = None
1819

1920
def run_test(self):
2021
try:
2122
self.setup_network()
23+
self.get_ingress_ip()
2224
self.check_fork_observer()
25+
self.check_extra_services()
2326
finally:
2427
self.cleanup()
2528

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

32-
def check_fork_observer(self):
33-
self.log.info("Creating chain split")
34-
self.warnet("bitcoin rpc john createwallet miner")
35-
self.warnet("bitcoin rpc john -generate 1")
36-
35+
def get_ingress_ip(self):
3736
self.log.info("Waiting for ingress controller")
3837
wait_for_ingress_controller()
39-
4038
self.log.info("Waiting for ingress host")
41-
ingress_ip = None
4239
attempts = 100
43-
while not ingress_ip:
44-
ingress_ip = get_ingress_ip_or_host()
40+
while not self.ingress_ip:
41+
self.ingress_ip = get_ingress_ip_or_host()
4542
attempts -= 1
4643
if attempts < 0:
4744
raise Exception("Never got ingress host")
4845
sleep(1)
46+
47+
def check_fork_observer(self):
48+
self.log.info("Creating chain split")
49+
self.warnet("bitcoin rpc john createwallet miner")
50+
self.warnet("bitcoin rpc john -generate 1")
51+
4952
# network id is 0xDEADBE in decimal
50-
fo_data_uri = f"http://{ingress_ip}/fork-observer/api/14593470/data.json"
53+
fo_data_uri = f"http://{self.ingress_ip}/fork-observer/api/14593470/data.json"
5154

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

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

8191
if __name__ == "__main__":
8292
test = ServicesTest()

0 commit comments

Comments
 (0)